I’m trying to add an extra parameter to StandardSurfaceOutput to do some additional calculations inside the lighting function.
I created a custom struct that mimics SurfaceOutputStandard, like so…
struct SurfaceOutputCustom
{
fixed3 Albedo; // base (diffuse or specular) color
float3 Normal; // tangent space normal, if written
half3 Emission;
half Metallic; // 0=non-metal, 1=metal
half Smoothness; // 0=rough, 1=smooth
half Occlusion; // occlusion (default 1)
fixed Alpha; // alpha for transparencies
// extra parameter...
};
inline half4 LightingCustom(SurfaceOutputCustom s, half3 viewDir, UnityGI gi)
{
// extra calculations...
SurfaceOutputStandard standard;
standard.Albedo = s.Albedo;
standard.Normal = s.Normal;
standard.Emission = s.Emission;
standard.Metallic = s.Metallic;
standard.Smoothness = s.Smoothness;
standard.Occlusion = s.Occlusion;
standard.Alpha = s.Alpha;
return LightingStandard(standard, viewDir, gi) + extraStuff;
}
However, when I change my surface shader to use this new struct, the alpha behaviour of my shader changes.
When I looked at the compiled shader code, I noticed that changing to the custom struct also modified these two lines:
I’m not sure why changing this struct should cause these changes in the compiled shader. I can’t figure out a way to use the custom struct while maintaining the old alpha behaviour.
Does anyone know what’s going on here?
