Skip to main content
gamedev.net
🔒 Locked

Reading ZBuffer values

Started by Raed Feb 25, 2008 at 7:30 PM 0 replies 750+ views
Original Post
Raed
Raed
Hello All I am trying to read ZBuffer values and store them in an R32F texture. So, i use HLSL, compute the depth and output it to the red channel of the texture. After that, I copy this texture into another texture residing in system memory using device.GeTRenderTargetData(). Then I lock the new texture to start reading depth values. The problem is that the returned GraphicsStream object (I use C#) is toooo large. No matter what was the size of the texture, the size of the stream is always 2,174,483,647 bytes which is really far beyond the expected size for a 1024 by 1024 texture. The size should be 1024*1024*4 = 4,194,304 bytes. Another thing is that, in the returned buffer, if I access data beyond 4,198,272 the program crashes. i would understand if the number was 4,194,304 but there is a difference of 3968 bytes! Here is the HLSL code that outputs the depth values: float appTime; //App's time in seconds float4x4 worldMatrix; // World matrix for object float4x4 worldViewProjection; // World * View * Projection matrix float4 camPos; float zNear = 0.1; float zFar = 1000; struct a2v { float4 Position : POSITION; }; struct v2p { float4 Position : POSITION; float4 ZValue : TEXCOORD0; }; struct p2s { float4 Color : COLOR; }; void vsLin( in a2v IN, out v2p OUT ) { OUT.Position = mul(IN.Position, worldViewProjection); float4 worldPos = mul(IN.Position, worldMatrix); float distFromCam = distance(camPos, worldPos); float z = (distFromCam - zNear) / (zFar - zNear); OUT.ZValue = z; } void ps( in v2p IN, out p2s OUT) { OUT.Color = IN.ZValue; } //-------------------------------------------------------------------------------------- // Techniques //-------------------------------------------------------------------------------------- technique ZLinear { pass P0 { vertexshader = compile vs_2_0 vsLin(); pixelshader = compile ps_2_0 ps(); } } Am I doing this the right way? Help would be much appreciated. Thanks Raed
jollyjeffers
jollyjeffers
So you're trying to read from a D3DFMT_R32F texture and not D3DFMT_D32F (or whatever)??

Have you got the debug runtimes enabled? They should hopefully give you some warnings about incorrect API usage.

I suspect, GraphicsStream as an abstraction over the native library, is probably just echoing some more fundamental problem with the usage of the API...

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.