Original Post
Hi guys, I really need your help, as I am getting very confused. During my rendering process, I generate a scene depth texture, which is basically a 32 bits floating point render target storing the distance between the camera and the point being shaded. This distance is stored as a normalized distance (thus in [0.0..1.0]) by dividing the result by the camera z far. So far so good. However, the generated texture get heavy banding artefact, as shown in the following picture:
Please not the concentric circles in the bottom of the picture. The shaders I use to generate this depth map are the following:
Please not the concentric circles in the bottom of the picture. The shaders I use to generate this depth map are the following:
Varying mainvert(VertexInput IN,
uniform float jcamerazfar,
const uniform float4x4 matworldview,
const uniform float4x4 matworldviewproj)
{
Varying OUT;
OUT.vPosition = mul(matworldviewproj, IN.vPosition);
OUT.vPosCam = mul(matworldview, IN.vPosition);
return OUT;
}
FragmentOutput mainfrag(Varying IN, uniform float jcamerazfar)
{
FragmentOutput OUT;
float fDist = length(IN.vPosCam.xyz / IN.vPosCam.w) / jcamerazfar; // scale to [0..1]
OUT.Color = float4(fDist,fDist,fDist,fDist);
return OUT;
}
I would really appreciate any input, as I have no idea what the problem could be. Also please not that reducing the z far value to increase the precision doesn't help. I am using HLSL, full floating point precision. I understand the banding in the screenshot could be caused by the f32 value being converted in a 8bits value. However, I experience the same banding problem when using the f32 value in another shader (where it should not suffer from this effect, as the value remain a float during the whole process). Any idea ? Thanks Gregory