How can I read the depth buffer in WebGL?

前端 未结 5 1059
逝去的感伤
逝去的感伤 2021-01-05 08:01

Using the WebGL API, how can I get a value from the depth buffer, or in any other way determine 3D coordinates from screen coordinates (i.e. to find a location clicked on),

5条回答
  •  醉酒成梦
    2021-01-05 08:30

    I don't know if it's possible to directly access the depth buffer but if you want depth information in a texture, you'll have to create a rgba texture, attach it as a colour attachment to an frame buffer object and render depth information into the texture, using a fragment shader that writes the depth value into gl_FragColor.

    For more information, see the answers to one of my older questions: WebGL - render depth to fbo texture does not work

    If you google for opengl es and shadow mapping or depth, you'll find more explanations and example source code.

提交回复
热议问题