Skip to main content
gamedev.net
🔒 Locked

Depth rendering wrong

Started by ooooooooOoo Apr 6, 2009 at 7:33 PM 4 replies 800+ views
Original Post
ooooooooOoo
ooooooooOoo
I thought I had sorted my depth rendering problem out, but something is still amiss. I'm doing per-pixel fog and packing the results of short, medium and long ranges into the rgb value of my depth render target. Because of the way I've packed it into different channels, it should display as black for close, red for short, yellow for medium and white for far. Somehow I'm getting a weird spot that moves around in relation to the camera, almost like some kind of evil specular hilight. It's not specific to any one object such as my terrain. Depth map: http://www.flickr.com/photos/nih7777/3419935584/sizes/o/ Screenshot: http://www.flickr.com/photos/nih7777/3419126857/sizes/o/ Because of the way I've packed it into different channels, it should be black for close, red for short, yellow for medium and white for far. The black spot in that shot is way off in the distance however. It's messing up my transmissive textures badly.

VertexShaderOutput VertexShader(VertexShaderInput In)
{
    Out.Position = mul(mul(mul(In.Position, World), View), Projection);
    Out.TransformedPosition = Out.Position;
    float3 PositionWorld = mul(In.Position, World).xyz;
    Out.WorldView = ViewInverse[3].xyz - PositionWorld;
}

float4 PixelShader(PixelShaderInput In) : COLOR0
{
	float3 Eye = In.WorldView;
	float EyeDistance = distance(Eye, In.TransformedPosition);
}

All the examples I've found do it this way. What could I be doing wrong here? Also, would vertex fog be a better option? [Edited by - ooooooooOoo on April 6, 2009 8:09:48 PM]
owl
owl
I don't have a clue about shaders but couldn't it be that the toon shading you seem to be applying (as seen in the picture with no fog) is messing your fog up?

BTW, do you type all those ooooooOoos every time you login?
[size="2"]I like the Walrus best.
MJP
MJP
Any reason you're not just using R32F for your depth texture? It's supported on most GPU's.

How exactly are you packing your depth value? Could you post your code here?
ooooooooOoo
ooooooooOoo
Quote:
Original post by owl
I don't have a clue about shaders but couldn't it be that the toon shading you seem to be applying (as seen in the picture with no fog) is messing your fog up?

BTW, do you type all those ooooooOoos every time you login?


No, they're different passes. And no, it saves it for me. ;)

Quote:
Original post by MJP
Any reason you're not just using R32F for your depth texture? It's supported on most GPU's.

How exactly are you packing your depth value? Could you post your code here?


if (DepthEnabled) {	Colour.r = saturate(EyeDistance / 10);	Colour.g = saturate(EyeDistance / 100);	Colour.b = saturate(EyeDistance / 1000);}


I packed in different distances because I figured using a smaller value for closer gradients would give me more granularity.

I hadn't heard of R32F, is that the same as vertex fog? I'll go look it up now.
ooooooooOoo
ooooooooOoo
Righty-ho. I switched to an Rb32 surface format and shifted my depth calculation into the vertex buffer, but I'm still seeing that overlaid dot moving around.

I'm also not entirely sure how the RB32 format is intended to be used. Should I continue encoding two depth ranges into each channel?

Edit: I found a much better example that did it this way:

Out.Position = mul(mul(mul(In.Position, World), View), Projection);
Out.TransformedPosition = Out.Position;
Colour.r = saturate(In.TransformedPosition.z / 10);
Colour.g = saturate(In.TransformedPosition.z / 100);

Now it's perfect.

[Edited by - ooooooooOoo on April 6, 2009 11:30:26 PM]
MJP
MJP
By "R32F" I meant a single-channel 32-bit floating-point format. In D3D9 it's known as D3DFMT_R32F, and in D3D10 it's known as DXGI_FORMAT_R32_FLOAT. This format is ideal for depth, since it gives you a single high precision value to work with.

To write to it you just put the value you want stored in the red channel, and put 1's in the other's:
return float4(depth, 1.0f, 1.0f, 1.0f);


Topic Locked

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

Sign in to reply to this topic.