using Godot; namespace Rokojori { [Tool] [GlobalClass] public partial class GlowFlareVFXLayer:FlareVFXLayer { [Export( PropertyHint.Range, "1, 1000" )] public int numInstances = 1; [ExportGroup("Color")] [Export] public BoxedColorValue colorOverwrite; [Export] public float opacity = 1f; [Export] public CurveTexture opacityCurve = new CurveTexture().WithCurve( new Curve().WithValues( 1f, 1f ).WithLinearTangents() ); [ExportGroup("Size")] [Export] public Vector2 size = Vector2.One; [Export] public float sizeXY = 1f; [Export] public float worldSizeScale = 1f; [Export] public float screenSizeScale = 1f; [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; GlowFlareVFXLayer parent; GlowFlareAddMaterial glowMaterial; int _numInstances = 0; public override FlareVFXLayer Create( FlareVFX flareVFX ) { var clone = Duplicate() as GlowFlareVFXLayer; clone.mesh = flareVFX.GetContainer().CreateChild(); clone._numInstances = numInstances; clone.mesh.Mesh = MeshGeometry.UnitBillboardQuads( numInstances, 0f, 1f ).GenerateMesh(); clone.glowMaterial = new GlowFlareAddMaterial(); 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.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 ); } } }