Recommended Posts

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:

--> 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 <= 1Now, 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).