除了执行我自己的光线投射之外,如何使用WebGL API,如何从深度缓冲区中获取一个值,或者如何以其他方式从屏幕坐标中确定3D坐标(即找到被点击的位置)?
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), other than by performing my own raycasting?
推荐答案几年过去了,这些天WEBGL_depth_texture扩展名广泛可用...除非您需要支持IE.
Several years have passed, these days the WEBGL_depth_texture extension is widely available... unless you need to support IE.
一般用法:
准备工作:
渲染:
取消绑定帧缓冲区,将深度纹理传递到着色器,并像读取其他任何纹理一样读取它:
Unbind the framebuffer, pass the depth texture to your shaders and read it like any other texture: texPos.xyz = (gl_Position.xyz / gl_Position.w) * 0.5 + 0.5; float depthFromZBuffer = texture2D(uTexDepthBuffer, texPos.xy).x;
更多推荐
如何读取WebGL中的深度缓冲区?
发布评论