84 lines
2.8 KiB
HLSL
84 lines
2.8 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 = frac(_Time.y / 20);
|
|
float t = Progression;
|
|
t -= RidgedNoise3D(PositionWS, .3, 1, 2, .5) * .3;
|
|
|
|
|
|
float depth = length(PositionWS - _WorldSpaceCameraPos.xyz);
|
|
//Light mainLight = GetMainLight(0);
|
|
//float3 mainLightDir = normalize(mainLight.direction);
|
|
//float lightGradient = dot(normalize(NormalWS), normalize(mainLightDir));
|
|
//lightGradient = smoothstep(-.5, 1, lightGradient);
|
|
//float ao = GetScreenSpaceAmbientOcclusion(ScreenUV).directAmbientOcclusion;
|
|
|
|
// Arks
|
|
|
|
/*float arkMask = abs(frac(PositionWS.z * .5) * 2 - 1);
|
|
arkMask = pow(smoothstep(.7, 0, arkMask), 2);
|
|
arkMask += smoothstep(2.8, 3.2, abs(PositionWS.x));
|
|
arkMask = saturate(arkMask);*/
|
|
float arkMask = 0;
|
|
|
|
// Sand
|
|
|
|
float sandLayers = 6;
|
|
|
|
float sandDirection = cos(t * sandLayers * 3.14);
|
|
|
|
//float sandDensity = smoothstep(1.5, 0, abs(PositionWS.x));
|
|
//sandDensity = saturate(sandDensity + arkMask);
|
|
|
|
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;
|
|
|
|
// Test
|
|
|
|
//float test = ValueNoise3D(PositionWS, 40);
|
|
//float test = PerlinNoise3D(PositionWS, 40);
|
|
//float test = PerlinNoise3DLOD(PositionWS, 100, 3.5);
|
|
//float test = SimplexNoise3D(PositionWS, 40);
|
|
//float test = WorleyNoise3D(PositionWS, 40, 1);
|
|
//float id;
|
|
//float test = VoronoiNoise3D(PositionWS, 10, 1, .05, id);
|
|
//float test = FBMNoise3D(PositionWS, 10, 2, 2, .5);
|
|
//float test = RidgedNoise3D(PositionWS, 10, 2, 2, .5);
|
|
|
|
// Output
|
|
|
|
Position = PositionWS;
|
|
Position.y += sandMask;
|
|
|
|
Height = sandMask;
|
|
|
|
Alpha = smoothstep(1, .5, abs(smoothstep(-20, 20, PositionWS.x) * 2 - 1));
|
|
//Debug = sandFlow;
|
|
}
|
|
|
|
#endif
|