depth and Cg shaders
I am writing a Ray tracer in Cg shading language, and want to calculate the depth to the nearest object in the fragment shader.
The ray tracer works much like a skybox, where each side in the skybox is raytraced.
Adding depth to the output enables me to add other objects (non raytraced) to the sceene. How do I calculate the depth to coorespond with the depth in the openGL depth buffer?
For reference:
A sceene with no aditional non raytraced objects.
The white box (non raytraced) is added. But since the depth information is wayback the sphere is not excluding most of the white box.
Problem solved:
found the solution here:
http://www.gpgpu.org/forums/viewtopic.php?p=14124
float zFar = 400;
float zNear = 0.1;
float z = length(ray.position-IN.Eye);
float a = zFar / ( zFar - zNear );
float b = zFar * zNear / ( zNear - zFar );
float depth = ( a + b / z );
Turned out to be quiet a simple solution.
found the solution here:
http://www.gpgpu.org/forums/viewtopic.php?p=14124
float zFar = 400;
float zNear = 0.1;
float z = length(ray.position-IN.Eye);
float a = zFar / ( zFar - zNear );
float b = zFar * zNear / ( zNear - zFar );
float depth = ( a + b / z );
Turned out to be quiet a simple solution.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement