I use Rendertarget with scene.overrideMaterial = depthMat to get the depth map of the scene. I sampled the depth map on the full screen triangle in post-processing and saw a lot of bands of color. Is there any way to fix them? These bands affect my calculations when I use the sobel operator to calculate edges
I tried sampling the depth map directly and converting it to a linear 0-1 to eliminate the effect of the uniform value passed in, but the result did not change.
float Linear01Depth(sampler2D depthTexture, vec2 coord) {
float depth = texture2D(depthTexture, coord).x;
float x = 1. - uCameraFar / uCameraNear;
float y = uCameraFar / uCameraNear;
float z = x / uCameraFar;
float w = y / uCameraFar;
return 1.0 / (x * depth + y);
}
By the way, without setting LinearFilter, you can see the change in depth, but there will be banding. This confuses me. I also tried to visualize the depth map in babylon. In babylon, if the saved depth map is 32bit, then no banding will be seen.
Try: depthTexture.minFilter = depthTexture.magFilter =NearestFilter;
Camera near 0.05-0.1 can give artefacts.
For depth without sending camera near far uniforms:
almost white,I zoomed in and saw a little bit of gray, but there were still bands.
By the way, I also tried using the depth in pmndr’s postprocess pipeline and converting it to linear01. It has obvious banding, just like the depthtexure I provided.
Commenting out the devicePixelRatio settings made it look a lot better.
I suspect because the effectcomposer and depth target are using window size, but the renderer is using non 1 devicePixelratio.
To get it to work correctly with devicePixelRatio, you might have to multiply your width/height for depth texture + composer by that ratio also.
I’m glad to see your modified demo. The banding is indeed reduced. The best solution I’ve found is to replace the LinearEyeDepth function with Linear01Depth, that is, from [near, far] to [near/far, 1]. I think the specific reason is that in linear space, the range is [near, far], the rate of change is too large and the depth map is not accurate enough. Converting to linear 01 depth can greatly reduce the banding.