huggingface / gsplat.js

JavaScript Gaussian Splatting library.
MIT License
1.26k stars 77 forks source link

Question: How do I recover depth of pixels? #89

Closed xiasun closed 3 months ago

xiasun commented 3 months ago

I was trying to recover depth info for raycasting, but when I tried to print the value gl_FragCoord.z inside RenderProgram.ts (as color output), its value is always 0.5.

Are there any solution for this kind of need? Many thanks.

Steps to reproduce:

  1. turn on depth test with gl.enable(gl.DEPTH_TEST); at this line
  2. insert the following in front of the fragment's main shader
    if (gl_FragCoord.z == 0.5) {
    fragColor = vec4(1.0, 0.0, 0.0, 1.0);
    }
    else {
    fragColor = vec4(0.0, 0.0, 1.0, 1.0);
    }
    return;
  3. run any of the example to load a splat, it will always be red.

I am wondering why is the value of gl_FragCoord.z always 0.5? And is there any other way to recover depth of fragment without this value?