diff options
| author | yum <yum.food.vr@gmail.com> | 2026-03-07 16:04:04 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-03-07 16:04:04 -0800 |
| commit | 94a91e950a02958488b4a223fab8f436d924f7de (patch) | |
| tree | c6d77ea32de6347f4f0f482bd07984d6c8a189d3 | |
| parent | a4b006dc873906d30f32eef15d730c31bb6bd608 (diff) | |
Add sdf mode to decals
| -rwxr-xr-x | 3ner.shader | 64 | ||||
| -rw-r--r-- | decal.cginc | 7 | ||||
| -rwxr-xr-x | globals.cginc | 3 |
3 files changed, 74 insertions, 0 deletions
diff --git a/3ner.shader b/3ner.shader index 11bc32f..31504e0 100755 --- a/3ner.shader +++ b/3ner.shader @@ -99,6 +99,14 @@ Shader "yum_food/3ner" _Decal0_Rotation("Rotation", Range(-0.5, 0.5)) = 0 [HideInInspector] m_end_Decal0_Rotation("Rotation", Float) = 0 //endex + + //ifex _Decal0_SDF_Enabled==0 + [HideInInspector] m_start_Decal0_SDF("SDF", Float) = 0 + [ThryToggle(_DECAL0_SDF)] _Decal0_SDF_Enabled("Enable", Float) = 0 + _Decal0_SDF_Threshold("Threshold", Range(0, 1)) = 0.5 + [ThryToggle(_DECAL0_SDF_INVERT)] _Decal0_SDF_Invert("Invert", Float) = 0 + [HideInInspector] m_end_Decal0_SDF("SDF", Float) = 0 + //endex [HideInInspector] m_end_Decal0("Decal 0", Float) = 0 //endex @@ -135,6 +143,14 @@ Shader "yum_food/3ner" _Decal1_Rotation("Rotation", Range(-0.5, 0.5)) = 0 [HideInInspector] m_end_Decal1_Rotation("Rotation", Float) = 0 //endex + + //ifex _Decal1_SDF_Enabled==0 + [HideInInspector] m_start_Decal1_SDF("SDF", Float) = 0 + [ThryToggle(_DECAL1_SDF)] _Decal1_SDF_Enabled("Enable", Float) = 0 + _Decal1_SDF_Threshold("Threshold", Range(0, 1)) = 0.5 + [ThryToggle(_DECAL1_SDF_INVERT)] _Decal1_SDF_Invert("Invert", Float) = 0 + [HideInInspector] m_end_Decal1_SDF("SDF", Float) = 0 + //endex [HideInInspector] m_end_Decal1("Decal 1", Float) = 0 //endex @@ -171,6 +187,14 @@ Shader "yum_food/3ner" _Decal2_Rotation("Rotation", Range(-0.5, 0.5)) = 0 [HideInInspector] m_end_Decal2_Rotation("Rotation", Float) = 0 //endex + + //ifex _Decal2_SDF_Enabled==0 + [HideInInspector] m_start_Decal2_SDF("SDF", Float) = 0 + [ThryToggle(_DECAL2_SDF)] _Decal2_SDF_Enabled("Enable", Float) = 0 + _Decal2_SDF_Threshold("Threshold", Range(0, 1)) = 0.5 + [ThryToggle(_DECAL2_SDF_INVERT)] _Decal2_SDF_Invert("Invert", Float) = 0 + [HideInInspector] m_end_Decal2_SDF("SDF", Float) = 0 + //endex [HideInInspector] m_end_Decal2("Decal 2", Float) = 0 //endex @@ -207,6 +231,14 @@ Shader "yum_food/3ner" _Decal3_Rotation("Rotation", Range(-0.5, 0.5)) = 0 [HideInInspector] m_end_Decal3_Rotation("Rotation", Float) = 0 //endex + + //ifex _Decal3_SDF_Enabled==0 + [HideInInspector] m_start_Decal3_SDF("SDF", Float) = 0 + [ThryToggle(_DECAL3_SDF)] _Decal3_SDF_Enabled("Enable", Float) = 0 + _Decal3_SDF_Threshold("Threshold", Range(0, 1)) = 0.5 + [ThryToggle(_DECAL3_SDF_INVERT)] _Decal3_SDF_Invert("Invert", Float) = 0 + [HideInInspector] m_end_Decal3_SDF("SDF", Float) = 0 + //endex [HideInInspector] m_end_Decal3("Decal 3", Float) = 0 //endex @@ -243,6 +275,14 @@ Shader "yum_food/3ner" _Decal4_Rotation("Rotation", Range(-0.5, 0.5)) = 0 [HideInInspector] m_end_Decal4_Rotation("Rotation", Float) = 0 //endex + + //ifex _Decal4_SDF_Enabled==0 + [HideInInspector] m_start_Decal4_SDF("SDF", Float) = 0 + [ThryToggle(_DECAL4_SDF)] _Decal4_SDF_Enabled("Enable", Float) = 0 + _Decal4_SDF_Threshold("Threshold", Range(0, 1)) = 0.5 + [ThryToggle(_DECAL4_SDF_INVERT)] _Decal4_SDF_Invert("Invert", Float) = 0 + [HideInInspector] m_end_Decal4_SDF("SDF", Float) = 0 + //endex [HideInInspector] m_end_Decal4("Decal 4", Float) = 0 //endex @@ -279,6 +319,14 @@ Shader "yum_food/3ner" _Decal5_Rotation("Rotation", Range(-0.5, 0.5)) = 0 [HideInInspector] m_end_Decal5_Rotation("Rotation", Float) = 0 //endex + + //ifex _Decal5_SDF_Enabled==0 + [HideInInspector] m_start_Decal5_SDF("SDF", Float) = 0 + [ThryToggle(_DECAL5_SDF)] _Decal5_SDF_Enabled("Enable", Float) = 0 + _Decal5_SDF_Threshold("Threshold", Range(0, 1)) = 0.5 + [ThryToggle(_DECAL5_SDF_INVERT)] _Decal5_SDF_Invert("Invert", Float) = 0 + [HideInInspector] m_end_Decal5_SDF("SDF", Float) = 0 + //endex [HideInInspector] m_end_Decal5("Decal 5", Float) = 0 //endex @@ -315,6 +363,14 @@ Shader "yum_food/3ner" _Decal6_Rotation("Rotation", Range(-0.5, 0.5)) = 0 [HideInInspector] m_end_Decal6_Rotation("Rotation", Float) = 0 //endex + + //ifex _Decal6_SDF_Enabled==0 + [HideInInspector] m_start_Decal6_SDF("SDF", Float) = 0 + [ThryToggle(_DECAL6_SDF)] _Decal6_SDF_Enabled("Enable", Float) = 0 + _Decal6_SDF_Threshold("Threshold", Range(0, 1)) = 0.5 + [ThryToggle(_DECAL6_SDF_INVERT)] _Decal6_SDF_Invert("Invert", Float) = 0 + [HideInInspector] m_end_Decal6_SDF("SDF", Float) = 0 + //endex [HideInInspector] m_end_Decal6("Decal 6", Float) = 0 //endex @@ -351,6 +407,14 @@ Shader "yum_food/3ner" _Decal7_Rotation("Rotation", Range(-0.5, 0.5)) = 0 [HideInInspector] m_end_Decal7_Rotation("Rotation", Float) = 0 //endex + + //ifex _Decal7_SDF_Enabled==0 + [HideInInspector] m_start_Decal7_SDF("SDF", Float) = 0 + [ThryToggle(_DECAL7_SDF)] _Decal7_SDF_Enabled("Enable", Float) = 0 + _Decal7_SDF_Threshold("Threshold", Range(0, 1)) = 0.5 + [ThryToggle(_DECAL7_SDF_INVERT)] _Decal7_SDF_Invert("Invert", Float) = 0 + [HideInInspector] m_end_Decal7_SDF("SDF", Float) = 0 + //endex [HideInInspector] m_end_Decal7("Decal 7", Float) = 0 //endex [HideInInspector] m_end_Decals("Decals", Float) = 0 diff --git a/decal.cginc b/decal.cginc index 069a42f..10b2f7a 100644 --- a/decal.cginc +++ b/decal.cginc @@ -35,6 +35,13 @@ float2 decal_rotate(float2 uv, float rotation) { uv -= _Decal##N##_MainTex_ST.zw; \ uv *= _Decal##N##_MainTex_ST.xy; \ float4 albedo = decal_sample(_Decal##N##_MainTex, uv, _Decal##N##_UV_Mode); \ + if (_Decal##N##_SDF_Enabled) { \ + float sd = _Decal##N##_SDF_Invert ? 1 - albedo.r : albedo.r; \ + float d = sd - _Decal##N##_SDF_Threshold; \ + float w = fwidth(d) * 0.5; \ + albedo.rgb = sd; \ + albedo.a = smoothstep(-w, w, d); \ + } \ albedo *= _Decal##N##_Color; \ albedo.a *= _Decal##N##_Opacity; \ if (_Decal##N##_Mask_Enabled) { \ diff --git a/globals.cginc b/globals.cginc index c3ac36c..1886a8c 100755 --- a/globals.cginc +++ b/globals.cginc @@ -265,6 +265,9 @@ float _Parallax_Heightmap_Ray_Marching_Steps; int _Decal##N##_Mask_UV_Channel; \ float _Decal##N##_Mask_Invert; \ float _Decal##N##_Albedo_Clamp; \ + float _Decal##N##_SDF_Enabled; \ + float _Decal##N##_SDF_Threshold; \ + float _Decal##N##_SDF_Invert; \ float _Decal##N##_Metallic_Gloss_Enabled; \ texture2D _Decal##N##_Metallic_Gloss; \ float4 _Decal##N##_Metallic_Gloss_ST; |
