Nori  23
warp.cpp
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Wenzel Jakob
5 
6  Nori is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Nori is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <nori/warp.h>
20 #include <nori/vector.h>
21 #include <nori/frame.h>
22 
23 NORI_NAMESPACE_BEGIN
24 
26  // Naive implementation using rejection sampling
27  Vector3f v;
28  do {
29  v.x() = 1.f - 2.f * sampler->next1D();
30  v.y() = 1.f - 2.f * sampler->next1D();
31  v.z() = 1.f - 2.f * sampler->next1D();
32  } while (v.squaredNorm() > 1.f);
33 
34  if (v.dot(pole) < 0.f)
35  v = -v;
36  v /= v.norm();
37 
38  return v;
39 }
40 
42  return sample;
43 }
44 
46  return ((sample.array() >= 0).all() && (sample.array() <= 1).all()) ? 1.0f : 0.0f;
47 }
48 
50  throw NoriException("Warp::squareToUniformDisk() is not yet implemented!");
51 }
52 
54  throw NoriException("Warp::squareToUniformDiskPdf() is not yet implemented!");
55 }
56 
57 Vector3f Warp::squareToUniformSphereCap(const Point2f &sample, float cosThetaMax) {
58  throw NoriException("Warp::squareToUniformSphereCap() is not yet implemented!");
59 }
60 
61 float Warp::squareToUniformSphereCapPdf(const Vector3f &v, float cosThetaMax) {
62  throw NoriException("Warp::squareToUniformSphereCapPdf() is not yet implemented!");
63 }
64 
66  throw NoriException("Warp::squareToUniformSphere() is not yet implemented!");
67 }
68 
70  throw NoriException("Warp::squareToUniformSpherePdf() is not yet implemented!");
71 }
72 
74  throw NoriException("Warp::squareToUniformHemisphere() is not yet implemented!");
75 }
76 
78  throw NoriException("Warp::squareToUniformHemispherePdf() is not yet implemented!");
79 }
80 
82  throw NoriException("Warp::squareToCosineHemisphere() is not yet implemented!");
83 }
84 
86  throw NoriException("Warp::squareToCosineHemispherePdf() is not yet implemented!");
87 }
88 
89 Vector3f Warp::squareToBeckmann(const Point2f &sample, float alpha) {
90  throw NoriException("Warp::squareToBeckmann() is not yet implemented!");
91 }
92 
93 float Warp::squareToBeckmannPdf(const Vector3f &m, float alpha) {
94  throw NoriException("Warp::squareToBeckmannPdf() is not yet implemented!");
95 }
96 
97 Vector3f Warp::squareToUniformTriangle(const Point2f &sample) {
98  float su1 = sqrtf(sample.x());
99  float u = 1.f - su1, v = sample.y() * su1;
100  return Vector3f(u,v,1.f-u-v);
101 }
102 
103 NORI_NAMESPACE_END
Simple exception class, which stores a human-readable error description.
Definition: common.h:148
Abstract sample generator.
Definition: sampler.h:63
virtual float next1D()=0
Retrieve the next component value from the current sample.
static float squareToUniformDiskPdf(const Point2f &p)
Probability density of squareToUniformDisk()
Definition: warp.cpp:53
static Vector3f sampleUniformHemisphere(Sampler *sampler, const Normal3f &northPole)
Uniformly sample a vector on the unit hemisphere with respect to solid angles (naive implementation)
Definition: warp.cpp:25
static float squareToUniformHemispherePdf(const Vector3f &v)
Probability density of squareToUniformHemisphere()
Definition: warp.cpp:77
static float squareToUniformSphereCapPdf(const Vector3f &v, float cosThetaMax)
Probability density of squareToUniformSphereCap()
Definition: warp.cpp:61
static Point2f squareToUniformSquare(const Point2f &sample)
Dummy warping function: takes uniformly distributed points in a square and just returns them.
Definition: warp.cpp:41
static Vector3f squareToCosineHemisphere(const Point2f &sample)
Uniformly sample a vector on the unit hemisphere around the pole (0,0,1) with respect to projected so...
Definition: warp.cpp:81
static Vector3f squareToBeckmann(const Point2f &sample, float alpha)
Warp a uniformly distributed square sample to a Beckmann distribution * cosine for the given 'alpha' ...
Definition: warp.cpp:89
static Vector3f squareToUniformSphere(const Point2f &sample)
Uniformly sample a vector on the unit sphere with respect to solid angles.
Definition: warp.cpp:65
static float squareToCosineHemispherePdf(const Vector3f &v)
Probability density of squareToCosineHemisphere()
Definition: warp.cpp:85
static Vector3f squareToUniformHemisphere(const Point2f &sample)
Uniformly sample a vector on the unit hemisphere around the pole (0,0,1) with respect to solid angles...
Definition: warp.cpp:73
static Point2f squareToUniformDisk(const Point2f &sample)
Uniformly sample a vector on a 2D disk with radius 1, centered around the origin.
Definition: warp.cpp:49
static float squareToBeckmannPdf(const Vector3f &m, float alpha)
Probability density of squareToBeckmann()
Definition: warp.cpp:93
static Vector3f squareToUniformSphereCap(const Point2f &sample, float cosThetaMax)
Uniformly sample a vector on a spherical cap around (0, 0, 1)
Definition: warp.cpp:57
static float squareToUniformSpherePdf(const Vector3f &v)
Probability density of squareToUniformSphere()
Definition: warp.cpp:69
static float squareToUniformSquarePdf(const Point2f &p)
Probability density of squareToUniformSquare()
Definition: warp.cpp:45
3-dimensional surface normal representation
Definition: vector.h:133