207 lines
5.6 KiB
C#
207 lines
5.6 KiB
C#
|
|
using Godot;
|
||
|
|
|
||
|
|
|
||
|
|
namespace Rokojori
|
||
|
|
{
|
||
|
|
[Tool]
|
||
|
|
[GlobalClass]
|
||
|
|
public partial class ShapeFlareVFXLayer:FlareVFXLayer
|
||
|
|
{
|
||
|
|
[Export( PropertyHint.Range, "1, 1000" )]
|
||
|
|
public int numInstances = 1;
|
||
|
|
|
||
|
|
[ExportGroup("Color")]
|
||
|
|
[Export]
|
||
|
|
public BoxedColorValue colorOverwrite;
|
||
|
|
|
||
|
|
[Export( PropertyHint.Range, "0.2,20")]
|
||
|
|
public float colorDistortion = 2f;
|
||
|
|
|
||
|
|
[Export( PropertyHint.Range, "0.2,20")]
|
||
|
|
public float alphaDistortion= 2f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public Vector4 centerHSLA = Vector4.Zero;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public Vector4 outsideHSLA = Vector4.Zero;
|
||
|
|
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float minShapeDistanceColor = 0f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float maxShapeDistanceColor = 0.05f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float shapeDistanceOffsetColor = 0f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float shapeDistanceSpreadColor = 0.05f;
|
||
|
|
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float minHueRandom = 0f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float maxHueRandom = 0f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float hueOffset = 0f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float hueSpread = 0f;
|
||
|
|
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float opacity = 1f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public CurveTexture opacityCurve = new CurveTexture().WithCurve( new Curve().WithValues( 1f, 1f ).WithLinearTangents() );
|
||
|
|
|
||
|
|
public enum ShapeType
|
||
|
|
{
|
||
|
|
Circle,
|
||
|
|
Cross,
|
||
|
|
Triangle,
|
||
|
|
Rectangle,
|
||
|
|
Pentagon,
|
||
|
|
Hexagon,
|
||
|
|
Octogon,
|
||
|
|
Hexagram,
|
||
|
|
Pentagram,
|
||
|
|
Ring,
|
||
|
|
Cutout1,
|
||
|
|
Cutout2,
|
||
|
|
Heart
|
||
|
|
}
|
||
|
|
|
||
|
|
[ExportGroup("Shape", "shape")]
|
||
|
|
[Export]
|
||
|
|
public ShapeType shapeType = ShapeType.Pentagon;
|
||
|
|
|
||
|
|
[Export( PropertyHint.Range, "-180,180" ) ]
|
||
|
|
public float shapeRotation = 0;
|
||
|
|
|
||
|
|
[Export( PropertyHint.Range, "0,1" ) ]
|
||
|
|
public float shapeScale = 0f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float shapeMinDistance = 0;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float shapeMaxDistance = 0.05f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float shapeDistanceOffset = 0f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float shapeDistanceSpread = 0f;
|
||
|
|
|
||
|
|
[ExportGroup("Size")]
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public Vector2 size = Vector2.One;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float sizeXY = 1f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float worldSizeScale = 1f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float screenSizeScale = 1f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float minRandomScale = 1f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float maxRandomScale = 1f;
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public float polarRandomScale = 0f;
|
||
|
|
|
||
|
|
[Export( PropertyHint.Range, "0,1" )]
|
||
|
|
public float worldSize_vs_screenSize = 1f;
|
||
|
|
|
||
|
|
[ExportGroup("Screen Offset")]
|
||
|
|
[Export]
|
||
|
|
public Vector2 screenOffset = Vector2.Zero;
|
||
|
|
[Export]
|
||
|
|
public Vector2 screenOffsetSpreadPerLayer = Vector2.Zero;
|
||
|
|
|
||
|
|
MeshInstance3D mesh;
|
||
|
|
ShapeFlareVFXLayer parent;
|
||
|
|
ShapeFlareAddMaterial glowMaterial;
|
||
|
|
int _numInstances = 0;
|
||
|
|
|
||
|
|
public override FlareVFXLayer Create( FlareVFX flareVFX )
|
||
|
|
{
|
||
|
|
var clone = Duplicate() as ShapeFlareVFXLayer;
|
||
|
|
|
||
|
|
clone.mesh = flareVFX.GetContainer().CreateChild<MeshInstance3D>();
|
||
|
|
clone._numInstances = numInstances;
|
||
|
|
clone.mesh.Mesh = MeshGeometry.UnitBillboardQuads( numInstances, 0f, 1f ).GenerateMesh();
|
||
|
|
|
||
|
|
clone.glowMaterial = new ShapeFlareAddMaterial();
|
||
|
|
clone.mesh.SetSurfaceOverrideMaterial( 0, clone.glowMaterial );
|
||
|
|
|
||
|
|
clone.parent = this;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
return clone;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void Update( FlareVFX flareVFX )
|
||
|
|
{
|
||
|
|
if ( _numInstances != parent.numInstances )
|
||
|
|
{
|
||
|
|
_numInstances = parent.numInstances;
|
||
|
|
mesh.Mesh = MeshGeometry.UnitBillboardQuads( _numInstances, 0f, 1f ).GenerateMesh();
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
glowMaterial.color.Set( parent.colorOverwrite !=null ? parent.colorOverwrite.GetColorValue() : flareVFX.preset.mainColor );
|
||
|
|
|
||
|
|
glowMaterial.colorDistortion.Set( parent.colorDistortion );
|
||
|
|
glowMaterial.alphaDistortion.Set( parent.alphaDistortion );
|
||
|
|
|
||
|
|
glowMaterial.centerHsl.Set( parent.centerHSLA );
|
||
|
|
glowMaterial.outsideHsl.Set( parent.outsideHSLA );
|
||
|
|
|
||
|
|
glowMaterial.minHueRandom.Set( parent.minHueRandom + parent.hueOffset - parent.hueSpread );
|
||
|
|
glowMaterial.maxHueRandom.Set( parent.maxHueRandom + parent.hueOffset + parent.hueSpread );
|
||
|
|
|
||
|
|
glowMaterial.opacity.Set( parent.opacity );
|
||
|
|
glowMaterial.opacityCurve.Set( parent.opacityCurve );
|
||
|
|
|
||
|
|
var size = parent.size * parent.sizeXY;
|
||
|
|
glowMaterial.sizeX.Set( size.X );
|
||
|
|
glowMaterial.sizeY.Set( size.Y );
|
||
|
|
glowMaterial.worldSizeScale.Set( parent.worldSizeScale );
|
||
|
|
glowMaterial.screenSizeScale.Set( parent.screenSizeScale );
|
||
|
|
glowMaterial.worldSizeVsScreenSize.Set( parent.worldSize_vs_screenSize );
|
||
|
|
|
||
|
|
glowMaterial.screenOffsetScale.Set( parent.screenOffset );
|
||
|
|
glowMaterial.screenOffsetLayerSpread.Set( parent.screenOffsetSpreadPerLayer );
|
||
|
|
|
||
|
|
glowMaterial.shapeType.Set( (int) parent.shapeType );
|
||
|
|
|
||
|
|
glowMaterial.shapeType.Set( (int) parent.shapeType );
|
||
|
|
glowMaterial.shapeRotation.Set( parent.shapeRotation );
|
||
|
|
glowMaterial.shapeScale.Set( parent.shapeScale );
|
||
|
|
|
||
|
|
glowMaterial.minShapeDistance.Set( parent.shapeMinDistance + parent.shapeDistanceOffset - parent.shapeDistanceSpread );
|
||
|
|
glowMaterial.maxShapeDistance.Set( parent.shapeMaxDistance + parent.shapeDistanceOffset + parent.shapeDistanceSpread );
|
||
|
|
|
||
|
|
glowMaterial.minShapeDistanceColor.Set( parent.minShapeDistanceColor + parent.shapeDistanceOffsetColor - parent.shapeDistanceSpreadColor );
|
||
|
|
glowMaterial.maxShapeDistanceColor.Set( parent.maxShapeDistanceColor + parent.shapeDistanceOffsetColor + parent.shapeDistanceSpreadColor );
|
||
|
|
|
||
|
|
|
||
|
|
glowMaterial.randomScaleMin.Set( parent.minRandomScale - parent.polarRandomScale );
|
||
|
|
glowMaterial.randomScaleMax.Set( parent.maxRandomScale + parent.polarRandomScale );
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|