summaryrefslogtreecommitdiffstats
path: root/decal.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-07-28 10:08:59 -0700
committeryum <yum.food.vr@gmail.com>2026-07-28 10:08:59 -0700
commit70f2b5fa235ec7b23eb8d9710bd7a3e5934211df (patch)
tree69cb485cef3318854b09919a8ff10e88a787944c /decal.cginc
parent110b619e8579a946f2448c61da380a8e4ae8cc48 (diff)
Add replace alpha option to decals
Diffstat (limited to 'decal.cginc')
-rw-r--r--decal.cginc56
1 files changed, 55 insertions, 1 deletions
diff --git a/decal.cginc b/decal.cginc
index a2092da..e917fdf 100644
--- a/decal.cginc
+++ b/decal.cginc
@@ -27,6 +27,58 @@ float2 decal_rotate(float2 uv, float rotation) {
return float2(d.x * c - d.y * s, d.x * s + d.y * c) + 0.5;
}
+#if defined(_DECAL0_REPLACE_ALPHA)
+#define APPLY_DECAL_REPLACE_ALPHA_0 pbr.albedo.a = lerp(albedo_alpha_before_decal, decal_alpha_at_full_opacity, _Decal0_Opacity);
+#else
+#define APPLY_DECAL_REPLACE_ALPHA_0
+#endif
+#if defined(_DECAL1_REPLACE_ALPHA)
+#define APPLY_DECAL_REPLACE_ALPHA_1 pbr.albedo.a = lerp(albedo_alpha_before_decal, decal_alpha_at_full_opacity, _Decal1_Opacity);
+#else
+#define APPLY_DECAL_REPLACE_ALPHA_1
+#endif
+#if defined(_DECAL2_REPLACE_ALPHA)
+#define APPLY_DECAL_REPLACE_ALPHA_2 pbr.albedo.a = lerp(albedo_alpha_before_decal, decal_alpha_at_full_opacity, _Decal2_Opacity);
+#else
+#define APPLY_DECAL_REPLACE_ALPHA_2
+#endif
+#if defined(_DECAL3_REPLACE_ALPHA)
+#define APPLY_DECAL_REPLACE_ALPHA_3 pbr.albedo.a = lerp(albedo_alpha_before_decal, decal_alpha_at_full_opacity, _Decal3_Opacity);
+#else
+#define APPLY_DECAL_REPLACE_ALPHA_3
+#endif
+#if defined(_DECAL4_REPLACE_ALPHA)
+#define APPLY_DECAL_REPLACE_ALPHA_4 pbr.albedo.a = lerp(albedo_alpha_before_decal, decal_alpha_at_full_opacity, _Decal4_Opacity);
+#else
+#define APPLY_DECAL_REPLACE_ALPHA_4
+#endif
+#if defined(_DECAL5_REPLACE_ALPHA)
+#define APPLY_DECAL_REPLACE_ALPHA_5 pbr.albedo.a = lerp(albedo_alpha_before_decal, decal_alpha_at_full_opacity, _Decal5_Opacity);
+#else
+#define APPLY_DECAL_REPLACE_ALPHA_5
+#endif
+#if defined(_DECAL6_REPLACE_ALPHA)
+#define APPLY_DECAL_REPLACE_ALPHA_6 pbr.albedo.a = lerp(albedo_alpha_before_decal, decal_alpha_at_full_opacity, _Decal6_Opacity);
+#else
+#define APPLY_DECAL_REPLACE_ALPHA_6
+#endif
+#if defined(_DECAL7_REPLACE_ALPHA)
+#define APPLY_DECAL_REPLACE_ALPHA_7 pbr.albedo.a = lerp(albedo_alpha_before_decal, decal_alpha_at_full_opacity, _Decal7_Opacity);
+#else
+#define APPLY_DECAL_REPLACE_ALPHA_7
+#endif
+
+#if defined(_DECAL0_REPLACE_ALPHA) || defined(_DECAL1_REPLACE_ALPHA) || defined(_DECAL2_REPLACE_ALPHA) || defined(_DECAL3_REPLACE_ALPHA) || defined(_DECAL4_REPLACE_ALPHA) || defined(_DECAL5_REPLACE_ALPHA) || defined(_DECAL6_REPLACE_ALPHA) || defined(_DECAL7_REPLACE_ALPHA)
+#define PREPARE_DECAL_REPLACE_ALPHA \
+ float albedo_alpha_before_decal = pbr.albedo.a; \
+ float decal_alpha_at_full_opacity = albedo.a;
+#else
+#define PREPARE_DECAL_REPLACE_ALPHA
+#endif
+
+#define APPLY_DECAL_REPLACE_ALPHA_IMPL(N) APPLY_DECAL_REPLACE_ALPHA_##N
+#define APPLY_DECAL_REPLACE_ALPHA(N) APPLY_DECAL_REPLACE_ALPHA_IMPL(N)
+
#define APPLY_DECAL(N) \
{ \
float2 uv = get_uv_by_channel(i, _Decal##N##_UV_Channel); \
@@ -43,7 +95,6 @@ float2 decal_rotate(float2 uv, float rotation) {
albedo.a = smoothstep(-w, w, d); \
} \
albedo *= _Decal##N##_Color; \
- albedo.a *= _Decal##N##_Opacity; \
if (_Decal##N##_Mask_Enabled) { \
float2 mask_uv = get_uv_by_channel(i, _Decal##N##_Mask_UV_Channel); \
mask_uv -= _Decal##N##_Mask_ST.zw; \
@@ -52,6 +103,8 @@ float2 decal_rotate(float2 uv, float rotation) {
if (_Decal##N##_Mask_Invert) mask = 1 - mask; \
albedo.a *= mask; \
} \
+ PREPARE_DECAL_REPLACE_ALPHA \
+ albedo.a *= _Decal##N##_Opacity; \
if (_Decal##N##_Albedo_Clamp) albedo.rgb = saturate(albedo.rgb); \
[forcecase] \
switch (_Decal##N##_Mix_Mode) { \
@@ -65,6 +118,7 @@ float2 decal_rotate(float2 uv, float rotation) {
pbr.albedo.rgb += lerp(0, albedo.rgb * pbr.albedo.rgb, albedo.a); \
break; \
} \
+ APPLY_DECAL_REPLACE_ALPHA(N) \
if (_Decal##N##_Metallic_Gloss_Enabled) { \
float4 mg = decal_sample(_Decal##N##_Metallic_Gloss, uv, _Decal##N##_UV_Mode); \
pbr.metallic = lerp(pbr.metallic, mg.r * _Decal##N##_Metallic, albedo.a); \