问题描述
我正在用webgl编写3D应用程序,并且需要提供纹理中包含的我自己的深度数据,我当前的代码是这样做的:
I am writing a 3D application in webgl, and need to provide my own depth data that is contained within a texture, my current code does this:
VS:
varying vec2 vUv;
void main() {
vUv = uv;
}
FS:
uniform sampler2D depthTex;
varying vec2 vUv;
void main() {
gl_FragDepth = texture2D(depthTex, vUv).r;
}
但是在opengl-es(和webgl)中禁用了gl_FragDepth
,是否有某种方式可以启用它,或者以任何方式提供我自己的深度数据而又不涉及渲染目标的繁重操作?
however gl_FragDepth
is disabled in opengl-es (and therefor webgl) is there anyway to somehow enable it, or any way to provide my own depth data that doesnt involve heavy manipulation of render targets?
推荐答案
EXT_frag_depth扩展启用gl_FragDepthEXT的使用.您可以在此处查看是否支持浏览器.目前仅在Firefox中支持.
The EXT_frag_depth extension enables the use of gl_FragDepthEXT. You can check if your browser supports it here. At the moment it's only supported in Firefox.
可以使用
gl.getExtension("EXT_frag_depth");
您可以使用
gl.getSupportedExtensions().indexOf("EXT_frag_depth") >= 0
这篇关于在WebGL中使用gl_FragDepth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!