diff options
| author | yum <yum.food.vr@gmail.com> | 2026-03-07 16:56:29 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-03-07 16:56:29 -0800 |
| commit | eb56b40f4a67530eab5422f374bfbcad71b1c6a0 (patch) | |
| tree | 0e98af9583b9df1ad973916bc3fd7cc01a7593da /decal.cginc | |
| parent | 94a91e950a02958488b4a223fab8f436d924f7de (diff) | |
Add normal map to decals
Diffstat (limited to 'decal.cginc')
| -rw-r--r-- | decal.cginc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/decal.cginc b/decal.cginc index 10b2f7a..bfd4bf5 100644 --- a/decal.cginc +++ b/decal.cginc @@ -1,8 +1,7 @@ #ifndef __DECAL_INC #define __DECAL_INC -#include "globals.cginc" -#include "pbr.cginc" +#include "data.cginc" #include "interpolators.cginc" #include "texture_utils.cginc" @@ -30,10 +29,10 @@ float2 decal_rotate(float2 uv, float rotation) { #define APPLY_DECAL(N) \ { \ float2 uv = get_uv_by_channel(i, _Decal##N##_UV_Channel); \ - if (_Decal##N##_Rotation_Enabled) \ - uv = decal_rotate(uv, _Decal##N##_Rotation); \ uv -= _Decal##N##_MainTex_ST.zw; \ uv *= _Decal##N##_MainTex_ST.xy; \ + if (_Decal##N##_Rotation_Enabled) \ + uv = decal_rotate(uv, _Decal##N##_Rotation); \ 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; \ @@ -72,9 +71,14 @@ float2 decal_rotate(float2 uv, float rotation) { pbr.roughness_perceptual = clamp(1 - pbr.smoothness, MIN_PERCEPTUAL_ROUGHNESS, 1); \ pbr.roughness = clamp(pbr.roughness_perceptual * pbr.roughness_perceptual, MIN_ROUGHNESS, 1); \ } \ + if (_Decal##N##_Normal_Enabled) { \ + float3 dn = UnpackNormal(decal_sample(_Decal##N##_Normal, uv, _Decal##N##_UV_Mode)); \ + dn.xy *= _Decal##N##_Normal_Scale; \ + normal_tangent = blendNormalsHill12(normal_tangent, float3(dn.xy * albedo.a, dn.z)); \ + } \ } -void applyDecals(v2f i, inout Pbr pbr) { +void applyDecals(v2f i, inout Pbr pbr, inout float3 normal_tangent) { #if defined(_DECAL0) APPLY_DECAL(0) #endif |
