From 84122dd0435a503da2636d7a59db21926782dac6 Mon Sep 17 00:00:00 2001 From: yum Date: Sun, 30 Nov 2025 16:50:57 -0800 Subject: asdf --- decals.cginc | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/decals.cginc b/decals.cginc index 4812dd3..694e48d 100644 --- a/decals.cginc +++ b/decals.cginc @@ -240,6 +240,35 @@ float4 getCmykWarpingPlanesColor(DecalParams params, float2 uv) { #define APPLY_DECAL_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} +#define APPLY_DECAL_SDF_SSN_ON(i, albedo, normal_tangent, metallic, smoothness, emission, params) \ + { \ + float sdf_val = params.mainTex.SampleBias(trilinear_aniso4_repeat_s, decal_uv, params.mip_bias).r; \ + sdf_val = params.sdf_invert ? 1 - sdf_val : sdf_val; \ + \ + float sdf_dx = ddx(sdf_val); \ + float sdf_dy = ddy(sdf_val); \ + \ + float2 uv_dx = ddx(decal_uv); \ + float2 uv_dy = ddy(decal_uv); \ + \ + float det = uv_dx.x * uv_dy.y - uv_dx.y * uv_dy.x; \ + float2 sdf_grad_uv; \ + if (abs(det) < 1e-6) { \ + sdf_grad_uv = float2(0,0); \ + } else { \ + sdf_grad_uv.x = (sdf_dx * uv_dy.y - sdf_dy * uv_dx.y) / det; \ + sdf_grad_uv.y = (sdf_dy * uv_dx.x - sdf_dx * uv_dy.x) / det; \ + } \ + \ + float2 scaled_grad = sdf_grad_uv * params.sdf_ssn_strength * decal_albedo.a * params.opacity; \ + \ + float3 sdf_normal_ts = normalize(float3(-scaled_grad.xy, 1.0)); \ + \ + normal_tangent = blendNormalsHill12(normal_tangent, sdf_normal_ts); \ + } + +#define APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, params) {} + void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, inout float metallic, inout float smoothness, inout float3 emission) { DecalParams decal; #if defined(_DECAL0) @@ -301,6 +330,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino #else APPLY_DECAL_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif + #if defined(_DECAL0_SDF_SSN) + APPLY_DECAL_SDF_SSN_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #else + APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #endif #if defined(_DECAL0_REFLECTIONS) APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else @@ -367,6 +401,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino #else APPLY_DECAL_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif + #if defined(_DECAL1_SDF_SSN) + APPLY_DECAL_SDF_SSN_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #else + APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #endif #if defined(_DECAL1_REFLECTIONS) APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else @@ -433,6 +472,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino #else APPLY_DECAL_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif + #if defined(_DECAL2_SDF_SSN) + APPLY_DECAL_SDF_SSN_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #else + APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #endif #if defined(_DECAL2_REFLECTIONS) APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else @@ -499,6 +543,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino #else APPLY_DECAL_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif + #if defined(_DECAL3_SDF_SSN) + APPLY_DECAL_SDF_SSN_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #else + APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #endif #if defined(_DECAL3_REFLECTIONS) APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else @@ -565,6 +614,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino #else APPLY_DECAL_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif + #if defined(_DECAL4_SDF_SSN) + APPLY_DECAL_SDF_SSN_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #else + APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #endif #if defined(_DECAL4_REFLECTIONS) APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else @@ -631,6 +685,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino #else APPLY_DECAL_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif + #if defined(_DECAL5_SDF_SSN) + APPLY_DECAL_SDF_SSN_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #else + APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #endif #if defined(_DECAL5_REFLECTIONS) APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else @@ -697,6 +756,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino #else APPLY_DECAL_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif + #if defined(_DECAL6_SDF_SSN) + APPLY_DECAL_SDF_SSN_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #else + APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #endif #if defined(_DECAL6_REFLECTIONS) APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else @@ -763,6 +827,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino #else APPLY_DECAL_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #endif + #if defined(_DECAL7_SDF_SSN) + APPLY_DECAL_SDF_SSN_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #else + APPLY_DECAL_SDF_SSN_OFF(i, albedo, normal_tangent, metallic, smoothness, emission, decal); + #endif #if defined(_DECAL7_REFLECTIONS) APPLY_DECAL_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, emission, decal); #else -- cgit v1.2.3