#if _PCHEIGHTGRADIENT TEXTURE2D(_PCHeightGradients); #endif #if _PCHEIGHTHSV TEXTURE2D(_PCHeightHSV); #endif #if _PCSLOPEGRADIENT TEXTURE2D(_PCSlopeGradients); #endif #if _PCSLOPEHSV TEXTURE2D(_PCSlopeHSV); #endif half3 PCRGB2HSV(half3 c) { half4 K = half4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); half4 p = lerp(half4(c.bg, K.wz), half4(c.gb, K.xy), step(c.b, c.g)); half4 q = lerp(half4(p.xyw, c.r), half4(c.r, p.yzx), step(p.x, c.r)); float d = q.x - min(q.w, q.y); float e = 1.0e-10; return half3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); } half3 PCHSV2RGB(half3 c) { half4 K = half4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); half3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www); return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y); } void ProceduralGradients(Input i, inout RawSamples samples, Config c, float worldHeight, float3 worldNormal) { float offset = 0.5 * _PerTexProps_TexelSize.x; #if _PCHEIGHTGRADIENT || _PCHEIGHTHSV float center = worldHeight - _WorldHeightRange.x; float range = max(0.0001, _WorldHeightRange.y - _WorldHeightRange.x); float h = saturate(center / range); #endif #if _PCSLOPEGRADIENT || _PCSLOPEHSV half slope = dot(float3(0,0,1), worldNormal); half slope0 = slope; half slope1 = slope; half slope2 = slope; half slope3 = slope; // Take local normal into account? //half slope0 = dot(float3(0,0,1), WorldNormalVector(i, float3(samples.normSAO0.xy, 1))) * 2 - 1; //half slope1 = dot(float3(0,0,1), WorldNormalVector(i, float3(samples.normSAO1.xy, 1))) * 2 - 1; //half slope2 = dot(float3(0,0,1), WorldNormalVector(i, float3(samples.normSAO2.xy, 1))) * 2 - 1; //half slope3 = dot(float3(0,0,1), WorldNormalVector(i, float3(samples.normSAO3.xy, 1))) * 2 - 1; #endif #if _PCHEIGHTGRADIENT samples.albedo0.rgb *= SAMPLE_TEXTURE2D(_PCHeightGradients, shared_linear_clamp_sampler, float2(h, c.uv0.z * _PerTexProps_TexelSize.x + offset)) * 2; samples.albedo1.rgb *= SAMPLE_TEXTURE2D(_PCHeightGradients, shared_linear_clamp_sampler, float2(h, c.uv1.z * _PerTexProps_TexelSize.x + offset)) * 2; #if !_MAX2LAYER samples.albedo2.rgb *= SAMPLE_TEXTURE2D(_PCHeightGradients, shared_linear_clamp_sampler, float2(h, c.uv2.z * _PerTexProps_TexelSize.x + offset)) * 2; #endif #if !_MAX3LAYER && !_MAX2LAYER samples.albedo3.rgb *= SAMPLE_TEXTURE2D(_PCHeightGradients, shared_linear_clamp_sampler, float2(h, c.uv3.z * _PerTexProps_TexelSize.x + offset)) * 2; #endif #endif #if _PCSLOPEGRADIENT samples.albedo0.rgb *= SAMPLE_TEXTURE2D(_PCSlopeGradients, shared_linear_clamp_sampler, float2(slope0, c.uv0.z * _PerTexProps_TexelSize.x + offset)) * 2; samples.albedo1.rgb *= SAMPLE_TEXTURE2D(_PCSlopeGradients, shared_linear_clamp_sampler, float2(slope1, c.uv1.z * _PerTexProps_TexelSize.x + offset)) * 2; #if !_MAX2LAYER samples.albedo2.rgb *= SAMPLE_TEXTURE2D(_PCSlopeGradients, shared_linear_clamp_sampler, float2(slope2, c.uv2.z * _PerTexProps_TexelSize.x + offset)) * 2; #endif #if !_MAX3LAYER && !_MAX2LAYER samples.albedo3.rgb *= SAMPLE_TEXTURE2D(_PCSlopeGradients, shared_linear_clamp_sampler, float2(slope3, c.uv3.z * _PerTexProps_TexelSize.x + offset)) * 2; #endif #endif #if _PCHEIGHTHSV || _PCSLOPEHSV samples.albedo0.rgb = PCRGB2HSV(samples.albedo0.rgb); samples.albedo1.rgb = PCRGB2HSV(samples.albedo1.rgb); #if !_MAX2LAYER samples.albedo2.rgb = PCRGB2HSV(samples.albedo2.rgb); #endif #if !_MAX3LAYER && !_MAX2LAYER samples.albedo3.rgb = PCRGB2HSV(samples.albedo3.rgb); #endif #if _PCHEIGHTHSV samples.albedo0.rgb += SAMPLE_TEXTURE2D(_PCHeightHSV, shared_linear_clamp_sampler, float2(h, c.uv0.z * _PerTexProps_TexelSize.x + offset)).xyz - 0.5; samples.albedo1.rgb += SAMPLE_TEXTURE2D(_PCHeightHSV, shared_linear_clamp_sampler, float2(h, c.uv1.z * _PerTexProps_TexelSize.x + offset)).xyz - 0.5; #if !_MAX2LAYER samples.albedo2.rgb += SAMPLE_TEXTURE2D(_PCHeightHSV, shared_linear_clamp_sampler, float2(h, c.uv2.z * _PerTexProps_TexelSize.x + offset)).xyz - 0.5; #endif #if !_MAX3LAYER && !_MAX2LAYER samples.albedo3.rgb += SAMPLE_TEXTURE2D(_PCHeightHSV, shared_linear_clamp_sampler, float2(h, c.uv3.z * _PerTexProps_TexelSize.x + offset)).xyz - 0.5; #endif #endif #if _PCSLOPEHSV samples.albedo0.rgb += SAMPLE_TEXTURE2D(_PCSlopeHSV, shared_linear_clamp_sampler, float2(slope0, c.uv0.z * _PerTexProps_TexelSize.x + offset)).xyz - 0.5; samples.albedo1.rgb += SAMPLE_TEXTURE2D(_PCSlopeHSV, shared_linear_clamp_sampler, float2(slope1, c.uv1.z * _PerTexProps_TexelSize.x + offset)).xyz - 0.5; #if !_MAX2LAYER samples.albedo2.rgb += SAMPLE_TEXTURE2D(_PCSlopeHSV, shared_linear_clamp_sampler, float2(slope2, c.uv2.z * _PerTexProps_TexelSize.x + offset)).xyz - 0.5; #endif #if !_MAX3LAYER && !_MAX2LAYER samples.albedo3.rgb += SAMPLE_TEXTURE2D(_PCSlopeHSV, shared_linear_clamp_sampler, float2(slope3, c.uv3.z * _PerTexProps_TexelSize.x + offset)).xyz - 0.5; #endif #endif samples.albedo0.rgb = PCHSV2RGB(samples.albedo0.rgb); samples.albedo1.rgb = PCHSV2RGB(samples.albedo1.rgb); #if !_MAX2LAYER samples.albedo2.rgb = PCHSV2RGB(samples.albedo2.rgb); #endif #if !_MAX3LAYER && !_MAX2LAYER samples.albedo3.rgb = PCHSV2RGB(samples.albedo3.rgb); #endif #endif }