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

相关推荐
℡枫叶℡1 天前
Unity - 全局配置Unity工程的资源检索的目录
unity·资源检索配置
mxwin1 天前
Unity URP 下 TBN 矩阵学习 切线空间、tangent.w 与镜像 UV 的那些坑
学习·unity·矩阵·shader
程序猿多布1 天前
Unity导表工具解决方案-Luban使用教程
unity·luban
mxwin1 天前
Unity URP Shader 混合模式完全指南
unity·游戏引擎
mxwin1 天前
Unity URP 下 HDR 与 Tonemapping 的 Shader 意识
unity·游戏引擎
沉默金鱼1 天前
U3D高级编程:主程手记——第二章2.1读书笔记
unity·游戏引擎
mxwin1 天前
Unity Shader 深度写入与关闭ZWrite Off · 半透明排序 · 粒子穿插
unity·游戏引擎·shader
张老师带你学2 天前
宇宙飞船完整Unity项目
科技·游戏·unity·游戏引擎·模型
mxwin2 天前
Unity URP 下的流体模拟 深入解析 Navier-Stokes 方程与浅水方程的数学原理
unity·游戏引擎
mxwin2 天前
Unity Shader 深度重建世界坐标
unity·游戏引擎·shader