Photon mapping questions

Started by
13 comments, last by Eelco 18 years, 9 months ago
Hi! I'm interested in writing 3D renderer that uses Real-time Photon Mapping (as per Tim Joznowski's thesis). I have couple of questions for which I couldn't find answer in the thesis: * Given two random polar coordinates, theta = [0..pi/2] and phi = [0..2*pi], how do I calculate a point on the surface of a hemisphere lying on an arbitrary plane? I understand that if the plane normal is coincident with Z-axis, it can be done like this:

v.x = sin(theta)*cos(phi)
v.y = sin(theta)*sin(phi)
v.z = cos(theta)
But how is this generalized for arbitrary planes? I ask this because this is obviously needed for the diffusive reflections. * Why use polar coordinates at all? Why shouldn't we instead use unit vectors to store the incident angles and generate the reflection vectors directly from them? Has this something to do with being able to uniformly generate random diffusive reflection vectors?
Advertisement
You can create an orthonormal basis aligned with the normal of the plane, e.g.:

normal is the normal of the plane.

 epsilon = 0.001  w = normalize( normal ) u = cross (w, vector3(1,0,0) )  if( length(u) < epsilon )   u = cross( w, vector3(0,1,0) ) u = normalize( u ) v = cross( w, u )


(This perhaps isn't the best way to do it, but it works ok).

You can now rotate the computed vector into the basis:

 x = sin(theta)*cos(phi) y = sin(theta)*sin(phi) z = cos(theta) x' = x * u y' = y * v z' = z * w


(x',y',z') will now be your vector. The use of polar coordinates is usually to facilitate computing cosine weighted (or some other weighting) vectors, e.g.:

 r1, r2 = uniform random numbers in [0..1] cos_theta = sqrt (1.0 - (r1))  phi = 2.0 *. pi *. (r2) sin_theta = sqrt (1.0 -. sqr cos_theta)  x = (cos phi *. sin_theta) y = (sin phi *. sin_theta) z = (cos_theta)
Quote:Original post by ZiM
* Given two random polar coordinates, theta = [0..pi/2] and phi = [0..2*pi], how do I calculate a point on the surface of a hemisphere lying on an arbitrary plane?


impossible.

its an indetermined problem. youd need a full coordinate basis, not just a normal, to relate your polar coordinates to in a meaningfull way.

if you want to generate uniformly distributed random vectors on a sphere, there are better methods that do not involve polar coordinates. are you sure that in this paper, polar coordinates are not just purely used for graphs/proofs? they are generally a poor tool for actual implementations.
It's not impossible, and since the distribution is invariant with rotation around the normal you can just pick any basis you want. If the distribution is not invariant then you likely have a second direction vector to fix the rotation (e.g. a phong distribution).
Quote:Original post by Eelco
Quote:Original post by ZiM
* Given two random polar coordinates, theta = [0..pi/2] and phi = [0..2*pi], how do I calculate a point on the surface of a hemisphere lying on an arbitrary plane?


impossible.

its an indetermined problem. youd need a full coordinate basis, not just a normal, to relate your polar coordinates to in a meaningfull way.

if you want to generate uniformly distributed random vectors on a sphere, there are better methods that do not involve polar coordinates. are you sure that in this paper, polar coordinates are not just purely used for graphs/proofs? they are generally a poor tool for actual implementations.


What are you saying?

I did this in my raytracer to find a random diffusely reflected vector... All you need is a normal vector for the plane.

Once you have this normal, you can find the orthogonal complement of its system (elementary linear algebra). This will give you two vectors that are perpendicular to the normal. You can then make the two vector orthogonal to one another using linear algebra techniques. You can then easily find a point on the unit sphere using the orthonormal basis made of the normal and the two orthonormal vectors you have just created.

However... This might be what you mean. A specific set of polar coordinates is going to be meaningless, as the orthonormal basis that is generated is unpredictable. But in this case, they are random polar coordinates, so it doesn't really matter.

Looking for a serious game project?
www.xgameproject.com
Avoid polar coordinates completely.

Create a random vector distributed uniformly on the sphere.
(generate random x,y,z, if x^2+y^2+z^2 > 1 or too close to centre then generate new vector else divide by length)

Now if dot(vector, normal)<
Reposted because of HTML errors,

Avoid polar coordinates completely.

Create a random vector distributed uniformly on the sphere.
(generate random x,y,z, if x^2+y^2+z^2 > 1 or too close to centre then generate new vector else divide by length)

Now if dot(vector, normal) < 0 then vector = -vector
this flips the half of the sphere facing away from the normal onto the half facing in the same direction as the normal, thus giving a hemisphere about the normal.
Quote:Original post by JuNC
It's not impossible, and since the distribution is invariant with rotation around the normal you can just pick any basis you want. If the distribution is not invariant then you likely have a second direction vector to fix the rotation (e.g. a phong distribution).


uhm yeah you can pick any basis you want, but dont you implicitly agree by making such a statement the normal alone is not enough information?
Quote:Original post by Max_Payne
Quote:Original post by Eelco
Quote:Original post by ZiM
* Given two random polar coordinates, theta = [0..pi/2] and phi = [0..2*pi], how do I calculate a point on the surface of a hemisphere lying on an arbitrary plane?


impossible.

its an indetermined problem. youd need a full coordinate basis, not just a normal, to relate your polar coordinates to in a meaningfull way.

if you want to generate uniformly distributed random vectors on a sphere, there are better methods that do not involve polar coordinates. are you sure that in this paper, polar coordinates are not just purely used for graphs/proofs? they are generally a poor tool for actual implementations.


What are you saying?

I did this in my raytracer to find a random diffusely reflected vector... All you need is a normal vector for the plane.

Once you have this normal, you can find the orthogonal complement of its system (elementary linear algebra). This will give you two vectors that are perpendicular to the normal. You can then make the two vector orthogonal to one another using linear algebra techniques. You can then easily find a point on the unit sphere using the orthonormal basis made of the normal and the two orthonormal vectors you have just created.

However... This might be what you mean. A specific set of polar coordinates is going to be meaningless, as the orthonormal basis that is generated is unpredictable. But in this case, they are random polar coordinates, so it doesn't really matter.


it might not really matter for the endresult, but i see little reason for using this approach, as its inefficient, too much code, and mathematicly extremely unelegant.
Quote:Original post by Anonymous Poster
Reposted because of HTML errors,

Avoid polar coordinates completely.

Create a random vector distributed uniformly on the sphere.
(generate random x,y,z, if x^2+y^2+z^2 > 1 or too close to centre then generate new vector else divide by length)

Now if dot(vector, normal) < 0 then vector = -vector
this flips the half of the sphere facing away from the normal onto the half facing in the same direction as the normal, thus giving a hemisphere about the normal.


amen.

This topic is closed to new replies.

Advertisement