#ifndef __TRIPLANAR_INC #define __TRIPLANAR_INC #include "burley.cginc" #include "globals.cginc" #include "math.cginc" #if defined(TRIPLANAR) void sample_triplanar(texture2D tex, float3 uv, out float4 s0, out float4 s1, out float4 s2) { s0 = tex.Sample(aniso4_trilinear_repeat_s, uv.yz); s1 = tex.Sample(aniso4_trilinear_repeat_s, uv.xz); s2 = tex.Sample(aniso4_trilinear_repeat_s, uv.xy); } float3 triplanar_weights(float3 worldNormal, float3 uv) { float3 weights = abs(worldNormal); return weights / (weights.x + weights.y + weights.z); } #endif void apply_triplanar_layers(float3 worldPos, float3 normal_world, inout Pbr pbr, inout float3 normal_tangent) { #if defined(TRIPLANAR) float3 weights = triplanar_weights(normal_world, worldPos); #if defined(_TRIPLANAR_LAYER0) { float3 uv = worldPos * _Triplanar_Layer0_Scale; float4 a0, a1, a2; sample_triplanar(_Triplanar_Layer0_MainTex, uv, a0, a1, a2); float3 albedo = a0 * weights.x + a1 * weights.y + a2 * weights.z; #if defined(_TRIPLANAR_LAYER0_BURLEY) float3 burley_weights = burley_apply_blend_gamma(weights, _Triplanar_Layer0_Burley_Blend_Gamma); albedo = burley_degaussianize( _Triplanar_Layer0_MainTex_Burley_LUT, burley_apply_soft_clipping(albedo, burley_weights), true); #endif // _TRIPLANAR_LAYER0_BURLEY pbr.albedo.rgb = albedo; } #endif // _TRIPLANAR_LAYER0 #endif // TRIPLANAR } #endif // __TRIPLANAR_INC