Game Development Community

Reading back the depth and normal information

by Dave Wagner · in Torque 3D Professional · 12/07/2010 (2:25 pm) · 5 replies

I'm in the process of moving our simulation code from TGE to T3D and need to read back the normal and depth information as a post rendering process. I'm look for advice on the best way to do this using the T3D architecture.

#1
12/07/2010 (2:43 pm)
In the definition of your post effect,set:
texture[0] = "#prepass";

In your shader:

#include "shadergen:/autogenConditioners.h"
#include "./postFx.hlsl"
#include "../torque.hlsl"

uniform sampler2D prepassTex;

float4 temp = prepassUncondition( prepassTex, IN.uv0 );
float depth = temp.w;
float3 viewSpaceNormal = temp.rgb;

A possible problem for you could be if you need to translate the normals to world space.
#2
12/07/2010 (5:37 pm)
Thanks Ivan. I should have elaborated more on what I need. I want to pull the depth and normal information off the video card into main memory.

In our old simulation, using TGE, we would read back the depth buffer and project our LADAR's, a type of laser range finder, scan pattern onto the depth buffer as a quick way of doing ray casting into the scene.

So should I use a post effect shader to write this information into another buffer and then read that buffer back from the video card or is there an easier way to do this?
#3
12/08/2010 (7:06 am)
"prepass" is a buffer,therefore you can grab the (linear) depth directly.
In the lightning code there are examples how to gain access to "prepass" and how to uncondition depth and normals (from spherical coordinates).
#4
12/09/2010 (8:41 pm)
Thanks again Ivan for all your help.

I've looked at the advancedLightingFeaturesHLSL.cpp file and played around with screenshotD3D9.cpp to try and read the "prepass" buffer into system memory but still haven't figured it out. Could you please point me in the right directions.
#5
12/10/2010 (9:38 am)
I believe a texture handle (or texture target) to this buffer will do the job.Then you have to invoke the uncondition method for this target.
You can see how the examples in advancedLightingFeaturesHLSL.cpp are organized.