0
\$\begingroup\$

I'm writing a custom shader for the transparent object with built-in pipeline of Unity2022.3.9f1.

For Subshader the Tags set like below

Tags { "LightMode"="ForwardBase" "Queue"="Transparent" "RenderType"="Transparent" "IgnoreProjector" = "True"}

For base pass everything is ok and the Tags look like below

Tags { "LightMode"="ForwardBase"}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off

And for additive pass, I set them like below

Tags { "LightMode"="ForwardAdd"}
Blend SrcAlpha One // Or Blend One One
ZWrite Off

Now when a point light is on, the blending is wrong no matter Blend SrcAlpha One or Blend One One. The result looks like below

enter image description here

I'm confused what happened and how should I fix this?

PS. I'm using Blinn Phong to illuminate everything and the code is

//Lighting
UNITY_LIGHT_ATTENUATION(atten, i, i.positionWS);

float3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.positionWS));
float3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz;
float3 diffuse = _LightColor0.rgb * _Diffuse.rgb * max(0, dot(normalWS, worldLightDir));
float3 halfDir = normalize(worldLightDir + viewDir);
float3 specular = _LightColor0.rgb * _Specular.rgb * pow(max(0, dot(normalWS, halfDir)), _Gloss);
float3 lighting = ambient + (diffuse + specular) * atten;
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

The funny thing is that I get rid of ambient in the ForwardAdd pass and then it's working as I imagine.

Quite confused...

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Ambient should be applied only once, in the forward base, not repeatedly with every additional light in forward add. Otherwise you end up multiplying the ambient brightness by the number of direct lights incident on the surface. \$\endgroup\$
    – DMGregory
    Commented Sep 20, 2023 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .