diff options
| author | yum <yum.food.vr@gmail.com> | 2026-03-02 17:39:03 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-03-02 17:39:03 -0800 |
| commit | fd5b8029a8303e6b0db0c9c7e309aa0075302935 (patch) | |
| tree | b8aebae783f8facc8e89afe442595ea51582a425 | |
| parent | 92c9035bb513886f99fde8c08694d9d6baa6f305 (diff) | |
More decal features
| -rwxr-xr-x | 3ner.shader | 14 | ||||
| -rw-r--r-- | decal.cginc | 20 | ||||
| -rwxr-xr-x | features.cginc | 3 | ||||
| -rwxr-xr-x | globals.cginc | 6 | ||||
| -rwxr-xr-x | math.cginc | 4 |
5 files changed, 43 insertions, 4 deletions
diff --git a/3ner.shader b/3ner.shader index 8cbbd09..9833950 100755 --- a/3ner.shader +++ b/3ner.shader @@ -70,11 +70,21 @@ Shader "yum_food/3ner" [HideInInspector] m_start_Decal0("Decal 0", Float) = 0 [ThryToggle(_DECAL0)] _Decal0_Enabled("Enable", Float) = 0 _Decal0_MainTex("Base color", 2D) = "white" {} - _Decal0_Color("Tint", Color) = (1, 1, 1, 1) + [HDR] _Decal0_Color("Tint", Color) = (1, 1, 1, 1) _Decal0_Opacity("Opacity", Range(0, 1)) = 1 [ThryWideEnum(Repeat, 0, Mirror, 1, Clamp, 2)] _Decal0_UV_Mode("UV Mode", Int) = 0 - [ThryWideEnum(AlphaBlend, 0, Multiply, 1)] _Decal0_Mix_Mode("Mix Mode", Int) = 0 + [ThryWideEnum(AlphaBlend, 0, Multiply, 1, AddProduct, 2)] _Decal0_Mix_Mode("Mix Mode", Int) = 0 [IntRange] _Decal0_UV_Channel("UV Channel", Range(0, 3)) = 0 + [ThryToggle(_DECAL0_ALBEDO_CLAMP)] _Decal0_Albedo_Clamp("Clamp albedo", Float) = 0 + + //ifex _Decal0_Mask_Enabled==0 + [HideInInspector] m_start_Decal0_Mask("Mask", Float) = 0 + [ThryToggle(_DECAL0_MASK)] _Decal0_Mask_Enabled("Enable", Float) = 0 + _Decal0_Mask("Mask", 2D) = "white" {} + [ThryToggle(_DECAL0_MASK_INVERT)] _Decal0_Mask_Invert("Invert", Float) = 0 + [IntRange] _Decal0_Mask_UV_Channel("UV Channel", Range(0, 3)) = 0 + [HideInInspector] m_end_Decal0_Mask("Mask", Float) = 0 + //endex //ifex _Decal0_Rotation_Enabled==0 [HideInInspector] m_start_Decal0_Rotation("Rotation", Float) = 0 diff --git a/decal.cginc b/decal.cginc index 69fb9e5..7673bee 100644 --- a/decal.cginc +++ b/decal.cginc @@ -39,6 +39,23 @@ void applyDecals(v2f i, inout Pbr pbr) { float4 albedo = decal_sample(_Decal0_MainTex, uv, _Decal0_UV_Mode); albedo *= _Decal0_Color; albedo.a *= _Decal0_Opacity; + +#if defined(_DECAL0_MASK) + float2 mask_uv = get_uv_by_channel(i, _Decal0_Mask_UV_Channel); + mask_uv -= _Decal0_Mask_ST.zw; + mask_uv *= _Decal0_Mask_ST.xy; + // For now, mask gets the same sampling mode as the decal. + float mask = decal_sample(_Decal0_Mask, mask_uv, _Decal0_UV_Mode); +#if defined(_DECAL0_MASK_INVERT) + mask = 1 - mask; +#endif // _DECAL0_MASK_INVERT + albedo.a *= mask; +#endif // _DECAL0_MASK + +#if defined(_DECAL0_ALBEDO_CLAMP) + albedo.rgb = saturate(albedo.rgb); +#endif // _DECAL0_ALBEDO_CLAMP + [forcecase] switch (_Decal0_Mix_Mode) { case DECAL_MIX_MODE_ALPHA_BLEND: @@ -47,6 +64,9 @@ void applyDecals(v2f i, inout Pbr pbr) { case DECAL_MIX_MODE_MULTIPLY: pbr.albedo.rgb *= lerp(1, albedo.rgb, albedo.a); break; + case DECAL_MIX_MODE_ADD_PRODUCT: + pbr.albedo.rgb += lerp(0, albedo.rgb * pbr.albedo.rgb, albedo.a); + break; } } #endif diff --git a/features.cginc b/features.cginc index 8107e94..796dcae 100755 --- a/features.cginc +++ b/features.cginc @@ -160,7 +160,10 @@ //ifex _Decal0_Enabled==0 #pragma shader_feature_local _DECAL0 +#pragma shader_feature_local _DECAL0_ALBEDO_CLAMP #pragma shader_feature_local _DECAL0_ROTATION +#pragma shader_feature_local _DECAL0_MASK +#pragma shader_feature_local _DECAL0_MASK_INVERT //endex //ifex _Matcap0_Enabled==0 diff --git a/globals.cginc b/globals.cginc index df9552e..2daab12 100755 --- a/globals.cginc +++ b/globals.cginc @@ -247,6 +247,7 @@ float _Parallax_Heightmap_Ray_Marching_Steps; #define DECAL_MIX_MODE_ALPHA_BLEND 0 #define DECAL_MIX_MODE_MULTIPLY 1 +#define DECAL_MIX_MODE_ADD_PRODUCT 2 #if defined(_DECAL0) float4 _Decal0_Color; @@ -259,6 +260,11 @@ int _Decal0_Mix_Mode; #if defined(_DECAL0_ROTATION) float _Decal0_Rotation; #endif // _DECAL0_ROTATION +#if defined(_DECAL0_MASK) +texture2D _Decal0_Mask; +float4 _Decal0_Mask_ST; +int _Decal0_Mask_UV_Channel; +#endif // _DECAL0_MASK #endif // _DECAL0 #define MATCAP_MODE_REPLACE 0 @@ -105,8 +105,8 @@ float luminance(float3 rgb) { return dot(float3(0.2126, 0.7152, 0.0722), rgb); } -float4 alpha_blend(float4 src, float4 dst) { - return float4(src.rgb * src.a + dst.rgb * (1 - src.a), src.a + dst.a * (1 - src.a)); +float4 alpha_blend(float4 front, float4 back) { + return float4(front.rgb * front.a + back.rgb * (1 - front.a), front.a + back.a * (1 - front.a)); } #endif // __MATH_INC |
