diff --git a/External/Imposter/materials/dilatate.gdshader b/External/Imposter/materials/dilatate.gdshader index ab74aed..42a2342 100644 --- a/External/Imposter/materials/dilatate.gdshader +++ b/External/Imposter/materials/dilatate.gdshader @@ -6,7 +6,7 @@ uniform int u_distance = 16; uniform bool u_alpha_overwrite = true; -vec4 dilate(sampler2D a_tex, sampler2D tex, vec2 coords, vec2 texel_size, int dist, float alpha_cutoff) +vec4 dilate( sampler2D a_tex, sampler2D tex, vec2 coords, vec2 texel_size, int dist, float alpha_cutoff ) { vec2 offsets[8] = { @@ -40,7 +40,7 @@ vec4 dilate(sampler2D a_tex, sampler2D tex, vec2 coords, vec2 texel_size, int di return sample; } -void fragment() { - COLOR = dilate(u_alpha_tex, TEXTURE, UV, TEXTURE_PIXEL_SIZE, u_distance, 0.95); - //COLOR.a = 1.0; +void fragment() +{ + COLOR = dilate(u_alpha_tex, TEXTURE, UV, TEXTURE_PIXEL_SIZE, u_distance, 0.95); } diff --git a/RokojoriPlugin.cs b/RokojoriPlugin.cs index 3d4f313..e2ffb80 100644 --- a/RokojoriPlugin.cs +++ b/RokojoriPlugin.cs @@ -10,6 +10,19 @@ namespace Rokojori { GizmoDrawerPlugin gizmoDrawerPlugin = new GizmoDrawerPlugin(); + static readonly string RokojoriRootAutoLoad = "RokojoriRootAutoLoad"; + static readonly string RokojoriRootAutoLoadPath = "res://addons/rokojori_action_library/Runtime/Godot/Root.cs"; + + public override void _EnablePlugin() + { + AddAutoloadSingleton( RokojoriRootAutoLoad, RokojoriRootAutoLoadPath ); + } + + public override void _DisablePlugin() + { + RemoveAutoloadSingleton( RokojoriRootAutoLoad ); + } + public override void _EnterTree() { AddNode3DGizmoPlugin( gizmoDrawerPlugin ); diff --git a/Runtime/Actions/ActionList.cs b/Runtime/Actions/ActionList.cs index 2d439a6..e21a0e2 100644 --- a/Runtime/Actions/ActionList.cs +++ b/Runtime/Actions/ActionList.cs @@ -19,6 +19,7 @@ namespace Rokojori */ + [Tool] [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/ActionList.svg") ] public partial class ActionList : Action { diff --git a/Runtime/Actions/Node3D/OnCollision.cs b/Runtime/Actions/Node3D/OnCollision.cs new file mode 100644 index 0000000..0460023 --- /dev/null +++ b/Runtime/Actions/Node3D/OnCollision.cs @@ -0,0 +1,100 @@ + +using System.Collections.Generic; +using Godot; +using Rokojori; + +namespace Rokojori +{ + [Tool] + [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/OnEvent.svg") ] + public partial class OnCollision:Node + { + [Export] + public Area3D area; + + [Export] + public Selector selector; + + [Export] + public Action onEntered; + + [Export] + public Action onInside; + + [Export] + public Action onExit; + + + + Dictionary _inside = new Dictionary(); + + + public override void _Ready() + { + if ( area == null ) + { + return; + } + + area.AreaEntered += TriggerOnEnter; + area.BodyEntered += TriggerOnEnter; + + area.AreaExited += TriggerOnExited; + area.BodyExited += TriggerOnExited; + } + + void TriggerOnEnter( Node n ) + { + if ( ! Selector.IsSelecting( selector, n ) ) + { + return; + } + + Action.Trigger( onEntered ); + + if ( onInside == null ) + { + return; + } + + var tm = Unique.Get(); + + if ( tm == null ) + { + return; + } + + var callback = ()=>{ Action.Trigger( onInside ); }; + _inside[ n ] = callback; + tm.AddProcessCallback( callback ); + + } + + void TriggerOnExited( Node n ) + { + if ( ! Selector.IsSelecting( selector, n ) ) + { + return; + } + + Action.Trigger( onExit ); + + if ( ! _inside.ContainsKey( n ) ) + { + return; + } + + var tm = Unique.Get(); + + if ( tm == null ) + { + return; + } + + var callback = _inside[ n ]; + tm.RemoveProcessCallback( callback ); + + _inside.Remove( n ); + } + } +} \ No newline at end of file diff --git a/Runtime/Actions/Node3D/OnCollision.cs.uid b/Runtime/Actions/Node3D/OnCollision.cs.uid new file mode 100644 index 0000000..82e5321 --- /dev/null +++ b/Runtime/Actions/Node3D/OnCollision.cs.uid @@ -0,0 +1 @@ +uid://c8gcunaffcaww diff --git a/Runtime/Actions/Node3D/PlayParticles.cs b/Runtime/Actions/Node3D/PlayParticles.cs new file mode 100644 index 0000000..67c93af --- /dev/null +++ b/Runtime/Actions/Node3D/PlayParticles.cs @@ -0,0 +1,17 @@ + +using Godot; + +namespace Rokojori +{ + [GlobalClass] + public partial class PlayParticles:Action + { + [Export] + public GpuParticles3D particles3D; + + protected override void _OnTrigger() + { + particles3D.Restart(); + } + } +} \ No newline at end of file diff --git a/Runtime/Actions/Node3D/PlayParticles.cs.uid b/Runtime/Actions/Node3D/PlayParticles.cs.uid new file mode 100644 index 0000000..22a9db9 --- /dev/null +++ b/Runtime/Actions/Node3D/PlayParticles.cs.uid @@ -0,0 +1 @@ +uid://dnstanbmrqthf diff --git a/Runtime/Actions/Node3D/PlaySound.cs b/Runtime/Actions/Node3D/PlaySound.cs new file mode 100644 index 0000000..212fee9 --- /dev/null +++ b/Runtime/Actions/Node3D/PlaySound.cs @@ -0,0 +1,17 @@ + +using Godot; + +namespace Rokojori +{ + [GlobalClass] + public partial class PlaySound:Action + { + [Export] + public AudioStreamPlayer player; + + protected override void _OnTrigger() + { + player.Play(); + } + } +} \ No newline at end of file diff --git a/Runtime/Actions/Node3D/PlaySound.cs.uid b/Runtime/Actions/Node3D/PlaySound.cs.uid new file mode 100644 index 0000000..36b7804 --- /dev/null +++ b/Runtime/Actions/Node3D/PlaySound.cs.uid @@ -0,0 +1 @@ +uid://ddgf2mfdmqywc diff --git a/Runtime/Godot/Nodes.cs b/Runtime/Godot/Nodes.cs index 60096bb..bde3bf2 100644 --- a/Runtime/Godot/Nodes.cs +++ b/Runtime/Godot/Nodes.cs @@ -226,6 +226,34 @@ namespace Rokojori return CreateChildIn( parent, name ); } + public static T CreateChildLocal3D( this Node parent, Vector3 position, Quaternion? rotation, string name = null ) where T:Node3D,new() + { + var c = CreateChildIn( parent, name ); + + c.Position = position; + + if ( rotation != null ) + { + Math3D.SetLocalQuaternion( c, (Quaternion)rotation ); + } + + return c; + } + + public static T CreateChildGlobal3D( this Node parent, Vector3 position, Quaternion? rotation, string name = null ) where T:Node3D,new() + { + var c = CreateChildIn( parent, name ); + + c.GlobalPosition = position; + + if ( rotation != null ) + { + Math3D.SetGlobalQuaternion( c, (Quaternion)rotation ); + } + + return c; + } + public static Node CreateChildWithType( this Node parent, Type type, string name = null ) { return CreateChildInWithType( parent, type, name ); diff --git a/Runtime/Math/Math3D.cs b/Runtime/Math/Math3D.cs index 3ffa643..2d445b8 100644 --- a/Runtime/Math/Math3D.cs +++ b/Runtime/Math/Math3D.cs @@ -242,16 +242,26 @@ namespace Rokojori return quaternion; } - public static Vector3 MinPosition( Node3D a, Node3D b ) + public static Vector3 MinGlobalPosition( Node3D a, Node3D b ) { return a.GlobalPosition.Min( b.GlobalPosition ); } - public static Vector3 MaxPosition( Node3D a, Node3D b ) + public static Vector3 MaxGlobalPosition( Node3D a, Node3D b ) { return a.GlobalPosition.Max( b.GlobalPosition ); } + public static Vector3 MinLocalPosition( Node3D a, Node3D b ) + { + return a.Position.Min( b.Position ); + } + + public static Vector3 MaxLocalPosition( Node3D a, Node3D b ) + { + return a.Position.Max( b.Position ); + } + public static Vector3 SnapRounded( Vector3 v, Vector3 snapping ) { v.X = MathX.SnapRounded( v.X, snapping.X ); @@ -443,6 +453,13 @@ namespace Rokojori node.Scale = localScale; } + public static void SetLocalQuaternion( this Node3D node, Quaternion quaternion ) + { + var localScale = node.Scale; + node.Basis = new Basis( quaternion ); + node.Scale = localScale; + } + public static void SetGlobalRotationTo( Node3D node, Quaternion quaternion ) { var forward = quaternion * Vector3.Forward; diff --git a/Runtime/Procedural/Assets/Grass/GrassPatch.cs b/Runtime/Procedural/Assets/Grass/GrassPatch.cs index ae25d95..8ab4424 100644 --- a/Runtime/Procedural/Assets/Grass/GrassPatch.cs +++ b/Runtime/Procedural/Assets/Grass/GrassPatch.cs @@ -24,6 +24,26 @@ namespace Rokojori [Export] public bool updateAlways; + [ExportGroup( "Patch")] + [Export] + public float patchSize = 2; + + [Export] + public float patchSizeX = 0; + + [Export] + public float patchSizeZ = 0; + + [Export] + public Vector2 patchOffsetPosition = new Vector2( 0.5f, 0.5f ); + + [Export] + public bool centerPatch = false; + + [Export] + public float centerPatchComputationHeightTreshold = 0.1f; + + [ExportGroup( "Blades")] [Export( PropertyHint.Range, "0,100")] @@ -38,27 +58,10 @@ namespace Rokojori [Export] public int X_numBlades; - [ExportGroup( "Patch")] - [Export] - public float patchSize = 2; - - [Export] - public float patchSizeX = 0; - - [Export] - public float patchSizeZ = 0; - - [Export] - public Vector2 patchOffsetPosition = new Vector2( 0.5f, 0.5f ); - - [Export] - public bool centerPatch = false; - - [Export] - public float centerPatchComputationHeightTreshold = 0.1f; - [ExportGroup( "Blade Triangles")] + + [ExportGroup( "Triangles")] [Export( PropertyHint.Range, "1,256")] public int bladeSegments = 3; @@ -75,7 +78,7 @@ namespace Rokojori [Export] public Curve bladeSegmentMapping = MathX.Curve( 0, 1 ); - [ExportGroup( "Blade Segmentation")] + [ExportGroup( "Segmentation")] [Export] public int uvSegmentColumns = 1; @@ -95,7 +98,7 @@ namespace Rokojori public float uvSegmentMaxRange = 0.3f; - [ExportGroup( "Blade Shape")] + [ExportGroup( "Shape")] [Export] public Curve bladeHeight = MathX.Curve( 0.4f ); @@ -109,19 +112,14 @@ namespace Rokojori [Export] public Curve bladeWidth2 = null; + [ExportGroup( "Curve")] + [Export] public Curve bladeBending = MathX.Curve( 0f ); [Export] public Curve bladeBending2 = null; - [Export] - public Curve bladeArching = MathX.Curve( 0f ); - - [Export] - public Curve bladeArching2 = null; - - [Export] public Curve bladeTwisting = null; @@ -135,7 +133,7 @@ namespace Rokojori public Curve rolling2 = null; - [ExportGroup( "Blade Offset")] + [ExportGroup( "Offset")] [Export] public Curve positionJitter = MathX.Curve( 0.05f ); @@ -148,7 +146,7 @@ namespace Rokojori - [ExportGroup( "Blade Scale")] + [ExportGroup( "Scale")] [Export] public Curve bladeScale = MathX.Curve( 1f ); @@ -178,7 +176,7 @@ namespace Rokojori public Curve scaleZForY = null; - [ExportGroup( "Blade Rotation")] + [ExportGroup( "Rotation")] [Export] public Curve yawRotation = MathX.Curve( 0f, 1f ); @@ -186,8 +184,24 @@ namespace Rokojori [Export] public Curve randomRotation = MathX.Curve( 0f, 20f ); + [ExportGroup( "Noise")] + [Export] + public Curve vertexTurbulenceAmount = MathX.Curve( 0f, 0f ); - [ExportGroup( "Blade Normals")] + [Export] + public Curve vertexTurbulenceScale = MathX.Curve( 1f, 1f ); + + [Export] + public Curve vertexTurbulenceScaleX = MathX.Curve( 1f, 1f ); + + [Export] + public Curve vertexTurbulenceScaleY = MathX.Curve( 1f, 1f ); + + [Export] + public Curve vertexTurbulenceScaleZ = MathX.Curve( 1f, 1f ); + + + [ExportGroup( "Normals")] [Export] public Curve normalBlending = MathX.Curve( 0.5f ); @@ -199,7 +213,7 @@ namespace Rokojori - [ExportGroup( "Blade Filter")] + [ExportGroup( "Filter")] [Export (PropertyHint.Range, "0,1")] public float filterTreshold = 1; @@ -412,6 +426,29 @@ namespace Rokojori mg.CenterMesh( true, false, true, box ); } + if ( vertexTurbulenceAmount != null ) + { + var turbulenceAmount = random.Sample( vertexTurbulenceAmount ); + var turbulenceScale = Vector3.One * ( vertexTurbulenceScale == null ? 1 : random.Sample( vertexTurbulenceScale ) ); + + if ( vertexTurbulenceScaleX != null ) + { + turbulenceScale.X *= random.Sample( vertexTurbulenceScaleX ); + } + + if ( vertexTurbulenceScaleY != null ) + { + turbulenceScale.Y *= random.Sample( vertexTurbulenceScaleY ); + } + + if ( vertexTurbulenceScaleZ != null ) + { + turbulenceScale.Z *= random.Sample( vertexTurbulenceScaleX ); + } + + mg.Turbulence( turbulenceAmount, turbulenceScale, Vector3.Zero ); + } + if ( xRemapper != null ) { mg.RemapX( xRemapper ); @@ -441,6 +478,8 @@ namespace Rokojori { mg.ScaleZForY( scaleZForY ); } + + X_numTriangles = mg.indices.Count / 3; diff --git a/Runtime/Procedural/Baking/Baker.cs b/Runtime/Procedural/Baking/Baker.cs index 6f42829..fb2fb1f 100644 --- a/Runtime/Procedural/Baking/Baker.cs +++ b/Runtime/Procedural/Baking/Baker.cs @@ -111,6 +111,22 @@ namespace Rokojori [Export] public float distance = 1; + public static Baker Create( Node parent, Node3D target, Vector2I size, string name ) + { + var bakingView = parent.CreateChild( "Viewport " + name ); + bakingView.TransparentBg = true; + bakingView.Size = size; + + var bakingCamera = bakingView.CreateChild( "Camera View " + name ); + var baker = bakingView.CreateChild( "Baker " + name ); + + baker.camera = bakingCamera; + baker.target = target; + baker.viewport = bakingView; + + return baker; + } + public override void _Process( double delta ) { if ( ! ( update || updateAlways ) ) diff --git a/Runtime/Procedural/Baking/MultiBaker.cs b/Runtime/Procedural/Baking/MultiBaker.cs index 09eb51a..cd5eb91 100644 --- a/Runtime/Procedural/Baking/MultiBaker.cs +++ b/Runtime/Procedural/Baking/MultiBaker.cs @@ -180,8 +180,8 @@ namespace Rokojori [Export] public WorldEnvironment X_worldEnvironment; - [Export] - public DilateTexture X_dilateTexture; + // [Export] + // public DilateTexture X_dilateTexture; [Export] public MeshInstance3D X_outputMesh; @@ -211,22 +211,23 @@ namespace Rokojori public Texture2D X_bakedTextureDepth; - - bool _initialized = false; bool _baking = false; - - - SerializedGodotObject _cached; - public override void _Ready() { - Initialize(); + } - + + public bool preventProcessing = true; + public override void _Process( double delta ) - { + { + if ( preventProcessing ) + { + return; + } + X_texturePreview.Visible = showOutputTexture; if ( _baking ) @@ -234,20 +235,14 @@ namespace Rokojori return; } - if ( initialize || ! _initialized ) + if ( initialize ) { initialize = false; Initialize(); } - var current = SerializedGodotObject.Create( this ); - - var changed = _cached != null && ! _cached.Equals( current ); - - _cached = current; - - if ( bake || changed && preview_UpdateAlways ) + if ( bake || preview_UpdateAlways ) { bake = false; Bake(); @@ -338,19 +333,19 @@ namespace Rokojori this.LogInfo( "Texture created:", bakingMaterialModes[ i ] ); - if ( preview_DilateTextures ) - { - this.LogInfo( "Dilating:", bakingMaterialModes[ i ] ); - texture = await CreateDilatedTexture(); + // if ( preview_DilateTextures ) + // { + // this.LogInfo( "Dilating:", bakingMaterialModes[ i ] ); + // texture = await CreateDilatedTexture(); - this.LogInfo( "Dilating done:", bakingMaterialModes[ i ] ); - } - else - { + // this.LogInfo( "Dilating done:", bakingMaterialModes[ i ] ); + // } + // else + // { texture = Textures.Copy( texture ); await this.RequestNextFrame(); await this.RequestNextFrame(); - } + // } this.LogInfo( "Assigning Texture", bakingMaterialModes[ i ] ); @@ -379,37 +374,37 @@ namespace Rokojori } - public async Task CreateDilatedTexture() - { - var viewports = GetAllViewports(); - var textures = Lists.Map( viewports, v => v.GetTexture() as Texture2D ); - var dilatedTextures = new List(); + // public async Task CreateDilatedTexture() + // { + // var viewports = GetAllViewports(); + // var textures = Lists.Map( viewports, v => v.GetTexture() as Texture2D ); + // var dilatedTextures = new List(); - var index = 0; + // var index = 0; - foreach ( var t in textures ) - { - index ++; + // foreach ( var t in textures ) + // { + // index ++; - var dilatedTexture = await X_dilateTexture.Create( t ); - dilatedTextures.Add( dilatedTexture ); - } + // var dilatedTexture = await X_dilateTexture.Create( t ); + // dilatedTextures.Add( dilatedTexture ); + // } - X_textureMerger.sourceTextures = dilatedTextures.ToArray(); - X_textureMerger.sourceMode = TextureMerger.SourceMode.Textures; + // X_textureMerger.sourceTextures = dilatedTextures.ToArray(); + // X_textureMerger.sourceMode = TextureMerger.SourceMode.Textures; - X_textureMerger.Initialize(); + // X_textureMerger.Initialize(); - await this.RequestNextFrame(); + // await this.RequestNextFrame(); - X_textureMerger.CreateLayout(); + // X_textureMerger.CreateLayout(); - await this.RequestNextFrame(); + // await this.RequestNextFrame(); - var finalTexture = await X_dilateTexture.Create( X_textureMerger.X_textureMergerViewport.GetTexture() ); + // var finalTexture = await X_dilateTexture.Create( X_textureMerger.X_textureMergerViewport.GetTexture() ); - return finalTexture; - } + // return finalTexture; + // } public List GetAllViewports() { @@ -474,7 +469,7 @@ namespace Rokojori X_views = X_bakingViewport.CreateChild( "Views" ); - X_dilateTexture = this.CreateChild( "Dilate Texture" ); + // X_dilateTexture = this.CreateChild( "Dilate Texture" ); X_textureMerger = this.CreateChild( "Texture Merger" ); X_textureMerger.multiBaker = this; diff --git a/Runtime/Procedural/Mesh/MeshGeometry.cs b/Runtime/Procedural/Mesh/MeshGeometry.cs index 36e7cf5..04c2e5f 100644 --- a/Runtime/Procedural/Mesh/MeshGeometry.cs +++ b/Runtime/Procedural/Mesh/MeshGeometry.cs @@ -791,6 +791,16 @@ namespace Rokojori } } + public void Turbulence( float amount, Vector3 noiseScale, Vector3 noiseOffset ) + { + for ( int i = 0; i < vertices.Count; i++ ) + { + var v = vertices[ i ]; + var offset = Noise.PerlinPolar3( v * noiseScale + noiseOffset ) * amount; + vertices[ i ] = v + offset; + } + } + public void RemapX( Curve curve ) { for ( int i = 0; i < vertices.Count; i++ ) @@ -821,6 +831,8 @@ namespace Rokojori } } + + public void ScaleXForY( Curve curve ) { for ( int i = 0; i < vertices.Count; i++ ) diff --git a/Runtime/Procedural/Scatter/Generators/GenerateInBox.cs b/Runtime/Procedural/Scatter/Generators/GenerateInBox.cs index 04ed5d8..6fe0536 100644 --- a/Runtime/Procedural/Scatter/Generators/GenerateInBox.cs +++ b/Runtime/Procedural/Scatter/Generators/GenerateInBox.cs @@ -28,8 +28,8 @@ namespace Rokojori { CreateWeights(); - var minPosition = Math3D.MinPosition( cornerA, cornerB ); - var maxPosition = Math3D.MaxPosition( cornerA, cornerB ); + var minPosition = Math3D.MinLocalPosition( cornerA, cornerB ); + var maxPosition = Math3D.MaxLocalPosition( cornerA, cornerB ); if ( snapToWorldGrid ) { @@ -46,7 +46,7 @@ namespace Rokojori if ( xzOnly ) { - var y = ( cornerA.GlobalPosition.Y + cornerB.GlobalPosition.Y ) / 2f; + var y = ( cornerA.Position.Y + cornerB.Position.Y ) / 2f; for ( int x = 0; x < pointsX; x++ ) { @@ -89,6 +89,8 @@ namespace Rokojori var p = new ScatterPoint( this, id++ ); p.position = new Vector3( x, y, z ); + p.useGlobalPosition = false; + p.visible = ! setDiscarded; p.seed = Noise.CreateSeed( p.position ); diff --git a/Runtime/Procedural/Scatter/Scatterer.cs b/Runtime/Procedural/Scatter/Scatterer.cs index 8a9e60a..6e5f794 100644 --- a/Runtime/Procedural/Scatter/Scatterer.cs +++ b/Runtime/Procedural/Scatter/Scatterer.cs @@ -103,6 +103,15 @@ namespace Rokojori Dictionary _scattererIDs = new Dictionary(); + public enum PositionMode + { + Local_As_Global, + Local_Plus_ScattererGlobal + } + + [Export] + public PositionMode positionMode; + public void ClearCache() { _instantiatedPoints.Clear(); diff --git a/Runtime/Procedural/Scatter/Transform/RandomizeTransform.cs b/Runtime/Procedural/Scatter/Transform/RandomizeTransform.cs index a023bc2..c6727c3 100644 --- a/Runtime/Procedural/Scatter/Transform/RandomizeTransform.cs +++ b/Runtime/Procedural/Scatter/Transform/RandomizeTransform.cs @@ -54,7 +54,7 @@ namespace Rokojori [Export] public Vector3 scaleNoiseOffset = Vector3.Zero; - + protected override List _Scatter( List points, Scatterer root ) { var output = points; diff --git a/Runtime/Random/RandomEngine.cs b/Runtime/Random/RandomEngine.cs index fe2ddb8..b31d409 100644 --- a/Runtime/Random/RandomEngine.cs +++ b/Runtime/Random/RandomEngine.cs @@ -377,6 +377,30 @@ namespace Rokojori return IndexFromUnnormalizedWeights( weights, 1 ); } + public List Numbers( int numValues, int offset = 0 ) + { + var list = new List(); + + for ( int i = 0; i < numValues; i++ ) + { + list.Add( i + offset ); + } + + return new RandomList( list, this ).GetList(); + } + + public List Selection( int possibleValues, int selection ) + { + var list = new List(); + + for ( int i = 0; i < possibleValues; i++ ) + { + list.Add( i ); + } + + return new RandomList( list, this ).GetList().GetRange( 0, selection ); + } + int _FindElementIndexWithWeights( List weights, float value ) { var limit = 0f; diff --git a/Runtime/Selectors/Selector.cs b/Runtime/Selectors/Selector.cs index 8b75b72..03768ef 100644 --- a/Runtime/Selectors/Selector.cs +++ b/Runtime/Selectors/Selector.cs @@ -16,5 +16,10 @@ namespace Rokojori { return true; } + + public static bool IsSelecting( Selector selector, Node node ) + { + return selector == null || selector.Selects( node ); + } } } \ No newline at end of file diff --git a/Runtime/Shading/Library/Transform.gdshaderinc b/Runtime/Shading/Library/Transform.gdshaderinc index b69d55d..959eb6c 100644 --- a/Runtime/Shading/Library/Transform.gdshaderinc +++ b/Runtime/Shading/Library/Transform.gdshaderinc @@ -15,6 +15,16 @@ vec3 applyMatrixWithTranslation( vec3 v, mat4 m ) return ( mw * vec4( v, 1.0 ) ).xyz; } +// L W V +// L +// W +// V + +// LD WD VD +// LD +// WD +// VD + vec3 localToWorld( vec3 _VERTEX, mat4 _MODEL_MATRIX ) { return ( _MODEL_MATRIX * vec4( _VERTEX, 1.0 ) ).xyz; diff --git a/Runtime/Shading/Materials/CustomMaterial.cs b/Runtime/Shading/Materials/CustomMaterial.cs index 9b536d9..a3725c4 100644 --- a/Runtime/Shading/Materials/CustomMaterial.cs +++ b/Runtime/Shading/Materials/CustomMaterial.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; namespace Rokojori { [Tool] - [GlobalClass] public partial class CustomMaterial:ShaderMaterial { public void CopyUniformsFrom( ShaderMaterial material ) diff --git a/Runtime/Shading/Shaders/Baking/Dilation.gdshader b/Runtime/Shading/Shaders/Baking/Dilation.gdshader new file mode 100644 index 0000000..51535c6 --- /dev/null +++ b/Runtime/Shading/Shaders/Baking/Dilation.gdshader @@ -0,0 +1,35 @@ +shader_type canvas_item; + +uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest; + +uniform float kernelOffset = 1; + +void fragment() +{ + vec2 pixelSize = SCREEN_PIXEL_SIZE * kernelOffset; + + vec4 blurred = vec4( 0, 0, 0, 0 ); + int kernel = 2; + + for ( int x = -kernel; x<= kernel; ++x ) + { + for ( int y = -kernel; y<= kernel; ++y ) + { + vec2 sampledUV = SCREEN_UV + pixelSize * vec2( float(x), float( y ) ); + vec4 value = textureLod( screen_texture, sampledUV, 0 ); + + if ( ( value.r + value.g + value.b ) * 255.0 < 10.0 ) + { + value.a = 0.0; + } + + blurred += value; + } + } + + blurred /= float( kernel * kernel ); + + + COLOR = blurred; + ; +} diff --git a/Runtime/Shading/Shaders/Baking/Dilation.gdshader.uid b/Runtime/Shading/Shaders/Baking/Dilation.gdshader.uid new file mode 100644 index 0000000..fd6a5f2 --- /dev/null +++ b/Runtime/Shading/Shaders/Baking/Dilation.gdshader.uid @@ -0,0 +1 @@ +uid://djf46k1sq5eks diff --git a/Runtime/Shading/Shaders/Billboards/QuadBillboard/QuadBillboardMaterial.cs b/Runtime/Shading/Shaders/Billboards/QuadBillboard/QuadBillboardMaterial.cs index de18579..da7d0c7 100644 --- a/Runtime/Shading/Shaders/Billboards/QuadBillboard/QuadBillboardMaterial.cs +++ b/Runtime/Shading/Shaders/Billboards/QuadBillboard/QuadBillboardMaterial.cs @@ -49,7 +49,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class QuadBillboardMaterial:CustomMaterial { diff --git a/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutlineMaterial.cs b/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutlineMaterial.cs index b4a4d84..45581f8 100644 --- a/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutlineMaterial.cs +++ b/Runtime/Shading/Shaders/Effects/FancyOutline/FancyOutlineMaterial.cs @@ -25,7 +25,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class FancyOutlineMaterial:CustomMaterial { public static readonly CachedResource ScanWhite500Ms20x = CustomMaterial.Cached( diff --git a/Runtime/Shading/Shaders/Effects/FresnelOverlay/FresnelOverlayMaterial.cs b/Runtime/Shading/Shaders/Effects/FresnelOverlay/FresnelOverlayMaterial.cs index 6ff2d81..2ecd445 100644 --- a/Runtime/Shading/Shaders/Effects/FresnelOverlay/FresnelOverlayMaterial.cs +++ b/Runtime/Shading/Shaders/Effects/FresnelOverlay/FresnelOverlayMaterial.cs @@ -20,7 +20,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class FresnelOverlayMaterial:CustomMaterial { diff --git a/Runtime/Shading/Shaders/Effects/Outline/OutlineMaterial.cs b/Runtime/Shading/Shaders/Effects/Outline/OutlineMaterial.cs index 7dec3b7..12b352c 100644 --- a/Runtime/Shading/Shaders/Effects/Outline/OutlineMaterial.cs +++ b/Runtime/Shading/Shaders/Effects/Outline/OutlineMaterial.cs @@ -22,7 +22,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class OutlineMaterial:CustomMaterial { public static readonly CachedResource BoldYellow = CustomMaterial.Cached( diff --git a/Runtime/Shading/Shaders/Effects/Overlay/OverlayMaterial.cs b/Runtime/Shading/Shaders/Effects/Overlay/OverlayMaterial.cs index 4291975..5047b44 100644 --- a/Runtime/Shading/Shaders/Effects/Overlay/OverlayMaterial.cs +++ b/Runtime/Shading/Shaders/Effects/Overlay/OverlayMaterial.cs @@ -17,7 +17,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class OverlayMaterial:CustomMaterial { diff --git a/Runtime/Shading/Shaders/Effects/ScanGradient/ScanGradientMaterial.cs b/Runtime/Shading/Shaders/Effects/ScanGradient/ScanGradientMaterial.cs index d0e4739..8e66401 100644 --- a/Runtime/Shading/Shaders/Effects/ScanGradient/ScanGradientMaterial.cs +++ b/Runtime/Shading/Shaders/Effects/ScanGradient/ScanGradientMaterial.cs @@ -29,7 +29,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class ScanGradientMaterial:CustomMaterial { public static readonly CachedResource White = CustomMaterial.Cached( diff --git a/Runtime/Shading/Shaders/Effects/TriPlanarOverlay/TriPlanarOverlayMaterial.cs b/Runtime/Shading/Shaders/Effects/TriPlanarOverlay/TriPlanarOverlayMaterial.cs index 90001b4..f354761 100644 --- a/Runtime/Shading/Shaders/Effects/TriPlanarOverlay/TriPlanarOverlayMaterial.cs +++ b/Runtime/Shading/Shaders/Effects/TriPlanarOverlay/TriPlanarOverlayMaterial.cs @@ -20,7 +20,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class TriPlanarOverlayMaterial:CustomMaterial { public static readonly CachedResource BlueShield = CustomMaterial.Cached( diff --git a/Runtime/Shading/Shaders/Wipes/FadeWipe/FadeWipeMaterial.cs b/Runtime/Shading/Shaders/Wipes/FadeWipe/FadeWipeMaterial.cs index a5f1483..b02ee65 100644 --- a/Runtime/Shading/Shaders/Wipes/FadeWipe/FadeWipeMaterial.cs +++ b/Runtime/Shading/Shaders/Wipes/FadeWipe/FadeWipeMaterial.cs @@ -24,7 +24,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class FadeWipeMaterial:CustomMaterial { diff --git a/Runtime/Shading/Tools/CSShaderClassGenerator/CSShaderClassTemplate.txt b/Runtime/Shading/Tools/CSShaderClassGenerator/CSShaderClassTemplate.txt index a95388c..a20677e 100644 --- a/Runtime/Shading/Tools/CSShaderClassGenerator/CSShaderClassTemplate.txt +++ b/Runtime/Shading/Tools/CSShaderClassGenerator/CSShaderClassTemplate.txt @@ -15,7 +15,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class ${ShaderName}Material:CustomMaterial { ${MaterialPresets} diff --git a/Runtime/Structures/QueueList.cs b/Runtime/Structures/QueueList.cs new file mode 100644 index 0000000..1f2eafd --- /dev/null +++ b/Runtime/Structures/QueueList.cs @@ -0,0 +1,54 @@ + +using System.Collections.Generic; + +namespace Rokojori +{ + public class QueueList:List + { + List _queuedInsertions = new List(); + List _queuedRemovals = new List(); + + public void QueueInsert( T t ) + { + _queuedInsertions.Add( t ); + } + + public void QueueRemoval( T t ) + { + _queuedRemovals.Add( t ); + } + + public void IterateAndResolve( System.Action callback ) + { + ResolveRemovalsQueue(); + ResolveInsertionQueue(); + + this.ForEach( t => callback( t ) ); + + ResolveRemovalsQueue(); + } + + protected void ResolveInsertionQueue() + { + if ( _queuedInsertions.Count == 0 ) + { + return; + } + + AddRange( _queuedInsertions ); + _queuedInsertions.Clear(); + } + + protected void ResolveRemovalsQueue() + { + if ( _queuedRemovals.Count == 0 ) + { + return; + } + + Lists.RemoveRange( this, _queuedRemovals ); + _queuedRemovals.Clear(); + } + + } +} \ No newline at end of file diff --git a/Runtime/Time/TimeLineManager.cs b/Runtime/Time/TimeLineManager.cs index 8b22b4a..8ea6013 100644 --- a/Runtime/Time/TimeLineManager.cs +++ b/Runtime/Time/TimeLineManager.cs @@ -50,16 +50,31 @@ namespace Rokojori float _lastTimeScale = 1; + QueueList _processCallbacks = new QueueList(); + public override void _Process( double delta ) { UpdateRealTime( delta ); if ( ! Engine.IsEditorHint() && gametimeTimeline != null ) { - Engine.TimeScale = gametimeTimeline.runner.modulatedSpeed; + Engine.TimeScale = GetRunner( gametimeTimeline ).modulatedSpeed; + } - _runners.ForEach( r => r.UpdateTimeLine( unscaledTimeDelta ) ); + _runners.ForEach( r => r.UpdateTimeLine( unscaledTimeDelta ) ); + + _processCallbacks.IterateAndResolve( t => t() ); + } + + public void AddProcessCallback( System.Action a ) + { + _processCallbacks.QueueInsert( a ); + } + + public void RemoveProcessCallback( System.Action a ) + { + _processCallbacks.QueueRemoval( a ); } public int GetTimeLineIndex( TimeLine timeLine ) diff --git a/Runtime/UI/Shaders/NinePatch/UINinePatchMaterial.cs b/Runtime/UI/Shaders/NinePatch/UINinePatchMaterial.cs index d74804c..729ca3c 100644 --- a/Runtime/UI/Shaders/NinePatch/UINinePatchMaterial.cs +++ b/Runtime/UI/Shaders/NinePatch/UINinePatchMaterial.cs @@ -16,7 +16,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class UINinePatchMaterial:CustomMaterial { diff --git a/Runtime/UI/Shaders/RoundedRectangle/RoundedRectangleMaterial.cs b/Runtime/UI/Shaders/RoundedRectangle/RoundedRectangleMaterial.cs index 4800576..9cfba3a 100644 --- a/Runtime/UI/Shaders/RoundedRectangle/RoundedRectangleMaterial.cs +++ b/Runtime/UI/Shaders/RoundedRectangle/RoundedRectangleMaterial.cs @@ -32,7 +32,6 @@ namespace Rokojori } [Tool] - [GlobalClass] public partial class RoundedRectangleMaterial:CustomMaterial {