Unity shader中真的可以动态关闭Stencil Test吗?

这个问题很多年前就有人问了:

https://discussions.unity.com/t/how-to-disable-the-stencil-block-via-shader-properties/600273/1

最后的答案是:

set [_StencilComp] to CompareFunction.Disabled to disable the Stencil Op completely.

但是我测试了一下,Disabled只出现在了Frame Debugger中,使用RenderDoc截帧分析(DX11),设置的渲染状态仍然是StencilEnabled True:

但是我没有测试移动平台和DX12,但这应该是RHI无关的逻辑吧。

另外,如果Shader中根本不包含Stencil这段,则Stencil Eanble为false。

可是Stencil这段没法动态关闭。

由此可知,如果我上面的测试是正确的,UGUI的 UI/Default shader由于包含了Stencil,那么Stencil Test对于所有的UGUI Drawcall都是开启的。那么使用Mask似乎也不会额外影响性能了是吧,那还优化个啥呢

相关推荐
雪儿waii18 小时前
Unity 中的 Resources 详解
unity·游戏引擎
RReality1 天前
【Unity UGUI】Toggle / ToggleGroup 与 Dropdown
ui·unity·游戏引擎·图形渲染·材质
雪儿waii1 天前
Unity 中的 InvokeRepeating 详解
unity·游戏引擎
mxwin1 天前
Unity Shader 程序化生成:Shader 中的数学宇宙
unity·游戏引擎
雪儿waii1 天前
Unity 中的 Quaternion(四元数)详解
unity·游戏引擎
RReality1 天前
【Unity UGUI】ScrollRect 与 Scrollbar 深度用法
unity·游戏引擎
人邮异步社区1 天前
如何自学游戏引擎的开发?
unity·程序员·游戏引擎
郝学胜-神的一滴1 天前
[简化版 Games 101] 计算机图形学 05:二维变换下
c++·unity·图形渲染·three.js·opengl·unreal
mxwin2 天前
Unity URP 热更新兼容性:Shader 在 IL2CPP 打包下的注意事项
unity·游戏引擎
mxwin2 天前
Unity shader中TransformWorldToShadowCoord原理解析
unity·游戏引擎·shader