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

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

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 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

Share on other sites
Quote:
 Original post by TheAdmiralPresumably, 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.RegardsAdmiral

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!!! :)

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
12
5. 5

• 14
• 9
• 22
• 9
• 31
• Forum Statistics

• Total Topics
632618
• Total Posts
3007485
• Who's Online (See full list)

There are no registered users currently online

×