From 03403b7ffb96c787ab24859bf4f5288a7e500fc8 Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 1 Dec 2025 18:37:01 -0800 Subject: add compile-time switch to alpha blend decal reflections --- 2ner.shader | 8 ++++++++ decals.cginc | 57 +++++++++++++++++++++++++++++++++++++++++---------------- features.cginc | 8 ++++++++ 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/2ner.shader b/2ner.shader index b3fd0b1..6609bdc 100644 --- a/2ner.shader +++ b/2ner.shader @@ -385,6 +385,7 @@ Shader "yum_food/2ner" //ifex _Decal0_Reflections_Enabled==0 [HideInInspector] m_start_Decal0_Reflections("Reflections", Float) = 0 [ThryToggle(_DECAL0_REFLECTIONS)] _Decal0_Reflections_Enabled("Enable", Float) = 0 + [ThryToggle(_DECAL0_REFLECTIONS_ALPHA_BLEND)] _Decal0_Reflections_Alpha_Blend("Alpha blend", Float) = 0 _Decal0_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} _Decal0_Smoothness("Smoothness", Range(0, 1)) = 0.5 _Decal0_Metallic("Metallic", Range(0, 1)) = 0.0 @@ -470,6 +471,7 @@ Shader "yum_food/2ner" //ifex _Decal1_Reflections_Enabled==0 [HideInInspector] m_start_Decal1_Reflections("Reflections", Float) = 0 [ThryToggle(_DECAL1_REFLECTIONS)] _Decal1_Reflections_Enabled("Enable", Float) = 0 + [ThryToggle(_DECAL1_REFLECTIONS_ALPHA_BLEND)] _Decal1_Reflections_Alpha_Blend("Alpha blend", Float) = 0 _Decal1_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} _Decal1_Smoothness("Smoothness", Range(0, 1)) = 0.5 _Decal1_Metallic("Metallic", Range(0, 1)) = 0.0 @@ -555,6 +557,7 @@ Shader "yum_food/2ner" //ifex _Decal2_Reflections_Enabled==0 [HideInInspector] m_start_Decal2_Reflections("Reflections", Float) = 0 [ThryToggle(_DECAL2_REFLECTIONS)] _Decal2_Reflections_Enabled("Enable", Float) = 0 + [ThryToggle(_DECAL2_REFLECTIONS_ALPHA_BLEND)] _Decal2_Reflections_Alpha_Blend("Alpha blend", Float) = 0 _Decal2_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} _Decal2_Smoothness("Smoothness", Range(0, 1)) = 0.5 _Decal2_Metallic("Metallic", Range(0, 1)) = 0.0 @@ -640,6 +643,7 @@ Shader "yum_food/2ner" //ifex _Decal3_Reflections_Enabled==0 [HideInInspector] m_start_Decal3_Reflections("Reflections", Float) = 0 [ThryToggle(_DECAL3_REFLECTIONS)] _Decal3_Reflections_Enabled("Enable", Float) = 0 + [ThryToggle(_DECAL3_REFLECTIONS_ALPHA_BLEND)] _Decal3_Reflections_Alpha_Blend("Alpha blend", Float) = 0 _Decal3_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} _Decal3_Smoothness("Smoothness", Range(0, 1)) = 0.5 _Decal3_Metallic("Metallic", Range(0, 1)) = 0.0 @@ -725,6 +729,7 @@ Shader "yum_food/2ner" //ifex _Decal4_Reflections_Enabled==0 [HideInInspector] m_start_Decal4_Reflections("Reflections", Float) = 0 [ThryToggle(_DECAL4_REFLECTIONS)] _Decal4_Reflections_Enabled("Enable", Float) = 0 + [ThryToggle(_DECAL4_REFLECTIONS_ALPHA_BLEND)] _Decal4_Reflections_Alpha_Blend("Alpha blend", Float) = 0 _Decal4_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} _Decal4_Smoothness("Smoothness", Range(0, 1)) = 0.5 _Decal4_Metallic("Metallic", Range(0, 1)) = 0.0 @@ -810,6 +815,7 @@ Shader "yum_food/2ner" //ifex _Decal5_Reflections_Enabled==0 [HideInInspector] m_start_Decal5_Reflections("Reflections", Float) = 0 [ThryToggle(_DECAL5_REFLECTIONS)] _Decal5_Reflections_Enabled("Enable", Float) = 0 + [ThryToggle(_DECAL5_REFLECTIONS_ALPHA_BLEND)] _Decal5_Reflections_Alpha_Blend("Alpha blend", Float) = 0 _Decal5_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} _Decal5_Smoothness("Smoothness", Range(0, 1)) = 0.5 _Decal5_Metallic("Metallic", Range(0, 1)) = 0.0 @@ -895,6 +901,7 @@ Shader "yum_food/2ner" //ifex _Decal6_Reflections_Enabled==0 [HideInInspector] m_start_Decal6_Reflections("Reflections", Float) = 0 [ThryToggle(_DECAL6_REFLECTIONS)] _Decal6_Reflections_Enabled("Enable", Float) = 0 + [ThryToggle(_DECAL6_REFLECTIONS_ALPHA_BLEND)] _Decal6_Reflections_Alpha_Blend("Alpha blend", Float) = 0 _Decal6_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} _Decal6_Smoothness("Smoothness", Range(0, 1)) = 0.5 _Decal6_Metallic("Metallic", Range(0, 1)) = 0.0 @@ -980,6 +987,7 @@ Shader "yum_food/2ner" //ifex _Decal7_Reflections_Enabled==0 [HideInInspector] m_start_Decal7_Reflections("Reflections", Float) = 0 [ThryToggle(_DECAL7_REFLECTIONS)] _Decal7_Reflections_Enabled("Enable", Float) = 0 + [ThryToggle(_DECAL7_REFLECTIONS_ALPHA_BLEND)] _Decal7_Reflections_Alpha_Blend("Alpha blend", Float) = 0 _Decal7_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} _Decal7_Smoothness("Smoothness", Range(0, 1)) = 0.5 _Decal7_Metallic("Metallic", Range(0, 1)) = 0.0 diff --git a/decals.cginc b/decals.cginc index e789b62..37b1196 100644 --- a/decals.cginc +++ b/decals.cginc @@ -233,10 +233,12 @@ float3 calculateSdfSsn(DecalParams params, float2 decal_uv, float4 decal_albedo) #define APPLY_DECAL_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ decal_albedo.a = lerp(0, decal_albedo.a, params.opacity); \ + float alpha_blend_amount = (1.0f - albedo.a) * decal_albedo.a; \ albedo = alphaBlend(albedo, decal_albedo); #define APPLY_DECAL_BLEND_MODE_ALPHA_BLEND_INVERTED(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ decal_albedo.a = lerp(0, decal_albedo.a, params.opacity); \ + float alpha_blend_amount = (1.0f - albedo.a) * decal_albedo.a; \ albedo = alphaBlend(decal_albedo, albedo); #define APPLY_DECAL_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ @@ -263,11 +265,16 @@ float3 calculateSdfSsn(DecalParams params, float2 decal_uv, float4 decal_albedo) #define APPLY_DECAL_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} -#define APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ +#define APPLY_DECAL_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ float4 metallic_gloss = params.metallicGlossMap.Sample(trilinear_repeat_s, decal_uv); \ metallic = lerp(metallic, metallic_gloss.r * params.metallic_value, decal_albedo.a); \ smoothness = lerp(smoothness, metallic_gloss.a * params.smoothness_value, decal_albedo.a); +#define APPLY_DECAL_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ + float4 metallic_gloss = params.metallicGlossMap.Sample(trilinear_repeat_s, decal_uv); \ + metallic = lerp(metallic, metallic_gloss.r * params.metallic_value, decal_albedo.a * alpha_blend_amount); \ + smoothness = lerp(smoothness, metallic_gloss.a * params.smoothness_value, decal_albedo.a * alpha_blend_amount); + #define APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} #define APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} @@ -344,8 +351,10 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino emission += tmp_emission; #endif - #if defined(_DECAL0_REFLECTIONS) - APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #if defined(_DECAL0_REFLECTIONS) && !defined(_DECAL0_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #elif defined(_DECAL0_REFLECTIONS) && defined(_DECAL0_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif @@ -421,8 +430,10 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino emission += tmp_emission; #endif - #if defined(_DECAL1_REFLECTIONS) - APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #if defined(_DECAL1_REFLECTIONS) && !defined(_DECAL1_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #elif defined(_DECAL1_REFLECTIONS) && defined(_DECAL1_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif @@ -498,7 +509,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino emission += tmp_emission; #endif - #if defined(_DECAL2_REFLECTIONS) + #if defined(_DECAL2_REFLECTIONS) && !defined(_DECAL2_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #elif defined(_DECAL2_REFLECTIONS) && defined(_DECAL2_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #else APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); @@ -575,8 +590,10 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino emission += tmp_emission; #endif - #if defined(_DECAL3_REFLECTIONS) - APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #if defined(_DECAL3_REFLECTIONS) && !defined(_DECAL3_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #elif defined(_DECAL3_REFLECTIONS) && defined(_DECAL3_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif @@ -652,8 +669,10 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino emission += tmp_emission; #endif - #if defined(_DECAL4_REFLECTIONS) - APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #if defined(_DECAL4_REFLECTIONS) && !defined(_DECAL4_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #elif defined(_DECAL4_REFLECTIONS) && defined(_DECAL4_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif @@ -729,8 +748,10 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino emission += tmp_emission; #endif - #if defined(_DECAL5_REFLECTIONS) - APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #if defined(_DECAL5_REFLECTIONS) && !defined(_DECAL5_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #elif defined(_DECAL5_REFLECTIONS) && defined(_DECAL5_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif @@ -806,8 +827,10 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino emission += tmp_emission; #endif - #if defined(_DECAL6_REFLECTIONS) - APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #if defined(_DECAL6_REFLECTIONS) && !defined(_DECAL6_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #elif defined(_DECAL6_REFLECTIONS) && defined(_DECAL6_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif @@ -883,8 +906,10 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino emission += tmp_emission; #endif - #if defined(_DECAL7_REFLECTIONS) - APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #if defined(_DECAL7_REFLECTIONS) && !defined(_DECAL7_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_REGULAR(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #elif defined(_DECAL7_REFLECTIONS) && defined(_DECAL7_REFLECTIONS_ALPHA_BLEND) + APPLY_DECAL_REFLECTIONS_ON_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif diff --git a/features.cginc b/features.cginc index eedcc99..2f3b4b1 100644 --- a/features.cginc +++ b/features.cginc @@ -130,6 +130,7 @@ #pragma shader_feature_local _DECAL0 #pragma shader_feature_local _DECAL0_NORMAL #pragma shader_feature_local _DECAL0_REFLECTIONS +#pragma shader_feature_local _DECAL0_REFLECTIONS_ALPHA_BLEND #pragma shader_feature_local _DECAL0_SDF #pragma shader_feature_local _DECAL0_SDF_SSN #pragma shader_feature_local _DECAL0_MASK @@ -147,6 +148,7 @@ #pragma shader_feature_local _DECAL1 #pragma shader_feature_local _DECAL1_NORMAL #pragma shader_feature_local _DECAL1_REFLECTIONS +#pragma shader_feature_local _DECAL1_REFLECTIONS_ALPHA_BLEND #pragma shader_feature_local _DECAL1_SDF #pragma shader_feature_local _DECAL1_SDF_SSN #pragma shader_feature_local _DECAL1_MASK @@ -164,6 +166,7 @@ #pragma shader_feature_local _DECAL2 #pragma shader_feature_local _DECAL2_NORMAL #pragma shader_feature_local _DECAL2_REFLECTIONS +#pragma shader_feature_local _DECAL2_REFLECTIONS_ALPHA_BLEND #pragma shader_feature_local _DECAL2_SDF #pragma shader_feature_local _DECAL2_SDF_SSN #pragma shader_feature_local _DECAL2_MASK @@ -181,6 +184,7 @@ #pragma shader_feature_local _DECAL3 #pragma shader_feature_local _DECAL3_NORMAL #pragma shader_feature_local _DECAL3_REFLECTIONS +#pragma shader_feature_local _DECAL3_REFLECTIONS_ALPHA_BLEND #pragma shader_feature_local _DECAL3_SDF #pragma shader_feature_local _DECAL3_SDF_SSN #pragma shader_feature_local _DECAL3_MASK @@ -198,6 +202,7 @@ #pragma shader_feature_local _DECAL4 #pragma shader_feature_local _DECAL4_NORMAL #pragma shader_feature_local _DECAL4_REFLECTIONS +#pragma shader_feature_local _DECAL4_REFLECTIONS_ALPHA_BLEND #pragma shader_feature_local _DECAL4_SDF #pragma shader_feature_local _DECAL4_SDF_SSN #pragma shader_feature_local _DECAL4_MASK @@ -215,6 +220,7 @@ #pragma shader_feature_local _DECAL5 #pragma shader_feature_local _DECAL5_NORMAL #pragma shader_feature_local _DECAL5_REFLECTIONS +#pragma shader_feature_local _DECAL5_REFLECTIONS_ALPHA_BLEND #pragma shader_feature_local _DECAL5_SDF #pragma shader_feature_local _DECAL5_SDF_SSN #pragma shader_feature_local _DECAL5_MASK @@ -232,6 +238,7 @@ #pragma shader_feature_local _DECAL6 #pragma shader_feature_local _DECAL6_NORMAL #pragma shader_feature_local _DECAL6_REFLECTIONS +#pragma shader_feature_local _DECAL6_REFLECTIONS_ALPHA_BLEND #pragma shader_feature_local _DECAL6_SDF #pragma shader_feature_local _DECAL6_SDF_SSN #pragma shader_feature_local _DECAL6_MASK @@ -249,6 +256,7 @@ #pragma shader_feature_local _DECAL7 #pragma shader_feature_local _DECAL7_NORMAL #pragma shader_feature_local _DECAL7_REFLECTIONS +#pragma shader_feature_local _DECAL7_REFLECTIONS_ALPHA_BLEND #pragma shader_feature_local _DECAL7_SDF #pragma shader_feature_local _DECAL7_SDF_SSN #pragma shader_feature_local _DECAL7_MASK -- cgit v1.2.3