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似乎也不会额外影响性能了是吧,那还优化个啥呢

相关推荐
心前阳光4 小时前
Unity发布PC软件图标不能改变
unity·游戏引擎
an869500112 小时前
unity如何在visual studio中打断点debug
unity·游戏引擎·visual studio
xcLeigh12 小时前
Unity基础:使用Transform控制物体移动——Translate与position详解
unity·游戏引擎
FairGuard手游加固14 小时前
Unity小游戏加密:global-metadata.dat与AssetBundle保护
游戏·unity·游戏引擎
狂人开飞机15 小时前
11、UI系统
游戏引擎·godot
真鬼12315 小时前
【Unity AI】Untiy链接cursor与MCP
unity·游戏引擎
WarPigs17 小时前
Unity设置人物位置无效的原因
unity
程序员正茂17 小时前
Unity3d行为树Behavior Designer Pro
unity·行为树
郝学胜-神的一滴18 小时前
C++11 工程级应用 10:减少拷贝,让容器跑得更快
服务器·开发语言·c++·游戏引擎·opengl
玖玥拾19 小时前
Lua 基础语法(八) Unity Huatuo (HybridCLR)
开发语言·unity·游戏引擎·lua