是否由Three.js支持gl_FragDepthEXT?

时间:2021-02-06 17:52:07

I was trying to use gl_FragDepthEXT in a shader but ran into issues. Is there something I have to do to enable this extension?

我试图在着色器中使用gl_FragDepthEXT但遇到了问题。有什么我必须做的事情来启用此扩展吗?

3 个解决方案

#1


It is your hardware that determines if an extension is supported or not. So what you can do is query the hardware to see if the extension is supported. If you look in the source of three.js (src/renderers/webgl/WebGLExtensions.js), there are helper function to determine if an extension is supported:

您的硬件决定是否支持扩展。因此,您可以查询硬件以查看是否支持扩展。如果你查看three.js的源代码(src / renderers / webgl / WebGLExtensions.js),有一个帮助函数来确定是否支持扩展:

// assuming here that _gl is the webgl context

var extensions = new THREE.WebGLExtensions( _gl );

// the return value is null if the extension is not supported,
// or otherwise an extension object 
extensions.get( "gl_FragDepthEXT" );

or in pure webGL:

或者在纯webGL中:

// returns an array of strings, one for each supported extension
// for informational purposes only
var available_extensions = _gl.getSupportedExtensions();

// the return value is null if the extension is not supported,
// or otherwise an extension object 
var object_ext = _gl.getExtension( "gl_FragDepthEXT" );

#2


Yes, you are missing one requirement, when you are using a raw shader you must enable with the following string in your shader code:

是的,您缺少一个要求,当您使用原始着色器时,必须在着色器代码中使用以下字符串启用:

"#extension GL_EXT_frag_depth : enable"

“#extension GL_EXT_frag_depth:enable”

When using a THREE.ShaderMaterial the program string is partly auto-generated therefore the above string cannot be added early enough in your shader strings to avoid a shader compiler error so you enable with:

当使用THREE.ShaderMaterial时,程序字符串部分是自动生成的,因此无法在着色器字符串中尽早添加上述字符串以避免着色器编译器错误,因此您启用了:

material.extensions.fragDepth = true

material.extensions.fragDepth = true

This will make gl_FragDepthEXT available as a fragment shader output if the extension is supported.

如果支持扩展,这将使gl_FragDepthEXT可用作片段着色器输出。

#3


Answering your question from the comments above, re: how well extension is supported. You can check http://webglstats.com/ to get a idea of webgl extensions currently supported by Devices/OS/Browser. The data comes from visitors on the participating websites only, but it should give you a general idea.

从上面的评论回答你的问题,重新:支持扩展的程度。您可以查看http://webglstats.com/,了解Devices / OS / Browser当前支持的webgl扩展。数据仅来自参与网站上的访问者,但它应该为您提供一般概念。

#1


It is your hardware that determines if an extension is supported or not. So what you can do is query the hardware to see if the extension is supported. If you look in the source of three.js (src/renderers/webgl/WebGLExtensions.js), there are helper function to determine if an extension is supported:

您的硬件决定是否支持扩展。因此,您可以查询硬件以查看是否支持扩展。如果你查看three.js的源代码(src / renderers / webgl / WebGLExtensions.js),有一个帮助函数来确定是否支持扩展:

// assuming here that _gl is the webgl context

var extensions = new THREE.WebGLExtensions( _gl );

// the return value is null if the extension is not supported,
// or otherwise an extension object 
extensions.get( "gl_FragDepthEXT" );

or in pure webGL:

或者在纯webGL中:

// returns an array of strings, one for each supported extension
// for informational purposes only
var available_extensions = _gl.getSupportedExtensions();

// the return value is null if the extension is not supported,
// or otherwise an extension object 
var object_ext = _gl.getExtension( "gl_FragDepthEXT" );

#2


Yes, you are missing one requirement, when you are using a raw shader you must enable with the following string in your shader code:

是的,您缺少一个要求,当您使用原始着色器时,必须在着色器代码中使用以下字符串启用:

"#extension GL_EXT_frag_depth : enable"

“#extension GL_EXT_frag_depth:enable”

When using a THREE.ShaderMaterial the program string is partly auto-generated therefore the above string cannot be added early enough in your shader strings to avoid a shader compiler error so you enable with:

当使用THREE.ShaderMaterial时,程序字符串部分是自动生成的,因此无法在着色器字符串中尽早添加上述字符串以避免着色器编译器错误,因此您启用了:

material.extensions.fragDepth = true

material.extensions.fragDepth = true

This will make gl_FragDepthEXT available as a fragment shader output if the extension is supported.

如果支持扩展,这将使gl_FragDepthEXT可用作片段着色器输出。

#3


Answering your question from the comments above, re: how well extension is supported. You can check http://webglstats.com/ to get a idea of webgl extensions currently supported by Devices/OS/Browser. The data comes from visitors on the participating websites only, but it should give you a general idea.

从上面的评论回答你的问题,重新:支持扩展的程度。您可以查看http://webglstats.com/,了解Devices / OS / Browser当前支持的webgl扩展。数据仅来自参与网站上的访问者,但它应该为您提供一般概念。