[unity] Fixed single pass additive slot blend mode for all URP and LWRP shaders (2D and 3D). Closes #1850.

This commit is contained in:
Harald Csaszar 2021-03-03 20:17:03 +01:00
parent 16e3de63cc
commit c5c71747c3
6 changed files with 56 additions and 36 deletions

View File

@ -59,6 +59,8 @@ VertexOutput vert(appdata v) {
float3 positionWS = TransformObjectToWorld(v.pos);
half3 fixedNormal = half3(0, 0, -1);
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
o.uv0 = v.uv0;
o.pos = TransformWorldToHClip(positionWS);
#ifdef _DOUBLE_SIDED_LIGHTING
// unfortunately we have to compute the sign here in the vertex shader
@ -69,7 +71,16 @@ VertexOutput vert(appdata v) {
#endif
half3 shadowedColor;
color.rgb = LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
if (color.a == 0) {
o.color = color;
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
o.shadowedColor = color;
o.shadowCoord = float4(0, 0, 0, 0);
#endif
return o;
}
color.rgb *= LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
o.shadowedColor = shadowedColor;
#endif
@ -78,10 +89,7 @@ VertexOutput vert(appdata v) {
half3 vertexSH;
OUTPUT_SH(normalWS.xyz, vertexSH);
color.rgb += SAMPLE_GI(input.lightmapUV, vertexSH, normalWS);
o.color = color;
o.uv0 = v.uv0;
o.pos = TransformWorldToHClip(positionWS);
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
VertexPositionInputs vertexInput;
@ -94,22 +102,19 @@ VertexOutput vert(appdata v) {
half4 frag(VertexOutput i) : SV_Target{
half4 tex = tex2D(_MainTex, i.uv0);
half4 col;
#if defined(_STRAIGHT_ALPHA_INPUT)
tex.rgb *= tex.a;
#endif
if (i.color.a == 0)
return tex * i.color;
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord);
i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation);
#endif
#if defined(_STRAIGHT_ALPHA_INPUT)
col.rgb = tex.rgb * i.color.rgb * tex.a;
#else
col.rgb = tex.rgb * i.color.rgb;
#endif
col.a = tex.a * i.color.a;
return col;
return tex * i.color;
}
#endif

View File

@ -213,6 +213,10 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
ALPHA_CLIP(texureColor, input.vertexColor)
#if !defined(_MULTIPLYBLEND) && !defined(_MULTIPLYBLEND_X2)
if (input.vertexColor.a == 0)
return texureColor * input.vertexColor;
#endif
// fill out InputData struct
InputData inputData;

View File

@ -89,6 +89,10 @@ half4 CombinedShapeLightFragment(VertexOutputSpriteURP2D input) : SV_Target
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
ALPHA_CLIP(texureColor, input.vertexColor)
texureColor *= input.vertexColor;
#if !defined(_MULTIPLYBLEND) && !defined(_MULTIPLYBLEND_X2)
if (input.vertexColor.a == 0)
return texureColor;
#endif
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, input.texcoord.xy);
half4 pixel = CombinedShapeLightShared(texureColor, mask, input.lightingUV);

View File

@ -98,14 +98,13 @@
half4 CombinedShapeLightFragment(Varyings i) : SV_Target
{
half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
half4 main;
#if defined(_STRAIGHT_ALPHA_INPUT)
main.rgb = tex.rgb * i.color.rgb * tex.a;
#else
main.rgb = tex.rgb * i.color.rgb;
tex.rgb *= tex.a;
#endif
main.a = tex.a * i.color.a;
half4 main = tex * i.color;
if (i.color.a == 0)
return main;
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
return CombinedShapeLightShared(main, mask, i.lightingUV);

View File

@ -59,6 +59,8 @@ VertexOutput vert(appdata v) {
float3 positionWS = TransformObjectToWorld(v.pos);
half3 fixedNormal = half3(0, 0, -1);
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
o.uv0 = v.uv0;
o.pos = TransformWorldToHClip(positionWS);
#ifdef _DOUBLE_SIDED_LIGHTING
// unfortunately we have to compute the sign here in the vertex shader
@ -69,7 +71,16 @@ VertexOutput vert(appdata v) {
#endif
half3 shadowedColor;
color.rgb = LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
if (color.a == 0) {
o.color = color;
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
o.shadowedColor = color;
o.shadowCoord = float4(0, 0, 0, 0);
#endif
return o;
}
color.rgb *= LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
o.shadowedColor = shadowedColor;
#endif
@ -78,10 +89,7 @@ VertexOutput vert(appdata v) {
half3 vertexSH;
OUTPUT_SH(normalWS.xyz, vertexSH);
color.rgb += SAMPLE_GI(input.lightmapUV, vertexSH, normalWS);
o.color = color;
o.uv0 = v.uv0;
o.pos = TransformWorldToHClip(positionWS);
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
VertexPositionInputs vertexInput;
@ -94,22 +102,18 @@ VertexOutput vert(appdata v) {
half4 frag(VertexOutput i) : SV_Target{
half4 tex = tex2D(_MainTex, i.uv0);
half4 col;
#if defined(_STRAIGHT_ALPHA_INPUT)
tex.rgb *= tex.a;
#endif
if (i.color.a == 0)
return tex * i.color;
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord);
i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation);
#endif
#if defined(_STRAIGHT_ALPHA_INPUT)
col.rgb = tex.rgb * i.color.rgb * tex.a;
#else
col.rgb = tex.rgb * i.color.rgb;
#endif
col.a = tex.a * i.color.a;
return col;
return tex * i.color;
}
#endif

View File

@ -223,6 +223,10 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
ALPHA_CLIP(texureColor, input.vertexColor)
#if !defined(_MULTIPLYBLEND) && !defined(_MULTIPLYBLEND_X2)
if (input.vertexColor.a == 0)
return texureColor * input.vertexColor;
#endif
// fill out InputData struct
InputData inputData;