Angle between two 3D vectors expressed as phi and theta

Started by
17 comments, last by asad_82 12 years, 11 months ago

To render the BRDF from MERL i need to index into the BRDF data. For that purpose I need to calculate local theta_IN, phi_IN and local theta_VIEW, phi_VIEW at each point on the sphere.
Although the MERL data is isotropic but still I want to have all the above four angles calculated.


Ok, so are you're just talking about converting the incoming light direction L and the view vector V into spherical coordinates?

I did a quick google and found this primer on BRDFs which describes a quick conversion between cartesian and spherical coordinates, but I presume you've already seen this?

http://www.cs.princeton.edu/courses/archive/fall06/cos526/tmp/wynn.pdf

x = cos(phi) * sin(theta)
y = sin(phi) * sin(theta)
z = cos(theta)

phi = atan (x/y)
theta = atan( sqrt(x^2 + y^2) / z^2)

Hope that helps!

Cheers, Paul.

Advertisement


x = cos(phi) * sin(theta)
y = sin(phi) * sin(theta)
z = cos(theta)

phi = atan (x/y)
theta = atan( sqrt(x^2 + y^2) / z^2)





Thanks for your attempt Wildbunny but I think you missed a point here.
The conversions you described are typical coordinate conversions from Cartesian to spherical and vice versa.

But what I need is a angle between two 3D vectors one of which is a normal vector N and the other can be a Light vector or a view vector.
This angle is simple to measure with acos stuff as I described in my first post.

But I need the two components of this angle i.e. theta and phi.
For that a coordinate needs to be built comprising of Normal vector, Tangent Vector and Binormal w.r.t to which the angles will be measured.

And then we can get the phi angle.
That where the problem is .... how to do that for each point on a sphere given normal for each point.

But what I need is a angle between two 3D vectors one of which is a normal vector N and the other can be a Light vector or a view vector.
This angle is simple to measure with acos stuff as I described in my first post.


Can you tell us why you need this angle in the first place?

I'm still not totally sure what you're attempting to do - is it not just getting light direction and view vector in spherical coordinates?

Cheers, Paul.


Can you tell us why you need this angle in the first place?
I'm still not totally sure what you're attempting to do - is it not just getting light direction and view vector in spherical coordinates?



Well a BRDF is a 4D function at each point on a surface such as theta_IN phi_IN and theta_VIEW and phi_VIEW.
So in order to index into BRDF data such as that of MERL you need to calculate these angles with the normal and tangent at each point on the sphere to get the corresponding BRDF value.
I hope you got it now.

Many people who have been working with models such a phong, Blinn Phong and Lafortune can easily get it wrong. There the concept is all together different.

The one I want to do is the actual rendering of the material from acquired BRDF data.

[quote name='wildbunny' timestamp='1304187666' post='4804797']
Can you tell us why you need this angle in the first place?
I'm still not totally sure what you're attempting to do - is it not just getting light direction and view vector in spherical coordinates?



Well a BRDF is a 4D function at each point on a surface such as theta_IN phi_IN and theta_VIEW and phi_VIEW.
[/quote]

Ok, so what are IN and VIEW?

:)


Ok, so what are IN and VIEW?



Well the IN direction is the light source direction calculated w.r.t to the surface normal and the VIEW direction is also w.r.t to the surface normal at a each point on the sphere.
Please see figure I posted of the arrangement in one of the earlier posts.

The concept is very simple I hope you are not lost any more.

[quote name='wildbunny' timestamp='1304191626' post='4804816']
Ok, so what are IN and VIEW?



Well the IN direction is the light source direction calculated w.r.t to the surface normal and the VIEW direction is also w.r.t to the surface normal at a each point on the sphere.
Please see figure I posted of the arrangement in one of the earlier posts.

The concept is very simple I hope you are not lost any more.
[/quote]

Looking at the example code that MERL provides for reading its BDRFs, it looks like the the required angles are not in tangent space as you seem to be implying, but rather in object space, accessed by what they call 'half vector difference' coordinates...

You must have seen this example code

They provide example code to map between 'standard coordinates' which appear to just be spherical coordinates, and their special coordinate system... I take it this is no good to you?

Cheers, Paul.



Looking at the example code that MERL provides for reading its BDRFs, it looks like the the required angles are not in tangent space as you seem to be implying, but rather in object space, accessed by what they call 'half vector difference' coordinates...

They provide example code to map between 'standard coordinates' which appear to just be spherical coordinates, and their special coordinate system... I take it this is no good to you?

Cheers, Paul.


Dear Paul
Thanks for it. Yes I have seen it earlier. This piece of code has to do with how the data is stored after re-parametrization from 4D to 3D.
It has nothing to do with how to display the data using local coordinate system at each point.

Asad
Well I think I have solved the issue and how I computed the four angles theta_IN phi_IN and theta_VIEW phi_VIEW locally for each point on the sphere is described below for others to validate and use as required:
I will describe it for one particular Normal vector and is valid as it is for all points on the sphere. The assumption is of a isotropic BRDF
All vectors are normalized before and during the computation.

L is light vector in Cartesian space
V is view vector in Cartesian space

N = [Nx Ny Nz] % normal vector


if abs(N(2)) ~= 1
TT = [0 1 0] % local tangent vector when surface normal is not in y direction
elseif abs(N(3)) ~= 1
TT = [0 0 1] % local tangent vector when surface normal is not in z direction
elseif abs(N(1)) ~= 1
TT = [1 0 0] % local tangent vector when surface normal is not in x direction
end

T = cross(TT,N) % get the tangent in local space

B = cross(N,T) % compute binormal which is orthogonal to both N and T

LP = L - dot(N,L) .* N % project L into the plane of surface to calculate phi_IN later

theta_IN = acos(dot(L,N) / norm(L)*norm(N)) % theta is the angle between the light and normal vector

phi_IN = atan2(dot(LP,B), dot(LP,T)) % phi is the angle computed from the projection of L onto the plane using binormal and tangent

VP = V - dot(N,V) .*N % project V into the plane of surface to calculate phi_VIEW later

theta_VIEW = acos(dot(V,N) / norm(V)*norm(N)) % theta is the angle between the view and normal vector

phi_VIEW = atan2(dot(VP,B), dot(VP,T)) % phi is the angle computed from the projection of V onto the plane using binormal and tangent

Theta should be in the range 0 - pi/2 and phi in the range 0 - 2*pi

Let me know if there is some mistake.

Cheers
Asad

This topic is closed to new replies.

Advertisement