在写SRP(unity版本2021.3.16)时出现了这样的报错内容
Builtin property offset in cbuffer overlap other stages
多次尝试发现是因为UnityPerDraw只定义了unity_ObjectToWorld
CBUFFER_START(UnityPerDraw)
float4x4 unity_ObjectToWorld;
CBUFFER_END
需要加上完整的定义,这每一条都不能少
CBUFFER_START(UnityPerDraw)
float4x4 unity_ObjectToWorld;
float4x4 unity_WorldToObject;
float4 unity_LODFade;
real4 unity_WorldTransformParams;
CBUFFER_END
猜测原因是需要保持和UnityShaderVariables.cginc保持一致,否则会覆盖原配置导致错误
建议是直接从UnityShaderVariables.cginc把这段拷贝出来
注:UnityShaderVariables.cginc在{Unity安装目录}\Editor\Data\CGIncludes目录下