rj-action-library/Runtime/Shading/Generators/Spatial/Geometry/Wind/GeometryWind.cs

101 lines
2.3 KiB
C#
Raw Normal View History

using Godot;
using System.Reflection;
using System.Collections.Generic;
2025-09-17 08:25:03 +00:00
using System;
namespace Rokojori
{
[Tool]
[GlobalClass]
2025-09-17 08:25:03 +00:00
public partial class GeometryWind:GeometryModifier
{
[Export]
public bool sampleAngleFromNoise = true;
[Export]
public bool heightCompensation = true;
2025-09-17 08:25:03 +00:00
public override List<ShaderCode> GetGeometryCode( ShaderGenerationContext context, int offsetIndex )
{
2025-09-17 08:25:03 +00:00
if ( offsetIndex != 0 )
{
throw new Exception( "Unique component, can't be used multiple times");
}
if ( ShaderPhase.Includes == context.phase )
{
2025-09-17 08:25:03 +00:00
return IncludeFromLibrary( "Wind" );
}
if ( ShaderPhase.Variables == context.phase )
{
return AsUniformGroup( "Wind",
@"
2025-09-17 08:25:03 +00:00
uniform float windStrength = 0;
uniform vec2 windSpeed = vec2(1,1);
2025-09-17 08:25:03 +00:00
uniform float windScale = 0.1;
uniform sampler2D windNoise;
uniform vec2 windNoiseAngleOffset;
2025-09-17 08:25:03 +00:00
uniform vec2 windNoiseStrengthOffset;
uniform float windStart = 0;
uniform float windEnd = 1;
uniform float windWeightCurve:hint_range(0,1) = 0.5f;
uniform float windHeightCompensation :hint_range(0,1) = 0.5f;
2025-09-17 08:25:03 +00:00
uniform float windNormalBending :hint_range(0,1) = 0.1f;
uniform float windOcclusionAmount = 0;
varying float vertexWindAO;
"
);
}
if ( ShaderPhase.Vertex == context.phase )
{
return ToInnerBlock( "Wind",
2025-09-17 08:25:03 +00:00
@"
float cachedVertexWindAO = 0.0;
2025-09-17 08:25:03 +00:00
applyWind(
TIME,
MODEL_MATRIX,
VERTEX,
NORMAL,
cachedVertexWindAO,
windOcclusionAmount,
windStrength,
windSpeed,
windScale,
windNoise,
windNoiseAngleOffset,
windNoiseStrengthOffset,
windStart,
windEnd,
windWeightCurve,
2025-09-17 08:25:03 +00:00
windHeightCompensation,
windNormalBending
);
2025-09-17 08:25:03 +00:00
vertexWindAO = cachedVertexWindAO;
"
2025-09-17 08:25:03 +00:00
) ;
}
if ( ShaderPhase.Fragment == context.phase )
{
return ToCode( "AO *= vertexWindAO;".Indent( " " ).LineBreaks() );
}
return null;
}
}
}