GhGL Discussion

Hi. I’m playing with SDFs and managed to build a shader to render those. What I need is to force the shader to not draw parts of image where SDF surface is inside other Rhino geometry I have in the scene.
I try to do it using _depthBuffer which is calculated before the shader and compare the values to customly calculated depth map in the shader. I visualized both and the values don’t match the same kind of range, if that makes any sense.

For visualisation of _depthBuffer along with my custom depth map I use this code:

    vec2 uv = gl_FragCoord.xy / _viewportSize;
    vec4 buffer = texture( _depthBuffer, uv );
    float depth = ( rLen - _cameraNear ) / ( _cameraFar - _cameraNear );
    
    fragment_color = vec4( vec3( min( buffer.x, depth )), 1.0);

and it gives me this:

Spheres are populated on a XY plane and the darker objects are my SDFs that are located in a way to intersect with those spheres, but on the depth image SDFs appear closer to the camera as they are darker.
Much weirder stuff starts when I zoom in, spheres start to become white and vanish instead of becoming almost black as shown on the image below:

I’m terrible in coding and doing that SDFs took me almost a week as I learn to code almost from scratch)). I do not understand what those values in _depthBuffer represent, it doesn’t look like those are normalized values of depth between clipping planes.

Would appreciate any help on this topic.