#ifndef HOUSE_OF_LEAVES_INCLUDED #define HOUSE_OF_LEAVES_INCLUDED #include "Assets/_Content/Shaders/Include/Noises.hlsl" float Hash(float n) { return frac(sin(n * 127.1) * 43758.5453123); } float3 ColorRemapRandom ( float rnd, float3 ColorA, float3 ColorB, float3 ColorC, float3 ColorD, float3 ColorE, float wA, float wB, float wC, float wD ) { if (rnd < wA) return ColorA; if (rnd < wA + wB) return ColorB; if (rnd < wA + wB + wC) return ColorC; if (rnd < wA + wB + wC + wD) return ColorD; return ColorE; } float3 ColorRemapLinear ( float Gradient, float3 ColorA, float3 ColorB, float3 ColorC, float3 ColorD, float3 ColorE ) { float3 col = ColorA; col = lerp(col, ColorB, smoothstep(0.0, .25, Gradient)); col = lerp(col, ColorC, smoothstep(.25, .50, Gradient)); col = lerp(col, ColorD, smoothstep(.50, .75, Gradient)); col = lerp(col, ColorE, smoothstep(.75, 1.0, Gradient)); return col; } void Sand_float ( float4 ColorA, float4 ColorB, float4 ColorC, float4 ColorD, float4 ColorE, float Progression, float3 PositionWS, float3 NormalWS, out float3 Color, out float3 Position, out float Height, out float Alpha ) { float t = Progression; t -= RidgedNoise3D(PositionWS, .3, 1, 2, .5) * .3; float depth = length(PositionWS - _WorldSpaceCameraPos.xyz); float arkMask = 0; // Sand float sandLayers = 6; float sandDirection = cos(t * sandLayers * 3.14); float sandPatern = RidgedNoise3D(PositionWS + float3(sandDirection, 0, 0), .6, 1, 2, .5) * .8; sandPatern += 1 - RidgedNoise3D(PositionWS + float3(0, 0, t * sandLayers * 2), .8, 2, 2, .5) * .2; float sandDensity = sqrt(smoothstep(0, 2, abs(PositionWS.x) + sandPatern)); float sandGradientSign = (floor(t * sandLayers) % 2 == 0) ? 1 : -1; float sandGradient = smoothstep(2 * -sandGradientSign, 2 * sandGradientSign, PositionWS.x); float sandPhase = frac(t * sandLayers); float sandFlow = smoothstep(sandPhase * 2, sandPhase * 2 - 1, sandGradient); sandFlow = (sandFlow + floor(t * sandLayers)) / sandLayers; float sandMask = sandFlow * 1.5 - t * .8 + (sandPatern * 2 - 1) * sandDensity * t * .3; sandMask *= sandDensity * .7 + .3; // Output Color = ColorRemapLinear(saturate(pow(smoothstep(5, 30, depth * sandPatern), .5)), ColorA, ColorB, ColorC, ColorD, ColorE); Position = PositionWS; Position.y += sandMask; Height = sandMask; Alpha = smoothstep(1, .5, abs(smoothstep(-20, 20, PositionWS.x) * 2 - 1)); } void HouseOfLeaves_float ( float4 ColorA, float4 ColorB, float4 ColorC, float4 ColorD, float4 ColorE, float3 PositionWS, float3 NormalWS, out float3 Output ) { float n0 = FBMNoise3D(PositionWS, 01, 2, 2, .5); float n1 = FBMNoise3D(PositionWS * float3(1, 1, .5) + n0 + float3(floor(_Time.y * 1.6), 0, 0), 60, 2, 2, .5); float n2 = PerlinNoise3D(PositionWS * float3(1, 1, 30) + float3(floor(_Time.y * 4), 0, 0), 1); float n3 = RidgedNoise3D(PositionWS * float3(n0, n1, n2 + 4) + float3(floor(_Time.y * 1), 0, 0), .3, 2, 2, 1); float depth = distance(_WorldSpaceCameraPos.xyz, PositionWS); float gradient = smoothstep(-30, 100, PositionWS.z); gradient += ((n1 * 2 - 1) * step(n0, .5)) * .001; gradient += n2 * .006; gradient -= NormalWS.y * .001; float t = 0; float bands = 300 + t; float bandPos = gradient * bands; float bandIndex = floor(bandPos); float bandFrac = frac(bandPos); float wA = pow(1.0 - gradient, 4.0); float wB = pow(1.0 - abs(gradient - .25) * 2.0, 2.0); float wC = pow(1.0 - abs(gradient - .50) * 2.0, 2.0); float wD = pow(1.0 - abs(gradient - .75) * 2.0, 2.0); float wE = .1 + pow(gradient, 4.0); float total = wA + wB + wC + wD + wE; wA /= total; wB /= total; wC /= total; wD /= total; wE /= total; float rnd0 = Hash(bandIndex); float3 col0 = ColorRemapRandom( rnd0, ColorA.rgb, ColorB.rgb, ColorC.rgb, ColorD.rgb, ColorE.rgb, wA, wB, wC, wD ); float depthAtten = smoothstep(50, 100, depth); float3 col = lerp(col0, _ColorB, n0 - n1); col = lerp(col, _ColorA, smoothstep(.8 - gradient, .7 - gradient, n3) * .8); col = lerp(col, _ColorE, pow(depthAtten, 2)); col = lerp(col, _ColorA, pow(smoothstep(.2 + n2 * 4, 0, PositionWS.y), 2) * (1 - depthAtten) * .95); col = lerp(col, _ColorA * .1, smoothstep(0, -30, PositionWS.z)); float blendWidth = .05; float blend = smoothstep( 1.0 - blendWidth, 1.0, bandFrac ); Output = col; } #endif