Webgl:替代编写gl_FragDepth [英] Webgl: alternative to writing to gl_FragDepth

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

问题描述

在WebGL中,是否可以写入片段的深度值或以其他方式控制片段的深度值?

In WebGL, is it possible to write to the fragment's depth value or control the fragment's depth value in some other way?

据我所知,webgl 1.x中没有gl_FragDepth,但是我想知道是否还有其他方法(扩展,特定于浏览器的支持等)来实现.

As far as I could find, gl_FragDepth is not present in webgl 1.x, but I am wondering if there is any other way (extensions, browser specific support, etc) to do it.

我要存档的是使光线跟踪的对象与使用常规模型,视图,投影绘制的其他元素一起播放.

What I want to archive is to have a ray traced object play along with other elements drawn using the usual model, view, projection.

推荐答案

有扩展名 EXT_frag_depth

由于它是扩展名,因此可能并非在所有地方都可用,因此您需要检查它是否存在.

Because it's an extension it might not be available everywhere so you need to check it exists.

var isFragDepthAvailable = gl.getExtension("EXT_frag_depth");

如果isFragDepthAvailable不为假,则可以使用

在着色器中启用它

If isFragDepthAvailable is not falsey then you can enable it in your shaders with

#extension GL_EXT_frag_depth : enable

否则,您可以在顶点着色器中操纵gl_Position.z,尽管我怀疑这并不是满足大多数需求的可行解决方案.

Otherwise you can manipulate gl_Position.z in your vertex shader though I suspect that's not really a viable solution for most needs.

这篇关于Webgl:替代编写gl_FragDepth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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