Jump to content
  • Advertisement
Sign in to follow this  
PPPZZZRRR

Projection Space To Eye Space

This topic is 2996 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

I'm trying to understand Nvidia SDK 10 Code Sample: Smoke.
The Method is contained in GPU Gems 2 Chapter 30.

In rendering the Cube,the author firsted rendered the back face,and then the front face using subtractive blend.And then use the ZBuffer difference to perform raycasting.In rendering the the two faces,the author projected the zbuffer to the eye space by the following code:

float2 normalizedInputPos = float2(input.pos.x/RTWidth, input.pos.y/RTHeight);
float sceneZ = sceneDepthTex.SampleLevel(samLinearClamp, normalizedInputPos,0).r;
float2 inputPos = float2((normalizedInputPos.x*2.0)-1.0,(normalizedInputPos.y*2.0)-1.0);

sceneZ = length(float3( inputPos.x * sceneZ * tan_FovXhalf,
inputPos.y * sceneZ * tan_FovYhalf,
sceneZ ));

These lines make no sence to me,can any one explain how it works?
Many thanks.

Share this post


Link to post
Share on other sites
Advertisement
These lines are from pixel shader.

--> float2 normalizedInputPos = float2(input.pos.x/RTWidth, input.pos.y/RTHeight);
First, position of the pixel (input.pos) is normalized (by dividing it by width and height of the depth texture), so that:
0 <= normalizedInputPos.x <= 1
0 <= normalizedInputPos.y <= 1

--> float sceneZ = sceneDepthTex.SampleLevel(samLinearClamp, normalizedInputPos,0).r;
We get the depth of the pixel from the depth texture using normalized position of the pixel. The r channel of the texture contains the depth (0 <= depth <= 1).

--> float2 inputPos = float2((normalizedInputPos.x*2.0)-1.0,(normalizedInputPos.y*2.0)-1.0);
Position of the pixel is scaled, so that:
-1 <= inputPos.x <= 1
-1 <= inputPos.y <= 1
Now, inputPos is a normalized 2D vector from the centre of screen to the current pixel.

--> sceneZ = length(float3( inputPos.x * sceneZ * tan_FovXhalf,
inputPos.y * sceneZ * tan_FovYhalf,
sceneZ ));
sceneZ is a length of vector inputPos multiplied by a depth of the pixel and tan_FovXhalf(x coordinate) and tan_FovYhalf(y coordinate).
tan_FovXhalf is a tangent of a half of an angle of horizontal field of view.
tan_FovYhalf is a tangent of a half of an angle of vertical field of view.
sceneZ is a value between 0 and 1 (0 <= sceneZ <= 1).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!