summaryrefslogtreecommitdiffstats
path: root/decal.cginc
diff options
context:
space:
mode:
Diffstat (limited to 'decal.cginc')
-rw-r--r--decal.cginc14
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