# Projection Space To Eye Space

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

## 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 on other sites
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).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015442
×