Files
Ipseity-Demo/Assets/_Content/Models/Environments/HouseOfLeaves/Shaders/Sand.hlsl
T

55 lines
1.6 KiB
HLSL

#ifndef SAND_INCLUDED
#define SAND_INCLUDED
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Assets/_Content/Shaders/Include/Noises.hlsl"
void Sand_float
(
float Progression,
float3 PositionWS,
float3 NormalWS,
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
Position = PositionWS;
Position.y += sandMask;
Height = sandMask;
Alpha = smoothstep(1, .5, abs(smoothstep(-20, 20, PositionWS.x) * 2 - 1));
}
#endif