Using gl_FragDepth in WebGL

喜夏-厌秋 提交于 2019-12-07 04:39:33

问题


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;
    }

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?


回答1:


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.

The extension can be loaded using

gl.getExtension("EXT_frag_depth");

And you can check if it is available programatically using

gl.getSupportedExtensions().indexOf("EXT_frag_depth") >= 0


来源:https://stackoverflow.com/questions/24499321/using-gl-fragdepth-in-webgl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!