rokojori_action_library/Runtime/Procedural/HeightMaps/HeightMapBlendMode.cs

59 lines
2.0 KiB
C#

using Godot;
using System;
using Rokojori.Extensions;
namespace Rokojori
{
/** How a HeightMapGeneratorLayer combines with what is already in the map.
All three are <marked>native</marked> BlitMaterial blend modes, so a layer
costs one content blit into a scratch buffer plus one hardware-blended blit
onto the map - no ping-pong buffer and no accumulation read anywhere.
The int values are passed to HeightMapShape.gdshader as shape_blend_mode,
which decides whether the falloff goes into RGB (Add/Subtract, premultiplied
so the hardware just sums it) or into alpha (Replace, so Mix crossfades to
the layer's height across the falloff). Do not renumber without updating the
shader.
*/
public enum HeightMapBlendMode
{
/** Adds the layer's height on top of what is underneath. The default, and
the one that makes a stack of layers read as constructive.
*/
Add = 0,
/** Subtracts it - craters, trenches, cut-outs. */
Subtract = 1,
/** Overwrites with the layer's height, fading back to what is underneath
across the falloff. The layer's height value is an <marked>absolute</marked>
world height here, not a delta - plateaus and flattened build sites.
*/
Replace = 2
}
public static class HeightMapBlendModeX
{
public static BlitMaterial.BlendModeEnum ToBlitBlendMode( this HeightMapBlendMode mode )
{
switch ( mode )
{
case HeightMapBlendMode.Add: return BlitMaterial.BlendModeEnum.Add;
case HeightMapBlendMode.Subtract: return BlitMaterial.BlendModeEnum.Sub;
case HeightMapBlendMode.Replace: return BlitMaterial.BlendModeEnum.Mix;
}
return BlitMaterial.BlendModeEnum.Add;
}
/** True when the layer's height value means "this world height", false when
it means "this much height on top of what is there".
*/
public static bool IsAbsolute( this HeightMapBlendMode mode )
{
return mode == HeightMapBlendMode.Replace;
}
}
}