Sign in to follow this  

How to find theta of view-direction on texture space?

This topic is 4092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all, I encode theta information in another texture image using pre-processing and apply it to my pixel shader program. Because I need viewing direction information to lookup texture. I already trasform view vector to tangent space and using atan(y/x) to find theta. But the theta simily not match on the texture's theta I encode. Could someone give me a hint how to do such thing? In fact, I encode visibility information on a texture depend on theta of view direction using pre-processing. For example, a 2D 512*512 texture image. Each pixel has theta information and I define north direction is Y axis(or PI/2) and east direction is X axis(or 0 or 2*PI), etc... I want to render a planar with a texture and using the additional texture which has theta info encoded. Hope someone could help me...my math is too poor to derive such operation... thx... cavatina [Edited by - cavatina on September 27, 2006 12:38:26 PM]

Share this post


Link to post
Share on other sites
Presumably, the problem lies in calculation of the 'theta' value. Either that, or your pre-processing stage is awry, in which case you're on your own [wink].

I don't fully understand what you're doing, but I know that many people have problems with angle-vector conversion. First, could you tell us what formula you are using to transform the view vector, in particular which of your three coordinates are mapping to x, y in the two atan(x/y)s?
Second, note that tan is pi-periodic, whereas sin & cos are 2-pi periodic. A consequence of this is that atan(y/x) is only 'correct' half of the time: atan(a/b) = atan(-a/-b) although the source vectors point in opposite directions. An easy way to fix this in C++ is to use atan2(x, y).

If you're still at a loss, perhaps you could describe what is wrong with your results or perhaps provide a screenshot. If the final image doesn't resemble the source at all, you may have scaling issues, but if it is reflected/offset/wrapped, it's probably a trig issue. There are many other possibilities but I won't go into them just now.

Regards
Admiral

Share this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
Presumably, the problem lies in calculation of the 'theta' value. Either that, or your pre-processing stage is awry, in which case you're on your own [wink].

I don't fully understand what you're doing, but I know that many people have problems with angle-vector conversion. First, could you tell us what formula you are using to transform the view vector, in particular which of your three coordinates are mapping to x, y in the two atan(x/y)s?
Second, note that tan is pi-periodic, whereas sin & cos are 2-pi periodic. A consequence of this is that atan(y/x) is only 'correct' half of the time: atan(a/b) = atan(-a/-b) although the source vectors point in opposite directions. An easy way to fix this in C++ is to use atan2(x, y).

If you're still at a loss, perhaps you could describe what is wrong with your results or perhaps provide a screenshot. If the final image doesn't resemble the source at all, you may have scaling issues, but if it is reflected/offset/wrapped, it's probably a trig issue. There are many other possibilities but I won't go into them just now.

Regards
Admiral

Thanks for your kind reply.
I use n, t, b to transform view vector into tangent space in vertex shader =>
vec3 n = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(gl_NormalMatrix * Tangent);
vec3 b = cross(n, t);
v.x = dot(vVec, t);
v.y = dot(vVec, b);
v.z = dot(vVec, n);

Then in pixel shader, I use "theta = atan2(vVec.y, vVec.x)" to replace "theta = atan(vVec.y, vVec.x)" that I use originally. The result seems correct now.
Thanks a lot!!! :)

Share this post


Link to post
Share on other sites

This topic is 4092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this