在WebGL中使用gl_FragDepth [英] Using gl_FragDepth in WebGL

查看:881
本文介绍了在WebGL中使用gl_FragDepth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆