Fade object out per pixel

Recommended Posts

I am trying to fade out an object at a per pixel level. I haven't done many pixel shaders and I can't find much information on how to achieve this.
The texdepth instruction is for ps1.4, I am using HLSL and ps2
There is a Depth register.
struct PS_OUTPUT
{
float4 Color[4] : COLOR0;
float Depth : DEPTH;
};
PS_OUTPUT main(void)
{
PS_OUTPUT out = (PS_OUTPUT)0;
// Shader statements
...
// Write up to four pixel shader output colors
out.Color[0] = ...
out.Color[1] = ...
out.Color[2] = ...
out.Color[3] = ...
// Write pixel depth
out.Depth = ...
return out;
}
But thats just writing to the depth register. I need to set the colour to the existing colour and alpha to a value based on the depth or z-buffer value.

0

Share this post

Link to post

Share on other sites

If you want to access the position from a pixel shader you need to pass it in as an interpolated value through a texture coordinate. In your vertex shader write out the position (or just the z value if that's all you need) to a tex coord output and then you can use it in your pixel shader. Here's an example - I've just modified simple.fx from the DX9 SDK, it should load into EffectEdit: