diff --git a/Runtime/Actions/Visual/TweenFloat.cs b/Runtime/Actions/Visual/TweenFloat.cs index 5268366..ae75c81 100644 --- a/Runtime/Actions/Visual/TweenFloat.cs +++ b/Runtime/Actions/Visual/TweenFloat.cs @@ -66,7 +66,23 @@ namespace Rokojori return; } - ReflectionHelper.SetValue( target, prop, value ); + try + { + ReflectionHelper.SetValue( target, prop, value ); + } + catch ( Exception e ) + { + try + { + ReflectionHelper.SetValue( target, prop, (int)value ); + } + catch ( Exception ex ) + { + + } + } + + } protected override void _OnTrigger() diff --git a/Runtime/Animation/Driver/FloatDriver.cs b/Runtime/Animation/Driver/FloatDriver.cs index 01c1bc8..0b05c9e 100644 --- a/Runtime/Animation/Driver/FloatDriver.cs +++ b/Runtime/Animation/Driver/FloatDriver.cs @@ -6,9 +6,14 @@ using Godot; namespace Rokojori { + public interface IFloatDriver + { + public float GetDriverFloatValue(); + } + [Tool] [GlobalClass] - public partial class FloatDriver:Node + public partial class FloatDriver:Node, IFloatDriver { float _driverValue = 0f; @@ -23,17 +28,15 @@ namespace Rokojori } } + public float GetDriverFloatValue() + { return _driverValue; } + [ExportToolButton( "Update Value")] public Callable updateValueButton => Callable.From( ()=> UpdateValue() ) ; void UpdateValue() - { - if ( targets == null ) - { - return; - } - - for ( int i = 0; i < targets.Length; i++ ) + { + for ( int i = 0; targets != null && i < targets.Length; i++ ) { if ( targets[ i ] == null || targets[ i ].GetGodotObject( this ) == null ) { @@ -42,11 +45,40 @@ namespace Rokojori targets[ i ].Update( this ); } + + onChange?.Trigger(); + + if ( value == 0 ) + { + onZero?.Trigger(); + } + else if ( value == 1 ) + { + onOne?.Trigger(); + } + else + { + onIntermediate?.Trigger(); + } } [Export] public FloatDriverTarget[] targets = []; + [Export] + public Action onChange; + + [Export] + public Action onZero; + + [Export] + public Action onOne; + + [Export] + public Action onIntermediate; + + + } diff --git a/Runtime/Animation/Driver/FloatDriverCompositorEffectTarget.cs b/Runtime/Animation/Driver/FloatDriverCompositorEffectTarget.cs new file mode 100644 index 0000000..8b89bc1 --- /dev/null +++ b/Runtime/Animation/Driver/FloatDriverCompositorEffectTarget.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using System.Text; +using Godot; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class FloatDriverCompositorEffectTarget:FloatDriverTarget + { + [Export] + public CompositorEffectReference compositorEffectReference; + + [Export] + public string targetMemberPath; + + public override GodotObject GetGodotObject( IFloatDriver driver ) + { + return compositorEffectReference.GetCompositorEffect( driver as Node ); + } + + public override string GetTargetMemberPath( IFloatDriver driver ) + { + return targetMemberPath; + } + + } +} \ No newline at end of file diff --git a/Runtime/Animation/Driver/FloatDriverCompositorEffectTarget.cs.uid b/Runtime/Animation/Driver/FloatDriverCompositorEffectTarget.cs.uid new file mode 100644 index 0000000..a3f1447 --- /dev/null +++ b/Runtime/Animation/Driver/FloatDriverCompositorEffectTarget.cs.uid @@ -0,0 +1 @@ +uid://bc72e1jvuv48g diff --git a/Runtime/Animation/Driver/FloatDriverNodeTarget.cs b/Runtime/Animation/Driver/FloatDriverNodeTarget.cs index b8119e9..958d472 100644 --- a/Runtime/Animation/Driver/FloatDriverNodeTarget.cs +++ b/Runtime/Animation/Driver/FloatDriverNodeTarget.cs @@ -16,12 +16,12 @@ namespace Rokojori [Export] public string targetMemberPath; - public override GodotObject GetGodotObject( FloatDriver driver ) + public override GodotObject GetGodotObject( IFloatDriver driver ) { - return driver.GetNode( nodePath ); + return ( driver as Node ).GetNode( nodePath ); } - public override string GetTargetMemberPath( FloatDriver driver ) + public override string GetTargetMemberPath( IFloatDriver driver ) { return targetMemberPath; } diff --git a/Runtime/Animation/Driver/FloatDriverResourceTarget.cs b/Runtime/Animation/Driver/FloatDriverResourceTarget.cs index e2ceba9..43bb166 100644 --- a/Runtime/Animation/Driver/FloatDriverResourceTarget.cs +++ b/Runtime/Animation/Driver/FloatDriverResourceTarget.cs @@ -16,12 +16,12 @@ namespace Rokojori [Export] public string targetMemberPath; - public override GodotObject GetGodotObject( FloatDriver driver ) + public override GodotObject GetGodotObject( IFloatDriver driver ) { return resource; } - public override string GetTargetMemberPath( FloatDriver driver ) + public override string GetTargetMemberPath( IFloatDriver driver ) { return targetMemberPath; } diff --git a/Runtime/Animation/Driver/FloatDriverTarget.cs b/Runtime/Animation/Driver/FloatDriverTarget.cs index 1fd0c62..4c40126 100644 --- a/Runtime/Animation/Driver/FloatDriverTarget.cs +++ b/Runtime/Animation/Driver/FloatDriverTarget.cs @@ -14,13 +14,13 @@ namespace Rokojori [Export] public Curve mappingCurve; - public abstract string GetTargetMemberPath( FloatDriver driver ); + public abstract string GetTargetMemberPath( IFloatDriver driver ); - public abstract GodotObject GetGodotObject( FloatDriver driver ); + public abstract GodotObject GetGodotObject( IFloatDriver driver ); - public void Update( FloatDriver driver ) + public void Update( IFloatDriver driver ) { - var mappedValue = mappingCurve.Sample( driver.value ); + var mappedValue = mappingCurve.Sample( driver.GetDriverFloatValue() ); var targetMemberPath = GetTargetMemberPath( driver ); TweenFloat.SetTargetValue( GetGodotObject( driver ), targetMemberPath, mappedValue ); } diff --git a/Runtime/Cameras/CameraManager.cs b/Runtime/Cameras/CameraManager.cs index 6c7aad7..57bde74 100644 --- a/Runtime/Cameras/CameraManager.cs +++ b/Runtime/Cameras/CameraManager.cs @@ -37,6 +37,9 @@ namespace Rokojori [Export] public bool postProcess = true; + [Export] + public CompositorEffectLayout compositorLayout = new CompositorEffectLayout(); + [Export] public PostProcessVolume[] postProcessVolumes = []; diff --git a/Runtime/Godot/Editor/Undo.cs b/Runtime/Godot/Editor/Undo.cs new file mode 100644 index 0000000..39b1796 --- /dev/null +++ b/Runtime/Godot/Editor/Undo.cs @@ -0,0 +1,100 @@ +using Godot; +using System.Text; +using System.Collections.Generic; +using System; + +namespace Rokojori +{ + public class UndoGDMarker + { + public string name = ""; + } + + public class UndoGD + { + static UndoGDMarker undoActionMarker = null; + + #if TOOLS + + static EditorUndoRedoManager UndoManager() + { + return EditorInterface.Singleton.GetEditorUndoRedo(); + } + + #endif + + public static UndoGDMarker Start( string actionName ) + { + #if TOOLS + + if ( undoActionMarker != null ) + { + return null; + } + + undoActionMarker = new UndoGDMarker(); + undoActionMarker.name = actionName; + + // UndoManager().CreateAction( actionName ); + + return undoActionMarker; + + #else + + return null; + + #endif + } + + + public static void End( UndoGDMarker marker ) + { + #if TOOLS + + if ( undoActionMarker != marker ) + { + return; + } + + // UndoManager().CommitAction(); + undoActionMarker = null; + + #else + + #endif + } + + public static void Set( GodotObject obj, string member, T value ) + { + #if TOOLS + + try + { + if ( undoActionMarker == null ) + { + RJLog.ErrorGD( obj, "No undo marker! ", member, ">>", value ); + return; + } + + var currentValue = ReflectionHelper.GetValue( obj, member ); + // UndoManager().AddUndoProperty( obj, member, (GodotObject)(object)currentValue ); + // UndoManager().AddDoProperty( obj, member, (GodotObject)(object)value ); + + } + catch( Exception e ) + { + + } + + ReflectionHelper.SetValue( obj, member, value ); + + #else + + ReflectionHelper.SetValue( obj, member, value ); + + #endif + + + } + } +} \ No newline at end of file diff --git a/Runtime/Godot/Editor/Undo.cs.uid b/Runtime/Godot/Editor/Undo.cs.uid new file mode 100644 index 0000000..2810e0f --- /dev/null +++ b/Runtime/Godot/Editor/Undo.cs.uid @@ -0,0 +1 @@ +uid://b3t2srtl1tli0 diff --git a/Runtime/Godot/Extensions/ArrayExtensions.cs b/Runtime/Godot/Extensions/ArrayExtensions.cs new file mode 100644 index 0000000..b9b7a1d --- /dev/null +++ b/Runtime/Godot/Extensions/ArrayExtensions.cs @@ -0,0 +1,31 @@ +using Godot; +using System.Text; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + public static class ArrayExtensions + { + public static void ForEach<[MustBeVariant] T>( this Godot.Collections.Array array, System.Action action ) + { + for (int i = 0; i < array.Count; i++) + { + action( array[i] ); + } + } + + public static T Find<[MustBeVariant] T>( this Godot.Collections.Array array, System.Func evaluater ) + { + for ( int i = 0; i < array.Count; i++ ) + { + if ( evaluater( array[ i ] ) ) + { + return array[ i ]; + } + } + + return default(T); + } + } +} \ No newline at end of file diff --git a/Runtime/Godot/Extensions/ArrayExtensions.cs.uid b/Runtime/Godot/Extensions/ArrayExtensions.cs.uid new file mode 100644 index 0000000..3a981a0 --- /dev/null +++ b/Runtime/Godot/Extensions/ArrayExtensions.cs.uid @@ -0,0 +1 @@ +uid://clusd1thvxjac diff --git a/Runtime/Godot/Extensions/Vector2Extensions.cs b/Runtime/Godot/Extensions/Vector2Extensions.cs new file mode 100644 index 0000000..afc9999 --- /dev/null +++ b/Runtime/Godot/Extensions/Vector2Extensions.cs @@ -0,0 +1,15 @@ +using Godot; +using System.Text; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + public static class Vector2Extensions + { + public static Vector4 ToVector4( this Vector2 xy, Vector2 zw ) + { + return new Vector4( xy.X, xy.Y, zw.X, zw.Y ); + } + } +} \ No newline at end of file diff --git a/Runtime/Godot/Extensions/Vector2Extensions.cs.uid b/Runtime/Godot/Extensions/Vector2Extensions.cs.uid new file mode 100644 index 0000000..13ef2dd --- /dev/null +++ b/Runtime/Godot/Extensions/Vector2Extensions.cs.uid @@ -0,0 +1 @@ +uid://c0d8bml6nct6w diff --git a/Runtime/Godot/Extensions/Vector4Extensions.cs b/Runtime/Godot/Extensions/Vector4Extensions.cs new file mode 100644 index 0000000..ae14c24 --- /dev/null +++ b/Runtime/Godot/Extensions/Vector4Extensions.cs @@ -0,0 +1,15 @@ +using Godot; +using System.Text; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + public static class Vector4Extensions + { + public static Vector4 Create( Vector2 xy, Vector2 zw ) + { + return new Vector4( xy.X, xy.Y, zw.X, zw.Y ); + } + } +} \ No newline at end of file diff --git a/Runtime/Godot/Extensions/Vector4Extensions.cs.uid b/Runtime/Godot/Extensions/Vector4Extensions.cs.uid new file mode 100644 index 0000000..eb3a887 --- /dev/null +++ b/Runtime/Godot/Extensions/Vector4Extensions.cs.uid @@ -0,0 +1 @@ +uid://bh02vu5qnklci diff --git a/Runtime/Logging/RJLog.cs b/Runtime/Logging/RJLog.cs index e042560..1eef39a 100644 --- a/Runtime/Logging/RJLog.cs +++ b/Runtime/Logging/RJLog.cs @@ -262,6 +262,22 @@ namespace Rokojori LogErrorMessage( "" + HierarchyName.Of( resource ) + "\n" + GetLogString( objects ), 4 ); } + public static void ErrorGD( GodotObject obj, params object[] objects) + { + if ( obj is Node n ) + { + Error( n, objects ); + } + else if ( obj is Resource r ) + { + Error( r, objects ); + } + else + { + LogErrorMessage( "" + obj + "\n" + GetLogString( objects ), 4 ); + } + } + public static string GetLogString( object[] objects ) diff --git a/Runtime/Rendering/ColorSpace.cs b/Runtime/Rendering/ColorSpace.cs new file mode 100644 index 0000000..fe55235 --- /dev/null +++ b/Runtime/Rendering/ColorSpace.cs @@ -0,0 +1,24 @@ + +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; +using System; +using Godot; + + +namespace Rokojori +{ + public enum ColorSpace + { + Unknown, + sRGB, + Linear + } + + public enum ColorSpaceConversion + { + No_Conversion, + Linear_to_sRGB, + sRGB_to_Linear + } +} \ No newline at end of file diff --git a/Runtime/Rendering/ColorSpace.cs.uid b/Runtime/Rendering/ColorSpace.cs.uid new file mode 100644 index 0000000..d0388fb --- /dev/null +++ b/Runtime/Rendering/ColorSpace.cs.uid @@ -0,0 +1 @@ +uid://cyvo4y3oorxf6 diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectDriverTarget.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectDriverTarget.cs new file mode 100644 index 0000000..27887f8 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectDriverTarget.cs @@ -0,0 +1,13 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public abstract partial class CompositorEffectDriverTarget:Resource + { + public abstract void OnDriverChange( RokojoriCompositorEffect re, float value ); + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectDriverTarget.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectDriverTarget.cs.uid new file mode 100644 index 0000000..ee9148d --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectDriverTarget.cs.uid @@ -0,0 +1 @@ +uid://dt61u7tn1hrws diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayer.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayer.cs new file mode 100644 index 0000000..0c661c8 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayer.cs @@ -0,0 +1,14 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CompositorEffectLayer:Resource + { + [Export] + public string layerName; + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayer.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayer.cs.uid new file mode 100644 index 0000000..764e615 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayer.cs.uid @@ -0,0 +1 @@ +uid://b2ik21q1iwjvo diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayout.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayout.cs new file mode 100644 index 0000000..9efb685 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayout.cs @@ -0,0 +1,112 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CompositorEffectLayout:Resource + { + [Export] + public CompositorEffectLayer[] layers; + + [Export] + public Compositor compositor; + + public void Ensure( RokojoriCompositorEffect[] effects, bool inside ) + { + + // this.LogInfo( "Ensure effects:", inside ); + + var list = new List>(); + var replacements = new List>(); + + effects.ForEach( + ( e )=> + { + var el = compositor.CompositorEffects.Find( ce => ce is RokojoriCompositorEffect re && re.compositorEffectID == e.compositorEffectID ); + + var isInside = el != null; + + if ( isInside == inside ) + { + if ( el != e ) + { + // var fx = compositor.CompositorEffects; + // var index = fx.IndexOf( el ); + + // fx[ index ] = e; + + // compositor.CompositorEffects = fx; + + replacements.Add( new System.Tuple( e, el as RokojoriCompositorEffect ) ) ; + } + + // this.LogInfo( "Already " + ( inside ? "inside" : "removed" ), e ); + return; + } + + if ( inside ) + { + // this.LogInfo( "Adding:", e ); + // compositor.CompositorEffects.Add( e ); + } + else + { + // this.LogInfo( "Removing:", el ); + + // compositor.CompositorEffects.Remove( e ); + } + + list.Add( new System.Tuple( e, el as RokojoriCompositorEffect ) ); + + + } + ); + + replacements.ForEach( + ( t )=> + { + var ef = t.Item1; + var indexE = effects.IndexOf( ef ); + var ce = t.Item2; + var indexC = compositor.CompositorEffects.IndexOf( ce ); + + effects[ indexE ] = (RokojoriCompositorEffect) ef.Duplicate(); + + var fx = compositor.CompositorEffects; + fx[ indexC ] = effects[ indexE ]; + compositor.CompositorEffects = fx; + } + ); + + + if ( list.Count > 0 ) + { + var newEffects = compositor.CompositorEffects; + + if ( inside ) + { + list.ForEach( + ( l )=> + { + var index = effects.IndexOf( l.Item1 ); + effects[ index ] = (RokojoriCompositorEffect) effects[ index ].Duplicate(); + newEffects.Add( effects[ index ] ); + } + ); + } + else + { + list.ForEach( e => newEffects.Remove( e.Item2 ) ); + } + + compositor.CompositorEffects = newEffects; + } + + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayout.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayout.cs.uid new file mode 100644 index 0000000..3ed7be8 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectLayout.cs.uid @@ -0,0 +1 @@ +uid://dn7xg8cqdnolq diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectMemberCurveTarget.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectMemberCurveTarget.cs new file mode 100644 index 0000000..4744c00 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectMemberCurveTarget.cs @@ -0,0 +1,47 @@ + +using Godot; +using System; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CompositorEffectMemberCurveTarget:CompositorEffectDriverTarget + { + [Export] + public string member; + + [Export] + public Curve curve; + + public enum TargetType + { + Float, + Int, + Bool + } + + [Export] + public TargetType targetType = TargetType.Float; + + public override void OnDriverChange( RokojoriCompositorEffect re, float value ) + { + var curveValue = curve == null ? value : curve.Sample( value ); + + if ( TargetType.Float == targetType ) + { + ReflectionHelper.SetValue( re, member, curveValue ); + } + else if ( TargetType.Int == targetType ) + { + ReflectionHelper.SetValue( re, member, (int)curveValue ); + } + else if ( TargetType.Bool == targetType ) + { + ReflectionHelper.SetValue( re, member, curveValue > 0 ); + } + + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectMemberCurveTarget.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectMemberCurveTarget.cs.uid new file mode 100644 index 0000000..08dae6f --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectMemberCurveTarget.cs.uid @@ -0,0 +1 @@ +uid://bwspscpb222by diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectOwner.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectOwner.cs new file mode 100644 index 0000000..1f67fb2 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectOwner.cs @@ -0,0 +1,13 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CompositorEffectOwner:Resource + { + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectOwner.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectOwner.cs.uid new file mode 100644 index 0000000..d37b4b2 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectOwner.cs.uid @@ -0,0 +1 @@ +uid://cx5qcow1mmd11 diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectReference.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectReference.cs new file mode 100644 index 0000000..1573322 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectReference.cs @@ -0,0 +1,13 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public abstract partial class CompositorEffectReference:Resource + { + public abstract CompositorEffect GetCompositorEffect( Node context ); + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectReference.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectReference.cs.uid new file mode 100644 index 0000000..f8cbb12 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorEffectReference.cs.uid @@ -0,0 +1 @@ +uid://cg5h1p6c6m1n6 diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFX.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFX.cs new file mode 100644 index 0000000..87d7f57 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFX.cs @@ -0,0 +1,160 @@ + +using Godot; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CompositorVFX:Node, IFloatDriver + { + [Export] + public CompositorVFXPreset preset; + + // [Export] + // public RokojoriCompositorEffect[] effects = []; + + float _driverValue = 0f; + + [Export( PropertyHint.Range, "0,1" ) ] + public float driverValue + { + get => _driverValue; + + set + { + _driverValue = value; + UpdateValue(); + } + } + + public float GetDriverFloatValue() + { + return _driverValue; + } + + public enum ManagingMode + { + None, + Remove_On_Zero_Insert_At_InterMediate, + Remove_On_NonIntermediate_Insert_Else + } + + [ExportGroup( "Actions")] + [Export] + public Action onChange; + + [Export] + public Action onZero; + + [Export] + public Action onOne; + + [Export] + public Action onIntermediate; + + [ExportGroup("Setup")] + [Export] + public ManagingMode managingMode = ManagingMode.Remove_On_Zero_Insert_At_InterMediate; + + [Export] + public CompositorEffectLayout layout; + + [Export] + public CompositorEffectOwner ownerReference; + + + void EnsureOwnerShip() + { + this.LogInfo( "EnsureOwnerShip", ownerReference ); + var undoMarker = UndoGD.Start( "Set Ownership for " + HierarchyName.Of( this ) ); + + if ( ownerReference == null ) + { + ownerReference = new CompositorEffectOwner(); + this.LogInfo( "Created ownership", ownerReference ); + UndoGD.Set( this, nameof( ownerReference ), ownerReference ); + } + + preset.effectPresets.ForEach( ep => SetOwnerShip( ep.effect ) ); + + UndoGD.End( undoMarker ); + } + + void SetOwnerShip( RokojoriCompositorEffect effect ) + { + var id = effect.compositorEffectID; + + if ( id == null ) + { + id = new RokojoriCompositorEffectID(); + UndoGD.Set( effect, nameof( effect.compositorEffectID ), id ); + } + + if ( id.owner != ownerReference ) + { + UndoGD.Set( id, nameof( id.owner ), ownerReference ); + } + } + + + public void UpdateValue() + { + this.LogInfo( "Updating value", _driverValue ); + + UpdateEffects(); + + onChange?.Trigger(); + + if ( _driverValue == 0 ) + { + onZero?.Trigger(); + } + else if ( _driverValue == 1 ) + { + onOne?.Trigger(); + } + else + { + onIntermediate?.Trigger(); + } + } + + void UpdateEffects() + { + if ( preset == null || preset.effectPresets == null || preset.effectPresets.Length == 0 ) + { + return; + } + + preset.effectPresets.ForEach( ep => ep.UpdateTargets( _driverValue ) ); + + if ( managingMode != ManagingMode.None ) + { + EnsureOwnerShip(); + + var effects = preset.effectPresets.Map( ep => ep.effect ).ToArray(); + + var currentLayout = layout != null ? layout : Unique.Get().compositorLayout; + + if ( _driverValue == 0 || ( _driverValue == 1 && managingMode == ManagingMode.Remove_On_NonIntermediate_Insert_Else ) ) + { + currentLayout.Ensure( effects, false ); + } + else + { + currentLayout.Ensure( effects, true ); + + for ( int i = 0; i < effects.Length; i++ ) + { + preset.effectPresets[ i ].effect = effects[ i ]; + } + } + + + } + } + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFX.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFX.cs.uid new file mode 100644 index 0000000..c590ce3 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFX.cs.uid @@ -0,0 +1 @@ +uid://cebnf3dtch0oh diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXEffectPreset.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXEffectPreset.cs new file mode 100644 index 0000000..a169d3a --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXEffectPreset.cs @@ -0,0 +1,23 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CompositorVFXEffectPreset:Resource + { + [Export] + public RokojoriCompositorEffect effect; + + [Export] + public CompositorEffectDriverTarget[] targets; + + public void UpdateTargets( float value ) + { + targets.ForEach( t => t.OnDriverChange( effect, value ) ); + } + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXEffectPreset.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXEffectPreset.cs.uid new file mode 100644 index 0000000..2072c09 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXEffectPreset.cs.uid @@ -0,0 +1 @@ +uid://cs4onr5s6171q diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXPreset.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXPreset.cs new file mode 100644 index 0000000..588c926 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXPreset.cs @@ -0,0 +1,14 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CompositorVFXPreset:Resource + { + [Export] + public CompositorVFXEffectPreset[] effectPresets = []; + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXPreset.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXPreset.cs.uid new file mode 100644 index 0000000..1ec662d --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/CompositorVFXPreset.cs.uid @@ -0,0 +1 @@ +uid://ckixweetchlo0 diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectID.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectID.cs new file mode 100644 index 0000000..01862da --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectID.cs @@ -0,0 +1,20 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class RokojoriCompositorEffectID:Resource + { + [Export] + public CompositorEffectOwner owner; + + [Export] + public CompositorEffectLayer layer; + + [Export] + public int priority = 0; + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectID.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectID.cs.uid new file mode 100644 index 0000000..0199684 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectID.cs.uid @@ -0,0 +1 @@ +uid://comuvej4dr22k diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectIDReference.cs b/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectIDReference.cs new file mode 100644 index 0000000..b3b23df --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectIDReference.cs @@ -0,0 +1,31 @@ + +using Godot; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class RokojoriCompositorEffectIDReference:CompositorEffectReference + { + [Export] + public NodePath worldEnvironmentPath; + + [Export] + public RokojoriCompositorEffectID compositorEffectID; + + public override CompositorEffect GetCompositorEffect( Node context ) + { + var we = context.GetNode( worldEnvironmentPath ); + + if ( we == null || we.Compositor == null ) + { + return null; + } + + var fxs = we.Compositor.CompositorEffects; + return fxs.Find( c => c is RokojoriCompositorEffect rce && rce.compositorEffectID == compositorEffectID ); + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectIDReference.cs.uid b/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectIDReference.cs.uid new file mode 100644 index 0000000..9561e02 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffectReferences/RokojoriCompositorEffectIDReference.cs.uid @@ -0,0 +1 @@ +uid://c5sw7q34a6m7f diff --git a/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DAA/DAAEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DAA/DAAEffect.cs new file mode 100644 index 0000000..e7537be --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DAA/DAAEffect.cs @@ -0,0 +1,130 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class DAAEffect:RDGraphCompositorEffect + { + public DAAEffect():base() + { + Initialize(); + } + + + [Export( PropertyHint.Range, "0,4")] + public float amount = 1; + + [Export( PropertyHint.Range, "0,1")] + public float edgeTreshold = 0.2f; + + [Export( PropertyHint.Range, "1,4")] + public float edgeTresholdPower = 1f; + + [Export( PropertyHint.Range, "0,4")] + public float edgeIntensity = 2f; + + [Export( PropertyHint.Range, "0,1")] + public float blurMix = 0.25f; + + public enum BlurMode + { + UniDirectional, + BiDirectional + } + + [Export] + public BlurMode blurMode = BlurMode.UniDirectional; + + [Export( PropertyHint.Range, "1,10" )] + public int blurSpread = 1; + + CEG_ScreenColorTexure screenColorTexture; + + RG_DAA _daa0; + RG_DAA _daa1; + RG_DAA _daa2; + RG_DAA _daa3; + + List _daa = []; + + + void Initialize() + { + EffectCallbackType = EffectCallbackTypeEnum.PostOpaque; + + screenColorTexture = new CEG_ScreenColorTexure( graph ); + _daa0 = new RG_DAA( graph ); + _daa1 = new RG_DAA( graph ); + _daa2 = new RG_DAA( graph ); + _daa3 = new RG_DAA( graph ); + + graph.InitializeNodes(); + + _daa = [ _daa0, _daa1, _daa2, _daa3 ]; + + _daa.ForEach( fx => + { + fx.input.sampler = context.Sampler( RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode.ClampToEdge ); + fx.SetTextureSlotInputs( screenColorTexture, screenColorTexture ); + } + ); + + + graph.SetProcessOrder( + screenColorTexture, + _daa0, + _daa1, + _daa2, + _daa3 + ); + } + + int lastIterations = -1; + + protected override void ForAllViews() + { + var clampedAmount = Mathf.Min( 3.99999999f, amount ); + int numIterations = Mathf.CeilToInt( clampedAmount ); + var partialAmount = amount - ( numIterations - 1 ); + + + if ( lastIterations != numIterations ) + { + lastIterations = numIterations; + var list = new List(); + + list.Add( screenColorTexture ); + + for ( int i = 0; i < numIterations; i++ ) + { + list.Add( _daa[ i ] ); + } + + graph.SetProcessOrder( list.ToArray() ); + } + + for ( int i = 0; i < numIterations; i++ ) + { + float fxAmount = i == ( numIterations - 1 ) ? partialAmount : 1f; + + _daa[ i ].constants.Set( + fxAmount, + Mathf.Pow( edgeTreshold, edgeTresholdPower ), + edgeIntensity, + blurMix, + + (float)blurMode, + (float)blurSpread, + 0f, + 0f + ); + } + + + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DAA/DAAEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DAA/DAAEffect.cs.uid new file mode 100644 index 0000000..da11d5f --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DAA/DAAEffect.cs.uid @@ -0,0 +1 @@ +uid://c88y1hc8yya48 diff --git a/Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingEffect.cs similarity index 80% rename from Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingEffect.cs rename to Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingEffect.cs index 6cba7a2..c0f6313 100644 --- a/Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingEffect.cs +++ b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingEffect.cs @@ -7,9 +7,9 @@ namespace Rokojori { [Tool] [GlobalClass] - public abstract partial class DepthAntiAliasingEffect:SingleShaderCompositorEffect + public abstract partial class DepthAntiAliasingEffect:SingleShaderCompositorEffect { - public static readonly string shaderPath = Path( "DepthAntiAliasing/DepthAntiAliasingShader.glsl" ); + public static readonly string shaderPath = Path( "AntiAliasing/DepthAntiAliasing/DepthAntiAliasingShader.glsl" ); RDSampler sampler; @@ -48,7 +48,7 @@ namespace Rokojori { base.OnInitialize(); - sampler = context.Sampler( RenderingDevice.SamplerFilter.Nearest, RenderingDevice.SamplerRepeatMode.ClampToEdge ); + sampler = context.Sampler( RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode.ClampToEdge ); } @@ -58,12 +58,16 @@ namespace Rokojori constants.Set( (Vector2)context.internalSize, new Vector2( greyAmount, depthAmount ), + Vector2.Zero, + Vector2.Zero, effectStrength, depthEdgeTreshold / 100f, depthEdgeIntensity * 20f, colorContrastTreshold / 100f, colorContrastIntensity * 20f, - debugView + debugView, + 0f, + 0f ); } diff --git a/Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingEffect.cs.uid similarity index 100% rename from Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingEffect.cs.uid rename to Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingEffect.cs.uid diff --git a/Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingShader.glsl b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingShader.glsl similarity index 97% rename from Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingShader.glsl rename to Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingShader.glsl index ff088ea..429fe44 100644 --- a/Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingShader.glsl +++ b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingShader.glsl @@ -15,12 +15,18 @@ uniform Params { vec2 rasterSize; vec2 amounts; + vec2 pad0; + vec2 pad1; + float effectStrength; float edgeThreshold; float edgeIntensity; float contrastThreshold; + float contrastIntensity; float debugView; + float pad2; + float pad3; } params; diff --git a/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingShader.glsl.import b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingShader.glsl.import new file mode 100644 index 0000000..8d2f2b1 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingShader.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://us4n0un8oo2v" +path="res://.godot/imported/DepthAntiAliasingShader.glsl-62b6b5b853b384dd1246151bf3fa7d65.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/DepthAntiAliasing/DepthAntiAliasingShader.glsl" +dest_files=["res://.godot/imported/DepthAntiAliasingShader.glsl-62b6b5b853b384dd1246151bf3fa7d65.res"] + +[params] + diff --git a/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/FXAA/FXAAEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/FXAA/FXAAEffect.cs new file mode 100644 index 0000000..d001975 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/FXAA/FXAAEffect.cs @@ -0,0 +1,124 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class FXAAEffect:RDGraphCompositorEffect + { + public FXAAEffect():base() + { + Initialize(); + } + + + [Export( PropertyHint.Range, "0,4")] + public float amount = 1; + + public enum ExecutionMode + { + Ints_FullAmount_Fraction_PartialAmount, + Four_With_PartialAmount + } + + [Export] + public ExecutionMode executionMode = ExecutionMode.Ints_FullAmount_Fraction_PartialAmount; + + // [Export( PropertyHint.Range, "0,2")] + // public float exposure = 1f; + + // [Export( PropertyHint.Range, "0,2")] + // public float luminance_multiplier = 1f; + + + CEG_ScreenColorTexure screenColorTexture; + + RG_FXAA _fxaa0; + RG_FXAA _fxaa1; + RG_FXAA _fxaa2; + RG_FXAA _fxaa3; + + List _fxaa = []; + + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + _fxaa0 = new RG_FXAA( graph ); + _fxaa1 = new RG_FXAA( graph ); + _fxaa2 = new RG_FXAA( graph ); + _fxaa3 = new RG_FXAA( graph ); + + graph.InitializeNodes(); + + _fxaa = [ _fxaa0, _fxaa1, _fxaa2, _fxaa3 ]; + + _fxaa.ForEach( fx => + { + fx.input.sampler = context.Sampler( RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode.ClampToEdge ); + fx.SetTextureSlotInputs( screenColorTexture, screenColorTexture ); + } + ); + + + graph.SetProcessOrder( + screenColorTexture, + _fxaa0, + _fxaa1, + _fxaa2, + _fxaa3 + ); + } + + int lastIterations = -1; + + protected override void ForAllViews() + { + var clampedAmount = Mathf.Min( 3.99999999f, amount ); + int numIterations = Mathf.CeilToInt( clampedAmount ); + var partialAmount = amount - ( numIterations - 1 ); + + if ( ExecutionMode.Four_With_PartialAmount == executionMode ) + { + numIterations = 4; + } + + + if ( lastIterations != numIterations ) + { + lastIterations = numIterations; + var list = new List(); + + list.Add( screenColorTexture ); + + for ( int i = 0; i < numIterations; i++ ) + { + list.Add( _fxaa[ i ] ); + } + + graph.SetProcessOrder( list.ToArray() ); + } + + for ( int i = 0; i < numIterations; i++ ) + { + float fxAmount = i == ( numIterations - 1 ) ? partialAmount : 1f; + + if ( ExecutionMode.Four_With_PartialAmount == executionMode ) + { + fxAmount = amount / 4.0f; + } + + _fxaa[ i ].constants.Set( + 1f, + 1f, + fxAmount + ); + } + + + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/FXAA/FXAAEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/FXAA/FXAAEffect.cs.uid new file mode 100644 index 0000000..b87aef8 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/AntiAliasing/FXAA/FXAAEffect.cs.uid @@ -0,0 +1 @@ +uid://bgw3wuqxbwrb0 diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Color/CrossChannelCurves/CrossChannelCurvesEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Color/CrossChannelCurves/CrossChannelCurvesEffect.cs new file mode 100644 index 0000000..ea06689 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Color/CrossChannelCurves/CrossChannelCurvesEffect.cs @@ -0,0 +1,96 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class CrossChannelCurvesEffect:RDGraphCompositorEffect + { + public CrossChannelCurvesEffect():base() + { + Initialize(); + } + + public enum CrossChannelDriver + { + Red, + Green, + Blue, + Hue, + Saturation, + Lightness + } + + public enum CrossChannelTarget + { + Red, + Green, + Blue, + Hue, + Saturation, + Lightness, + Temparature + } + + [Export( PropertyHint.Range, "0,1") ] + public float amount = 0.5f; + + [Export] + public CrossChannelDriver driver = CrossChannelDriver.Lightness; + + [Export] + public CrossChannelTarget target = CrossChannelTarget.Saturation; + + [Export] + public CurveTexture curve = new CurveTexture(); + + CEG_ScreenColorTexure screenColorTexture; + RG_ImageTexture _curvesTexture; + RG_CrossChannelCurves _curves; + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + _curvesTexture = new RG_ImageTexture( graph ); + _curves = new RG_CrossChannelCurves( graph ); + + + graph.InitializeNodes(); + + + _curves.SetTextureSlotInputs( screenColorTexture, screenColorTexture ); + _curves.SetCurvesTextureSlotInputs( _curvesTexture ); + + _curvesTexture.SetImageTexture( curve ); + + _curves.curves.sampler = context.Sampler( RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode.ClampToEdge ); + + graph.SetProcessOrder( + screenColorTexture, + _curves + ); + } + + + protected override void ForAllViews() + { + _curvesTexture.SetImageTexture( curve ); + + _curves.constants.Set( + amount, + (float)(int)driver, + (float)(int)target, + 0f, + 0f, + 0f, + 0f, + 0f + ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Color/CrossChannelCurves/CrossChannelCurvesEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/Color/CrossChannelCurves/CrossChannelCurvesEffect.cs.uid new file mode 100644 index 0000000..af16715 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Color/CrossChannelCurves/CrossChannelCurvesEffect.cs.uid @@ -0,0 +1 @@ +uid://7dbnbfv4pdw diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Color/HDRMapping/HDRMappingEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Color/HDRMapping/HDRMappingEffect.cs new file mode 100644 index 0000000..7ff85f9 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Color/HDRMapping/HDRMappingEffect.cs @@ -0,0 +1,86 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class HDRMappingEffect:RDGraphCompositorEffect + { + public HDRMappingEffect():base() + { + Initialize(); + } + + [Export( PropertyHint.Range, "0,1") ] + public float amount = 0.5f; + + [Export] + public CurveTexture mapping = new CurveTexture(); + + [Export] + public float inputMaxmimum = 10; + + [Export] + public float outputMaximum = 10; + + [ExportGroup( "Luma Settings")] + [Export] + public Vector3 lumaWeights = new Vector3( 0.3f, 0.5f, 0.2f ); + + [Export] + public float lumaPower = 1; + + [Export] + public float lumaScale = 1; + + CEG_ScreenColorTexure screenColorTexture; + RG_ImageTexture _curvesTexture; + RG_HDRMapping _mapping; + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + _curvesTexture = new RG_ImageTexture( graph ); + _mapping = new RG_HDRMapping( graph ); + + + graph.InitializeNodes(); + + + _mapping.SetTextureSlotInputs( _curvesTexture, screenColorTexture ); + + _curvesTexture.SetImageTexture( mapping ); + + _mapping.input.sampler = context.Sampler( RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode.ClampToEdge ); + + graph.SetProcessOrder( + screenColorTexture, + _curvesTexture, + _mapping + ); + } + + + protected override void ForAllViews() + { + _curvesTexture.SetImageTexture( mapping ); + + _mapping.constants.Set( + inputMaxmimum, + lumaWeights.X, + lumaWeights.Y, + lumaWeights.Z, + + lumaPower, + lumaScale, + outputMaximum, + 0f + ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Color/HDRMapping/HDRMappingEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/Color/HDRMapping/HDRMappingEffect.cs.uid new file mode 100644 index 0000000..1f5c808 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Color/HDRMapping/HDRMappingEffect.cs.uid @@ -0,0 +1 @@ +uid://uwj67glvbmk4 diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Color/HSLCurves/HSLCurvesEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Color/HSLCurves/HSLCurvesEffect.cs new file mode 100644 index 0000000..d0e926b --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Color/HSLCurves/HSLCurvesEffect.cs @@ -0,0 +1,63 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class HSLCurvesEffect:RDGraphCompositorEffect + { + public HSLCurvesEffect():base() + { + Initialize(); + } + + [Export( PropertyHint.Range, "0,1") ] + public float amount = 0.5f; + + [Export] + public CurveXyzTexture curves = new CurveXyzTexture(); + + CEG_ScreenColorTexure screenColorTexture; + RG_ImageTexture _curvesTexture; + RG_HSLCurves _curves; + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + _curvesTexture = new RG_ImageTexture( graph ); + _curves = new RG_HSLCurves( graph ); + + + graph.InitializeNodes(); + + + _curves.SetTextureSlotInputs( screenColorTexture, screenColorTexture ); + _curves.SetCurvesTextureSlotInputs( _curvesTexture ); + + _curvesTexture.SetImageTexture( curves ); + + _curves.curves.sampler = context.Sampler( RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode.ClampToEdge ); + + graph.SetProcessOrder( + screenColorTexture, + _curves + ); + } + + + protected override void ForAllViews() + { + _curvesTexture.SetImageTexture( curves ); + + _curves.constants.Set( + + amount + ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Color/HSLCurves/HSLCurvesEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/Color/HSLCurves/HSLCurvesEffect.cs.uid new file mode 100644 index 0000000..eac3b0f --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Color/HSLCurves/HSLCurvesEffect.cs.uid @@ -0,0 +1 @@ +uid://v8yddy4erbru diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Color/RGBCurves/RGBCurvesEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Color/RGBCurves/RGBCurvesEffect.cs new file mode 100644 index 0000000..23ae583 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Color/RGBCurves/RGBCurvesEffect.cs @@ -0,0 +1,63 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class RGBCurvesEffect:RDGraphCompositorEffect + { + public RGBCurvesEffect():base() + { + Initialize(); + } + + [Export( PropertyHint.Range, "0,1") ] + public float amount = 0.5f; + + [Export] + public CurveXyzTexture curves = new CurveXyzTexture(); + + CEG_ScreenColorTexure screenColorTexture; + RG_ImageTexture _curvesTexture; + RG_RGBCurves _curves; + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + _curvesTexture = new RG_ImageTexture( graph ); + _curves = new RG_RGBCurves( graph ); + + + graph.InitializeNodes(); + + + _curves.SetTextureSlotInputs( screenColorTexture, screenColorTexture ); + _curves.SetCurvesTextureSlotInputs( _curvesTexture ); + + _curvesTexture.SetImageTexture( curves ); + + _curves.curves.sampler = context.Sampler( RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode.ClampToEdge ); + + graph.SetProcessOrder( + screenColorTexture, + _curves + ); + } + + + protected override void ForAllViews() + { + _curvesTexture.SetImageTexture( curves ); + + _curves.constants.Set( + + amount + ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Color/RGBCurves/RGBCurvesEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/Color/RGBCurves/RGBCurvesEffect.cs.uid new file mode 100644 index 0000000..0d9ae15 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Color/RGBCurves/RGBCurvesEffect.cs.uid @@ -0,0 +1 @@ +uid://bwobnip0unil2 diff --git a/Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingShader.glsl.import b/Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingShader.glsl.import deleted file mode 100644 index 1c0f3be..0000000 --- a/Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingShader.glsl.import +++ /dev/null @@ -1,14 +0,0 @@ -[remap] - -importer="glsl" -type="RDShaderFile" -uid="uid://us4n0un8oo2v" -path="res://.godot/imported/DepthAntiAliasingShader.glsl-51ad5443a76812922ed37cac7bc9291d.res" - -[deps] - -source_file="res://addons/rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingShader.glsl" -dest_files=["res://.godot/imported/DepthAntiAliasingShader.glsl-51ad5443a76812922ed37cac7bc9291d.res"] - -[params] - diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Distortion/EdgeDistortion/EdgeDistortionEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Distortion/EdgeDistortion/EdgeDistortionEffect.cs new file mode 100644 index 0000000..9818d12 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Distortion/EdgeDistortion/EdgeDistortionEffect.cs @@ -0,0 +1,113 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class EdgeDistortionEffect:RDGraphCompositorEffect + { + public EdgeDistortionEffect():base() + { + Initialize(); + } + + [Export( PropertyHint.Range, "0,0.5") ] + public float distortionAmount = 0.1f; + + [Export( PropertyHint.Range, "0,1") ] + public float blendAmount = 1f; + + [Export( PropertyHint.Range, "0,1") ] + public float horizontalAmount = 1f; + + [Export( PropertyHint.Range, "0,0.5") ] + public float horizontalEdge = 0.5f; + + [Export( PropertyHint.Range, "0,1") ] + public float horizontalEdgePower = 0.25f; + + [Export( PropertyHint.Range, "0,1") ] + public float verticalAmount = 1f; + + [Export( PropertyHint.Range, "0,0.5") ] + public float verticalEdge = 0.5f; + + [Export( PropertyHint.Range, "0,1") ] + public float verticalEdgePower = 0.25f; + + + [Export( PropertyHint.Range, "1,10") ] + public int smearingSteps = 5; + + [Export( PropertyHint.Range, "1,1.5") ] + public float smearing = 1.1f; + + [Export( PropertyHint.Range, "-1,1") ] + public float redShift = 0.1f; + + [Export( PropertyHint.Range, "-1,1") ] + public float greenShift = 0f; + + [Export( PropertyHint.Range, "-1,1") ] + public float blueShift = 0f; + + + CEG_ScreenColorTexure screenColorTexture; + CEG_BufferTexture bufferTexture; + + CEG_Copy copy; + RG_EdgeDistortion distortion; + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + bufferTexture = CEG_BufferTexture.ScreenSize( graph ); + + copy = new CEG_Copy( graph ); + distortion = new RG_EdgeDistortion( graph ); + graph.InitializeNodes(); + + copy.SetTextureSlotInputs( screenColorTexture, bufferTexture ); + distortion.SetTextureSlotInputs( copy.output, copy.input ); + + + + graph.SetProcessOrder( + screenColorTexture, + bufferTexture, + copy, + distortion + ); + + } + + + protected override void ForAllViews() + { + + distortion.constants.Set( + distortionAmount, + blendAmount, + horizontalEdge, + verticalEdge, + 1.0f + redShift, + 1.0f + greenShift, + 1.0f + blueShift, + (float) smearingSteps, + smearing, + Mathf.Pow( 10f, horizontalEdgePower ), + Mathf.Pow( 10f, verticalEdgePower ), + horizontalAmount, + verticalAmount, + 0f, + 0f, + 0f + ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Distortion/EdgeDistortion/EdgeDistortionEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/Distortion/EdgeDistortion/EdgeDistortionEffect.cs.uid new file mode 100644 index 0000000..8364143 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Distortion/EdgeDistortion/EdgeDistortionEffect.cs.uid @@ -0,0 +1 @@ +uid://be2v7ns5irml5 diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Distortion/TextureDistortion/TextureDistortionEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Distortion/TextureDistortion/TextureDistortionEffect.cs new file mode 100644 index 0000000..219d003 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Distortion/TextureDistortion/TextureDistortionEffect.cs @@ -0,0 +1,204 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class TextureDistortionEffect:RDGraphCompositorEffect + { + public TextureDistortionEffect():base() + { + Initialize(); + } + + + [ExportGroup("Main")] + [Export( PropertyHint.Range, "0,1") ] + public float distortionAmount = 0.1f; + + [Export( PropertyHint.Range, "0,1") ] + public float blendAmount = 1f; + + [Export( PropertyHint.Range, "1,5") ] + public int smearingSteps = 3; + + [Export( PropertyHint.Range, "1,1.5") ] + public float smearing = 1.1f; + + [Export( PropertyHint.Range, "-1,1") ] + public float redShift = 0.1f; + + [Export( PropertyHint.Range, "-1,1") ] + public float greenShift = 0f; + + [Export( PropertyHint.Range, "-1,1") ] + public float blueShift = 0f; + + [ExportGroup("Distortion Texture", "distortion")] + [Export] + public Texture2D distortionTexture; + + [Export] + public Vector2 distortionTiling = Vector2.One; + + [Export] + public Vector2 distortionOffset = Vector2.Zero; + + [Export] + public Vector2 distortionScroll = Vector2.Zero; + + [Export] + public TimeLine distortionScrollTimeLine; + + + [Export] + public RenderingDevice.SamplerFilter distortionFilter = RenderingDevice.SamplerFilter.Linear; + + [Export] + public RenderingDevice.SamplerRepeatMode distortionRepeatMode = RenderingDevice.SamplerRepeatMode.Repeat; + + [Export] + public ColorSpaceConversion distortionTextureConversion = ColorSpaceConversion.No_Conversion; + + [ExportGroup("Mask Texture", "mask")] + [Export] + public Texture2D maskTexture; + + [Export ] + public Vector2 maskTiling = Vector2.One; + + [Export ] + public Vector2 maskOffset = Vector2.Zero; + + [Export ] + public Vector2 maskScroll = Vector2.Zero; + + [Export] + public TimeLine maskScrollTimeLine; + + [Export] + public RenderingDevice.SamplerFilter maskFilter = RenderingDevice.SamplerFilter.Linear; + + [Export] + public RenderingDevice.SamplerRepeatMode maskRepeatMode = RenderingDevice.SamplerRepeatMode.Repeat; + + [Export] + public ColorSpaceConversion maskTextureConversion = ColorSpaceConversion.No_Conversion; + + CEG_ScreenColorTexure screenColorTexture; + CEG_BufferTexture bufferTexture; + RG_ImageTexture distortionTextureInput; + RG_ImageTexture maskTextureInput; + + CEG_Copy copy; + RD_TextureDistortion distortion; + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + bufferTexture = CEG_BufferTexture.ScreenSize( graph ); + distortionTextureInput = new RG_ImageTexture( graph ); + maskTextureInput = new RG_ImageTexture( graph ); + + copy = new CEG_Copy( graph ); + distortion = new RD_TextureDistortion( graph ); + + graph.InitializeNodes(); + + copy.SetTextureSlotInputs( screenColorTexture, bufferTexture ); + + distortion.SetTextureSlotInputs( copy.output, copy.input ); + distortion.SetDistortionTextureSlotInputs( distortionTextureInput, maskTextureInput ); + + distortion.distortion.sampler = context.Sampler( distortionFilter, distortionRepeatMode ); + distortion.mask.sampler = context.Sampler( maskFilter, maskRepeatMode ); + + distortionTextureInput.SetImageTexture( distortionTexture ); + maskTextureInput.SetImageTexture( maskTexture ); + + graph.SetProcessOrder( + screenColorTexture, + bufferTexture, + distortionTextureInput, + maskTextureInput, + + copy, + distortion + ); + + } + + RenderingDevice.SamplerFilter assignedfilterTop = RenderingDevice.SamplerFilter.Linear; + RenderingDevice.SamplerRepeatMode assignedRepeatModeTop = RenderingDevice.SamplerRepeatMode.Repeat; + + RenderingDevice.SamplerFilter assignedfilterMask = RenderingDevice.SamplerFilter.Linear; + RenderingDevice.SamplerRepeatMode assignedRepeatModeMask = RenderingDevice.SamplerRepeatMode.Repeat; + + + protected override void ForAllViews() + { + // RJLog.Log( "FOR ALL:", distortionTexture, maskTexture ); + + if ( assignedfilterTop != distortionFilter || assignedRepeatModeTop != distortionRepeatMode ) + { + assignedfilterTop = distortionFilter; + assignedRepeatModeTop = distortionRepeatMode; + + distortion.distortion.sampler = context.Sampler( assignedfilterTop, assignedRepeatModeTop ); + } + + if ( assignedfilterMask != maskFilter || assignedRepeatModeMask != maskRepeatMode ) + { + assignedfilterMask = maskFilter; + assignedRepeatModeMask = maskRepeatMode; + + distortion.mask.sampler = context.Sampler( assignedfilterMask, assignedRepeatModeMask ); + } + + distortionTextureInput.SetImageTexture( distortionTexture ); + maskTextureInput.SetImageTexture( maskTexture ); + + // RJLog.Log( + // distortionTextureInput.GetTexture(), distortionTexture, + // maskTextureInput.GetTexture(), maskTexture + // ); + + var timeLine = TimeLineManager.Ensure( distortionScrollTimeLine ); + var scrollPosition = timeLine.position * distortionScroll; + scrollPosition.X = MathX.Repeat( scrollPosition.X, 1.0f ); + scrollPosition.Y = MathX.Repeat( scrollPosition.Y, 1.0f ); + + var timeLineMask = TimeLineManager.Ensure( maskScrollTimeLine ); + var scrollPositionMask = timeLineMask.position * maskScroll; + scrollPositionMask.X = MathX.Repeat( scrollPositionMask.X, 1.0f ); + scrollPositionMask.Y = MathX.Repeat( scrollPositionMask.Y, 1.0f ); + + distortion.constants.Set( + distortionTiling.ToVector4( distortionOffset + scrollPosition ), + maskTiling.ToVector4( maskOffset + scrollPositionMask ), + Vector4.Zero, + Vector4.Zero, + + distortionAmount, + blendAmount, + 1.0f + redShift, + 1.0f + greenShift, + + 1.0f + blueShift, + (float) smearingSteps, + smearing, + (float)(int)distortionTextureConversion, + (float)(int)maskTextureConversion, + 0f, + 0f, + 0f + + ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Distortion/TextureDistortion/TextureDistortionEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/Distortion/TextureDistortion/TextureDistortionEffect.cs.uid new file mode 100644 index 0000000..62a3df5 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Distortion/TextureDistortion/TextureDistortionEffect.cs.uid @@ -0,0 +1 @@ +uid://balixgskgouhm diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Glow/ChromaticBloom/ChromaticBloomEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Glow/ChromaticBloom/ChromaticBloomEffect.cs new file mode 100644 index 0000000..1ab4009 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Glow/ChromaticBloom/ChromaticBloomEffect.cs @@ -0,0 +1,245 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class ChromaticBloomEffect:RDGraphCompositorEffect + { + public ChromaticBloomEffect():base() + { + Initialize(); + } + + [ExportGroup( "Main")] + [Export( PropertyHint.Range, "0,1") ] + public float amount = 0.5f; + + [Export( PropertyHint.Range, "1,10") ] + public int num = 2; + + [ExportGroup( "Distortion")] + + [Export( PropertyHint.Range, "0,1") ] + public float distortionAmount = 0.5f; + + [Export( PropertyHint.Range, "0,360") ] + public float distortionAngle = 0.5f; + + [Export( PropertyHint.Range, "0,360") ] + public float distortionAngleSpeed = 0.5f; + + [Export] + public TimeLine distortionAngleTimeLine; + + [Export( PropertyHint.Range, "-1,1") ] + public Vector2 distortionOffset = Vector2.Zero; + + [ExportGroup( "Smearing")] + [Export( PropertyHint.Range, "1,32") ] + public int smearingSteps = 5; + + [Export( PropertyHint.Range, "1,1.5") ] + public float smearing = 1.1f; + + [Export( PropertyHint.Range, "-1,1") ] + public float redShift = 0.1f; + + [Export( PropertyHint.Range, "-1,1") ] + public float greenShift = 0f; + + [Export( PropertyHint.Range, "-1,1") ] + public float blueShift = 0f; + + [ExportGroup( "Luma")] + [Export] + public Color lumaTint = Colors.White; + + [Export] + public Vector3 lumaWeights = new Vector3( 0.3f, 0.5f, 0.2f ); + + [Export] + public float lumaWeightPower =1f; + + [Export] + public Vector2 lumaInputRange = new Vector2( 0.5f, 1.5f ); + + [Export] + public float lumaNormalizationPower = 1f; + + [Export] + public Vector2 lumaOutputRange = new Vector2( 0f, 1.5f ); + + [Export] + public float desaturation = 1f; + + + int _downSampling = 16; + + public enum DownSampling + { + _1x_, + _2x_, + _4x_, + _8x_, + _16x_, + _32x_ + } + + public int downSamplingRate => Mathf.RoundToInt( Mathf.Pow( 2, (int) downSampling ) ); + + [Export] + public DownSampling downSampling = DownSampling._4x_; + + + CEG_ScreenColorTexure screenColorTexture; + CEG_BufferTexture bufferTexture; + + RG_Resize downScale; + + RG_ExtractGlow extractGlow; + + int maxBlooms = 10; + + + List _blooms = []; + + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + bufferTexture = CEG_BufferTexture.ScreenSize( graph, Vector2.One / (float) _downSampling ); + + downScale = new RG_Resize( graph ); + extractGlow = new RG_ExtractGlow( graph ); + + // bloom = new RG_ChromaticBloom( graph ); + // bloom2 = new RG_ChromaticBloom( graph ); + // bloom3 = new RG_ChromaticBloom( graph ); + // bloom4 = new RG_ChromaticBloom( graph ); + + // _blooms = [ bloom, bloom2, bloom3, bloom4 ]; + + _blooms = new List(); + + for ( int i = 0; i < maxBlooms; i++ ) + { + var b = new RG_ChromaticBloom( graph ); + _blooms.Add( b ); + } + + graph.InitializeNodes(); + + downScale.SetTextureSlotInputs( screenColorTexture, bufferTexture ); + downScale.input.UseSampler(); + + extractGlow.SetTextureSlotInputs( screenColorTexture, bufferTexture ); + extractGlow.input.UseSampler(); + + _blooms.ForEach( + ( b )=> + { + b.SetTextureSlotInputs( bufferTexture, screenColorTexture ); + b.input.UseSampler(); + } + ); + + graph.SetProcessOrder( + screenColorTexture, + bufferTexture, + extractGlow + ); + + } + + int _lastNum = -1; + + protected override void ForAllViews() + { + if ( downSamplingRate != _downSampling ) + { + _downSampling = downSamplingRate; + ( bufferTexture.GetCreator() as CEG_TextureCreator_ScreenSize ).scale = Vector2.One / (float) _downSampling; + } + + downScale.SetCustomComputeSize( context.internalSize / _downSampling ); + + extractGlow.SetCustomComputeSize( context.internalSize / _downSampling ); + + extractGlow.constants.Set( + lumaWeights.X, + lumaWeights.Y, + lumaWeights.Z, + lumaWeightPower, + + lumaInputRange.X, + lumaInputRange.Y, + lumaNormalizationPower, + lumaOutputRange.X, + + lumaOutputRange.Y, + desaturation, + lumaTint.R, + lumaTint.G, + + lumaTint.B, + 0f, + 0f, + 0f + ); + + if ( _lastNum != num ) + { + _lastNum = num; + + var list = new List(){ + screenColorTexture, + bufferTexture, + extractGlow + }; + + for ( int i = 0; i < num; i++ ) + { + list.Add( _blooms[ i ] ); + } + + graph.SetProcessOrder( list.ToArray() ); + } + + var combinedRotation = distortionAngle; + + var tl = TimeLineManager.Ensure( distortionAngleTimeLine ); + var animationRotation = MathX.Repeat( tl.position * distortionAngleSpeed / 360, 1f ) * 360f; + combinedRotation = MathX.Repeat( animationRotation + combinedRotation, 360f ); + + + for ( int i = 0; i < num; i++ ) + { + float angleOffset = 180f / (float) num; + + _blooms[ i ].constants.Set( + amount, + 1.0f + redShift, + 1.0f + greenShift, + 1.0f + blueShift, + + (float) smearingSteps, + smearing, + distortionAmount, + ( combinedRotation + i * angleOffset ) / 180f * Mathf.Pi, + + distortionOffset.X, + distortionOffset.Y, + 0f, + 0f + ); + } + + + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Glow/ChromaticBloom/ChromaticBloomEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/Glow/ChromaticBloom/ChromaticBloomEffect.cs.uid new file mode 100644 index 0000000..a07d9a2 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Glow/ChromaticBloom/ChromaticBloomEffect.cs.uid @@ -0,0 +1 @@ +uid://6jkixa201wux diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Glow/Streaks/StreaksEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Glow/Streaks/StreaksEffect.cs new file mode 100644 index 0000000..ed4a1f4 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Glow/Streaks/StreaksEffect.cs @@ -0,0 +1,213 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class StreaksEffect:RDGraphCompositorEffect + { + public StreaksEffect():base() + { + Initialize(); + } + + [Export( PropertyHint.Range, "0,1") ] + public float intensity = 0.5f; + + [Export( PropertyHint.Range, "0,1") ] + public float intensityScale = 0.1f; + + [Export( PropertyHint.Range, "0,1") ] + public float amount = 0.1f; + + [Export ] + public Vector2 direction = new Vector2( 1f, 0f ); + + [Export( PropertyHint.Range, "-360,360") ] + public float rotationOffset = 0; + + [Export( PropertyHint.Range, "-360,360") ] + public float rotationSpeed = 0; + + [Export] + public TimeLine rotationSpeedTimeLine; + + [Export( PropertyHint.Range, "1,8") ] + public int numStreaks = 3; + + [Export( PropertyHint.Range, "0,1") ] + public float attenuation = 0.5f; + + [Export( PropertyHint.Range, "0,5") ] + public float lumaTreshold = 1.0f; + + [Export( PropertyHint.Range, "-1,1") ] + public float lumaScale5 = 0f; + + [Export( PropertyHint.Range, "1,12") ] + public int samples = 2; + + [Export( PropertyHint.Range, "0,1") ] + public float desaturation = 0.5f; + + [Export( PropertyHint.Range, "1,5") ] + public int blurRadius = 1; + + [Export( PropertyHint.Range, "1,10") ] + public int blurSpread = 1; + + [Export( PropertyHint.Range, "0,10") ] + public float blurNoise = 1; + + public enum DownSampling + { + _1x_, + _2x_, + _4x_, + _8x_, + _16x_, + _32x_ + } + + public int downSamplingRate => Mathf.RoundToInt( Mathf.Pow( 2, (int) downSampling ) ); + + [Export] + public DownSampling downSampling = DownSampling._4x_; + + CEG_ScreenColorTexure screenColorTexture; + CEG_BufferTexture bufferTexture; + CEG_BufferTexture bufferTexture2; + + RG_Resize downScale; + CEG_Copy copy; + + RG_GlowAdd upScale; + + RG_Streaks streaks1; + RG_Streaks streaks2; + RG_Streaks streaks3; + + List _streaks; + + int _downSampling = 16; + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + bufferTexture = CEG_BufferTexture.ScreenSize( graph, Vector2.One / (float) _downSampling ); + bufferTexture2 = CEG_BufferTexture.ScreenSize( graph, Vector2.One / (float) _downSampling ); + + downScale = new RG_Resize( graph ); + upScale = new RG_GlowAdd( graph ); + + copy = new CEG_Copy( graph ); + + streaks1 = new RG_Streaks( graph ); + streaks2 = new RG_Streaks( graph ); + streaks3 = new RG_Streaks( graph ); + + _streaks = + [ + streaks1, + streaks2, + streaks3 + ]; + + graph.InitializeNodes(); + + downScale.SetTextureSlotInputs( screenColorTexture, bufferTexture ); + downScale.input.UseSampler(); + + copy.SetTextureSlotInputs( bufferTexture, bufferTexture2 ); + + streaks1.SetTextureSlotInputs( bufferTexture, bufferTexture2 ); + streaks1.input.UseSampler(); + + streaks2.SetTextureSlotInputs( bufferTexture2, bufferTexture ); + streaks2.input.UseSampler(); + + streaks3.SetTextureSlotInputs( bufferTexture, bufferTexture2 ); + streaks3.input.UseSampler(); + + upScale.SetTextureSlotInputs( bufferTexture2, screenColorTexture ); + upScale.input.UseSampler(); + + + graph.SetProcessOrder( + screenColorTexture, + bufferTexture, + bufferTexture2, + + downScale, + + copy, + + streaks1, + streaks2, + streaks3, + + upScale + ); + + } + + + protected override void ForAllViews() + { + if ( downSamplingRate != _downSampling ) + { + _downSampling = downSamplingRate; + ( bufferTexture.GetCreator() as CEG_TextureCreator_ScreenSize ).scale = Vector2.One / (float) _downSampling; + ( bufferTexture2.GetCreator() as CEG_TextureCreator_ScreenSize ).scale = Vector2.One / (float) _downSampling; + } + + downScale.SetCustomComputeSize( context.internalSize / _downSampling ); + copy.SetCustomComputeSize( context.internalSize / _downSampling ); + + var iteration = 0; + var lumaScale = Mathf.Pow( 5f, lumaScale5 ); + + var combinedRotation = rotationOffset; + + var tl = TimeLineManager.Ensure( rotationSpeedTimeLine ); + var animationRotation = MathX.Repeat( tl.position * rotationSpeed / 360, 1f ) * 360f; + combinedRotation = MathX.Repeat( animationRotation + combinedRotation, 360f ); + + _streaks.ForEach( + ( s )=> + { + s.SetCustomComputeSize( context.internalSize / _downSampling ); + + s.constants.Set( + direction, + new Vector2( attenuation, amount ), + new Vector2( samples, iteration ), + new Vector2( lumaTreshold, lumaScale ), + new Vector2( numStreaks, blurRadius ), + new Vector2( combinedRotation / 180 * Mathf.Pi, desaturation ) + ); + + iteration++; + } + ); + + upScale.constants.Set( + intensity * intensityScale, + blurNoise, + (float)blurSpread, + (float)blurRadius, + + lumaTreshold, + lumaScale, + 0f, + 0f + ); + + + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Glow/Streaks/StreaksEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/Glow/Streaks/StreaksEffect.cs.uid new file mode 100644 index 0000000..6c6732c --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Glow/Streaks/StreaksEffect.cs.uid @@ -0,0 +1 @@ +uid://duvytqqnfwvf6 diff --git a/Runtime/Rendering/Compositor/CompositorEffects/HSLAdjustment/HSLAdjustmentEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/HSLAdjustment/HSLAdjustmentEffect.cs index 09ca7c1..7f6f92d 100644 --- a/Runtime/Rendering/Compositor/CompositorEffects/HSLAdjustment/HSLAdjustmentEffect.cs +++ b/Runtime/Rendering/Compositor/CompositorEffects/HSLAdjustment/HSLAdjustmentEffect.cs @@ -79,8 +79,8 @@ namespace Rokojori amount, MathX.Repeat( hueShift, 360 ) / 360f, temparatureShift, - saturationOffset / 100f, Mathf.Pow( 5f, saturationGamma / 100f ), - lightnessOffset / 100f, Mathf.Pow( 5f, lightnessGamma / 100f ), + ( saturationOffset ) / 100f, Mathf.Pow( 5f, saturationGamma / 100f ), + ( lightnessOffset) / 100f, Mathf.Pow( 5f, lightnessGamma / 100f ), (float)(int)hslConversionMode, diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Noise/ChannelPixelation/ChannelPixelationEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Noise/ChannelPixelation/ChannelPixelationEffect.cs new file mode 100644 index 0000000..f246554 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Noise/ChannelPixelation/ChannelPixelationEffect.cs @@ -0,0 +1,122 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class ChannelPixelationEffect:RDGraphCompositorEffect + { + public ChannelPixelationEffect():base() + { + Initialize(); + } + + [Export( PropertyHint.Range, "0,1") ] + public float amount = 0.1f; + + [Export( PropertyHint.Range, "1,2000") ] + public int pixelSizeX = 3; + + [Export( PropertyHint.Range, "1,2000") ] + public int pixelSizeY = 3; + + [Export( PropertyHint.Range, "0,1") ] + public float pixelOffsetX = 0.5f; + + [Export( PropertyHint.Range, "0,1") ] + public float pixelOffsetY = 0.5f; + + public enum Channel + { + Red, + Green, + Blue, + Hue, + Saturation, + Lightness, + RGB + } + + [Export] + public Channel targetChannel; + + [Export( PropertyHint.Range, "0,1") ] + public float noiseAmount = 0.1f; + + [Export( PropertyHint.Range, "0.01,100") ] + public float noiseScale = 3; + + [Export] + public Vector3 xU = new Vector3( 0f, 0f, 0f ); + + [Export] + public Vector3 xV = new Vector3( 0f, 0f, 0f ); + + [Export] + public Vector3 yU = new Vector3( 0f, 0f, 0f ); + + [Export] + public Vector3 yV = new Vector3( 0f, 0f, 0f ); + + + + CEG_ScreenColorTexure screenColorTexture; + CEG_BufferTexture bufferTexture; + + CEG_Copy copy; + RG_ChannelPixelation pixelation; + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + bufferTexture = CEG_BufferTexture.ScreenSize( graph ); + + copy = new CEG_Copy( graph ); + pixelation = new RG_ChannelPixelation( graph ); + graph.InitializeNodes(); + + copy.SetTextureSlotInputs( screenColorTexture, bufferTexture ); + pixelation.SetTextureSlotInputs( copy.output, copy.input ); + + + + graph.SetProcessOrder( + screenColorTexture, + bufferTexture, + copy, + pixelation + ); + + } + + + protected override void ForAllViews() + { + var time = TimeLine.osTime; + + pixelation.constants.Set( + new Vector4( + xU.X + Mathf.Sin( xU.Y * time ) * xU.Z, + xV.X + Mathf.Sin( xV.Y * time ) * xV.Z, + yU.X + Mathf.Sin( yU.Y * time ) * yU.Z, + yV.X + Mathf.Sin( yV.Y * time ) * yV.Z + ), + + (float)pixelSizeX, + (float)pixelSizeY, + amount, + (float)(int)targetChannel, + + noiseAmount, + noiseScale, + pixelOffsetX, + pixelOffsetY + ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Noise/ChannelPixelation/ChannelPixelationEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/Noise/ChannelPixelation/ChannelPixelationEffect.cs.uid new file mode 100644 index 0000000..04c493f --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/Noise/ChannelPixelation/ChannelPixelationEffect.cs.uid @@ -0,0 +1 @@ +uid://lytit04mgc2d diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TextureDilation/TextureDilationCompositerEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/TextureDilation/TextureDilationCompositerEffect.cs index 1133b7d..a619ba8 100644 --- a/Runtime/Rendering/Compositor/CompositorEffects/TextureDilation/TextureDilationCompositerEffect.cs +++ b/Runtime/Rendering/Compositor/CompositorEffects/TextureDilation/TextureDilationCompositerEffect.cs @@ -11,7 +11,7 @@ namespace Rokojori { [Tool] [GlobalClass] - public partial class TextureDilationCompositerEffect:RDGraphCompositorEffect + public abstract partial class TextureDilationCompositerEffect:RDGraphCompositorEffect { } diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TextureOverlay/TextureOverlayEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/TextureOverlay/TextureOverlayEffect.cs new file mode 100644 index 0000000..fcf86c8 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TextureOverlay/TextureOverlayEffect.cs @@ -0,0 +1,208 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class TextureOverlayEffect:RDGraphCompositorEffect + { + public TextureOverlayEffect():base() + { + Initialize(); + } + + [ExportGroup("All")] + [Export( PropertyHint.Range, "0,1")] + public float opacity = 1f; + + [Export] + public RG_BlendModeType blendMode = RG_BlendModeType.Alpha; + + [ExportGroup("Overlay")] + + [Export] + public Texture2D overlayTexture; + + [Export] + public Color overlayTint = Colors.White; + + [Export] + public ColorSpaceConversion overlayConversion = ColorSpaceConversion.sRGB_to_Linear; + + [Export] + public Vector2 tiling = Vector2.One; + + [Export] + public Vector2 offset = Vector2.Zero; + + [Export] + public Vector2 scrolling = Vector2.Zero; + + [Export] + public TimeLine scrollTimeline; + + [Export] + public RenderingDevice.SamplerFilter filter = RenderingDevice.SamplerFilter.Linear; + + [Export] + public RenderingDevice.SamplerRepeatMode repeatMode = RenderingDevice.SamplerRepeatMode.Repeat; + + [ExportGroup("Mask")] + [Export] + public Texture2D maskTexture; + + [Export] + public ColorSpaceConversion maskOverlayConversion = ColorSpaceConversion.sRGB_to_Linear; + + + [Export] + public Vector2 maskTiling = Vector2.One; + + [Export] + public Vector2 maskOffset = Vector2.Zero; + + [Export] + public Vector2 maskScrolling = Vector2.Zero; + + [Export] + public TimeLine maskScrollTimeline; + + [Export] + public RenderingDevice.SamplerFilter maskFilter = RenderingDevice.SamplerFilter.Linear; + + [Export] + public RenderingDevice.SamplerRepeatMode maskRepeatMode = RenderingDevice.SamplerRepeatMode.Repeat; + + [ExportGroup("Advanced")] + [Export] + public ColorSpaceConversion screenConversion = ColorSpaceConversion.No_Conversion; + + [Export] + public ColorSpaceConversion outputConversion = ColorSpaceConversion.No_Conversion; + + RG_ImageTexture _topTexture; + RG_ImageTexture _maskTexture; + CEG_ScreenColorTexure _bottomTexture; + CEG_ScreenColorTexure _outputTexture; + + + List _blendModes; + + RenderingDevice.SamplerFilter assignedfilterTop = RenderingDevice.SamplerFilter.Linear; + RenderingDevice.SamplerRepeatMode assignedRepeatModeTop = RenderingDevice.SamplerRepeatMode.Repeat; + + RenderingDevice.SamplerFilter assignedfilterMask = RenderingDevice.SamplerFilter.Linear; + RenderingDevice.SamplerRepeatMode assignedRepeatModeMask = RenderingDevice.SamplerRepeatMode.Repeat; + + RG_BlendModeType _assignBlendMode = RG_BlendModeType.Alpha; + + void Initialize() + { + _topTexture = new RG_ImageTexture( graph ); + _maskTexture = new RG_ImageTexture( graph ); + _bottomTexture = new CEG_ScreenColorTexure( graph ); + _outputTexture = new CEG_ScreenColorTexure( graph ); + + _blendModes = RG_BlendModesTool.CreateAll( graph ); + + graph.InitializeNodes(); + + _blendModes.ForEach( + ( bm )=> + { + bm.SetTextureSlotInputs( _topTexture, _maskTexture, _bottomTexture, _outputTexture ); + + bm.top.sampler = context.Sampler( assignedfilterTop, assignedRepeatModeTop ); + bm.mask.sampler = context.Sampler( assignedfilterMask, assignedRepeatModeMask ); + bm.bottom.sampler = context.Sampler( RenderingDevice.SamplerFilter.Nearest, RenderingDevice.SamplerRepeatMode.ClampToEdge ); + + } + ); + + _assignBlendMode = blendMode; + + graph.SetProcessOrder( + _topTexture, + _maskTexture, + _bottomTexture, + _outputTexture, + RG_BlendModesTool.GetCurrentBlendMode( _blendModes, _assignBlendMode ) + ); + + } + + + + protected override void ForAllViews() + { + if ( _assignBlendMode != blendMode ) + { + _assignBlendMode = blendMode; + + var nextBlendMode = RG_BlendModesTool.GetCurrentBlendMode( _blendModes, _assignBlendMode ); + graph.SetProcessOrder( + _topTexture, + _maskTexture, + _bottomTexture, + _outputTexture, + RG_BlendModesTool.GetCurrentBlendMode( _blendModes, _assignBlendMode ) + ); + + nextBlendMode.top.sampler = context.Sampler( assignedfilterTop, assignedRepeatModeTop ); + nextBlendMode.mask.sampler = context.Sampler( assignedfilterMask, assignedRepeatModeMask ); + } + + var currentBlendMode = RG_BlendModesTool.GetCurrentBlendMode( _blendModes, blendMode ); + + if ( assignedfilterTop != filter || assignedRepeatModeTop != repeatMode ) + { + assignedfilterTop = filter; + assignedRepeatModeTop = repeatMode; + + currentBlendMode.top.sampler = context.Sampler( assignedfilterTop, assignedRepeatModeTop ); + } + + if ( assignedfilterMask != maskFilter || assignedRepeatModeMask != maskRepeatMode ) + { + assignedfilterMask = maskFilter; + assignedRepeatModeMask = maskRepeatMode; + + currentBlendMode.mask.sampler = context.Sampler( assignedfilterMask, assignedRepeatModeMask ); + } + + _topTexture.SetImageTexture( overlayTexture ); + _maskTexture.SetImageTexture( maskTexture ); + + var timeLine = TimeLineManager.Ensure( scrollTimeline ); + var scrollPosition = timeLine.position * scrolling; + scrollPosition.X = MathX.Repeat( scrollPosition.X, 1.0f ); + scrollPosition.Y = MathX.Repeat( scrollPosition.Y, 1.0f ); + + var timeLineMask = TimeLineManager.Ensure( maskScrollTimeline ); + var scrollPositionMask = timeLineMask.position * maskScrolling; + scrollPositionMask.X = MathX.Repeat( scrollPositionMask.X, 1.0f ); + scrollPositionMask.Y = MathX.Repeat( scrollPositionMask.Y, 1.0f ); + + currentBlendMode.constants.Set( + [ + new Vector4( tiling.X, tiling.Y, offset.X + scrollPosition.X, offset.Y + scrollPosition.Y ), + new Vector4( maskTiling.X, maskTiling.Y, maskOffset.X + scrollPositionMask.X, maskOffset.Y + scrollPositionMask.Y ), + new Vector4( 1f, 1f, 0f, 0f ), + overlayTint, + opacity, + (float)(int)overlayConversion, + (float)(int)maskOverlayConversion, + (float)(int)screenConversion, + (float)(int)outputConversion, + 1f + ] + ); + + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TextureOverlay/TextureOverlayEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/TextureOverlay/TextureOverlayEffect.cs.uid new file mode 100644 index 0000000..70d8eb2 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TextureOverlay/TextureOverlayEffect.cs.uid @@ -0,0 +1 @@ +uid://t5g1g1uv5yrj diff --git a/Runtime/Rendering/Compositor/RokojoriCompositorEffect.cs b/Runtime/Rendering/Compositor/RokojoriCompositorEffect.cs index b265ffa..b10763c 100644 --- a/Runtime/Rendering/Compositor/RokojoriCompositorEffect.cs +++ b/Runtime/Rendering/Compositor/RokojoriCompositorEffect.cs @@ -8,6 +8,10 @@ namespace Rokojori [GlobalClass] public abstract partial class RokojoriCompositorEffect:CompositorEffect { + [ExportGroup("Debug")] + [Export] + public RokojoriCompositorEffectID compositorEffectID; + [ExportToolButton( "Clear Caches" )] public Callable clearCachesButton => Callable.From( ()=> ClearCaches() ); diff --git a/Runtime/Rendering/Compositor/SetCompositorEffectsStates.cs b/Runtime/Rendering/Compositor/SetCompositorEffectsStates.cs new file mode 100644 index 0000000..783b4c1 --- /dev/null +++ b/Runtime/Rendering/Compositor/SetCompositorEffectsStates.cs @@ -0,0 +1,47 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class SetCompositorEffectsStates:Action + { + [Export] + public CompositorEffectReference[] compositorEffectReferences = []; + + public enum ChangeMode + { + Set_Enabled, + Set_Disabled, + Toggle + } + + [Export] + public ChangeMode mode = ChangeMode.Set_Disabled; + + protected override void _OnTrigger() + { + if ( compositorEffectReferences == null ) + { + return; + } + + compositorEffectReferences.ForEach( + ( cr )=> + { + if ( cr == null ) + { + return; + } + + var c = cr.GetCompositorEffect( this ); + + var settingMode = mode == ChangeMode.Toggle ? ! c.Enabled : ( ChangeMode.Set_Enabled == mode ); + c.Enabled = settingMode; + } + ); + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/SetCompositorEffectsStates.cs.uid b/Runtime/Rendering/Compositor/SetCompositorEffectsStates.cs.uid new file mode 100644 index 0000000..5e977c7 --- /dev/null +++ b/Runtime/Rendering/Compositor/SetCompositorEffectsStates.cs.uid @@ -0,0 +1 @@ +uid://ndhbl08jwmg1 diff --git a/Runtime/Rendering/Context/RDContext.Create.cs b/Runtime/Rendering/Context/RDContext.Create.cs index 4efb384..49a404b 100644 --- a/Runtime/Rendering/Context/RDContext.Create.cs +++ b/Runtime/Rendering/Context/RDContext.Create.cs @@ -6,7 +6,7 @@ namespace Rokojori { public partial class RDContext { - public RDSampler Sampler( RDSamplerState state = null) + public RDSampler Sampler( RDSamplerState state ) { if ( state == null ) { @@ -21,7 +21,7 @@ namespace Rokojori return sampler; } - public RDSampler Sampler( RenderingDevice.SamplerFilter filter, RenderingDevice.SamplerRepeatMode repeatMode) + public RDSampler Sampler( RenderingDevice.SamplerFilter filter = RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode repeatMode = RenderingDevice.SamplerRepeatMode.Repeat ) { var state = new RDSamplerState(); @@ -34,5 +34,6 @@ namespace Rokojori return Sampler( state ); } + } } \ No newline at end of file diff --git a/Runtime/Rendering/Context/RDContext.cs b/Runtime/Rendering/Context/RDContext.cs index 7aaca19..7a7ea0a 100644 --- a/Runtime/Rendering/Context/RDContext.cs +++ b/Runtime/Rendering/Context/RDContext.cs @@ -200,8 +200,17 @@ namespace Rokojori public Vector2I computeSize = new Vector2I( 512, 512 ); + public bool useFixedComputeSize = false; + + + public Vector2I GetComputeSize() { + if ( useFixedComputeSize ) + { + return computeSize; + } + if ( _sceneBuffers != null ) { return _sceneBuffers.GetInternalSize(); diff --git a/Runtime/Rendering/Objects/RDUniformSet.cs b/Runtime/Rendering/Objects/RDUniformSet.cs index 1691b16..2c7208a 100644 --- a/Runtime/Rendering/Objects/RDUniformSet.cs +++ b/Runtime/Rendering/Objects/RDUniformSet.cs @@ -11,14 +11,14 @@ namespace Rokojori public RDUniformSet( RDContext effect, int setIndex, Rid rid ):base( effect, rid ) { - _setIndex =setIndex; + _setIndex = setIndex; } - public static RDUniformSet Image( RDContext context, RDTexture texture, int setIndex ) + public static RDUniformSet Image( RDContext context, RDTexture texture, int setIndex, int binding = 0 ) { var uniform = new RDUniform(); uniform.UniformType = RenderingDevice.UniformType.Image; - uniform.Binding = 0; + uniform.Binding = binding; uniform.AddId( texture.rid ); @@ -29,11 +29,11 @@ namespace Rokojori return new RDUniformSet( context, setIndex, rid ); } - public static RDUniformSet Sampler( RDContext context, RDSampler sampler, RDTexture texture, int setIndex ) + public static RDUniformSet Sampler( RDContext context, RDSampler sampler, RDTexture texture, int setIndex, int binding = 0 ) { var uniform = new RDUniform(); uniform.UniformType = RenderingDevice.UniformType.SamplerWithTexture; - uniform.Binding = 0; + uniform.Binding = binding; uniform.AddId( sampler.rid ); uniform.AddId( texture.rid ) ; diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/DAA.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/DAA.glsl new file mode 100644 index 0000000..72afa98 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/DAA.glsl @@ -0,0 +1,87 @@ +#[compute] +#version 450 + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( set = 0, binding = 0 ) +uniform sampler2D depthSampler; + +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + + +layout( push_constant, std430 ) +uniform Parameters +{ + float amount; + float edgeThreshold; + float edgeIntensity; + float blurMix; + + float blurType; + float spread; + int pad; + int pad2; + +} parameters; + +float sampleDepth( ivec2 xy, vec2 pixelSize ) +{ + vec2 uv = ( vec2( xy ) + 0.5 ) * pixelSize; + return texture( depthSampler, uv ).r; +} + +void main( ) +{ + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + ivec2 size = imageSize( outputImage ); + + if ( xy.x >= size.x || xy.y >= size.y ) + { + return; + } + + vec2 pixelSize = vec2( 1.0 ) / vec2( size ); + + float centerDepth = sampleDepth( xy, pixelSize ); + + float topLeft = sampleDepth( xy + ivec2( -1, -1 ), pixelSize ); + float top = sampleDepth( xy + ivec2( 0, -1 ), pixelSize ); + float topRight = sampleDepth( xy + ivec2( 1, -1 ), pixelSize ); + + float left = sampleDepth( xy + ivec2( -1, 0 ), pixelSize ); + float right = sampleDepth( xy + ivec2( 1, 0 ), pixelSize ); + + float bottomLeft = sampleDepth( xy + ivec2( -1, 1 ), pixelSize ); + float bottom = sampleDepth( xy + ivec2( 0, 1 ), pixelSize ); + float bottomRight = sampleDepth( xy + ivec2( 1, 1 ), pixelSize ); + + + float gx = -topLeft - 2.0 * left - bottomLeft + topRight + 2.0 * right + bottomRight; + float gy = -topLeft - 2.0 * top - topRight + bottomLeft + 2.0 * bottom + bottomRight; + + + float edge = length( vec2( gx, gy ) ); + edge = ( edge - parameters.edgeThreshold ) * parameters.edgeIntensity; + edge = clamp( edge, 0.0, 1.0 ); + + + vec4 color = imageLoad( outputImage, xy ); + + int spread = int( parameters.spread ); + vec4 color0 = imageLoad( outputImage, xy + ivec2( -1, 0 ) * spread ); + vec4 color1 = imageLoad( outputImage, xy + ivec2( 1, 0 ) * spread ); + + ivec2 dir2 = int( parameters.blurType ) == 0 ? ivec2( 2, 0 ) : ivec2( 0, 1 ); + + vec4 color2 = imageLoad( outputImage, xy - dir2 * spread ); + vec4 color3 = imageLoad( outputImage, xy + dir2 * spread ); + + vec4 blurColor = 0.35 * ( color0 + color1 ) + ( color2 + color3 ) * 0.15; + + vec4 smoothedColor = mix( color, blurColor, parameters.blurMix ); + + color.rgb = mix( color.rgb, smoothedColor.rgb, edge * parameters.amount ); + + imageStore( outputImage, xy, color ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/DAA.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/DAA.glsl.import new file mode 100644 index 0000000..ca6b389 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/DAA.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://d1k1ht3v6vifm" +path="res://.godot/imported/DAA.glsl-751e497645ace7b9b9009529d035728d.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/DAA.glsl" +dest_files=["res://.godot/imported/DAA.glsl-751e497645ace7b9b9009529d035728d.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/RG_DAA.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/RG_DAA.cs new file mode 100644 index 0000000..e4027e1 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/RG_DAA.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_DAA:CEG_ImageProcessor + { + + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/AntiAliasing/DAA/DAA.glsl" ); + + public RG_DAA( RDGraph graph ):base( graph, shaderPath ){} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/RG_DAA.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/RG_DAA.cs.uid new file mode 100644 index 0000000..71dd4cf --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/DAA/RG_DAA.cs.uid @@ -0,0 +1 @@ +uid://cbfamydf7cioe diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/FXAA.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/FXAA.glsl new file mode 100644 index 0000000..7a92d6e --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/FXAA.glsl @@ -0,0 +1,213 @@ +#[compute] +#version 450 + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + + +layout( set = 0, binding = 0 ) +uniform sampler2D sourceColor; + +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + +layout( push_constant, std430 ) +uniform Parameters +{ + float luminance_multiplier; + float exposure; + float amount; + float pad1; + +} parameters; + + +float QUALITY( float q ) +{ + return ( q < 5 ? 1.0 : ( q > 5 ? ( q < 10 ? 2.0 : ( q < 11 ? 4.0 : 8.0 ) ) : 1.5 ) ); +} + +float rgb2luma( vec3 rgb ) +{ + return sqrt( dot( rgb, vec3( 0.299, 0.587, 0.114 ) ) ); +} + +vec3 applyFXAA( vec3 color, float exposure, vec2 uv_interp, vec2 pixel_size ) +{ + const float EDGE_THRESHOLD_MIN = 0.0312; + const float EDGE_THRESHOLD_MAX = 0.125; + const int ITERATIONS = 12; + const float SUBPIXEL_QUALITY = 0.75; + + float lumaUp = rgb2luma( textureLodOffset( sourceColor, uv_interp, 0.0, ivec2( 0, 1 ) ).xyz * exposure * parameters.luminance_multiplier ); + float lumaDown = rgb2luma( textureLodOffset( sourceColor, uv_interp, 0.0, ivec2( 0, -1 ) ).xyz * exposure * parameters.luminance_multiplier ); + float lumaLeft = rgb2luma( textureLodOffset( sourceColor, uv_interp, 0.0, ivec2( -1, 0 ) ).xyz * exposure * parameters.luminance_multiplier ); + float lumaRight = rgb2luma( textureLodOffset( sourceColor, uv_interp, 0.0, ivec2( 1, 0 ) ).xyz * exposure * parameters.luminance_multiplier ); + + float lumaCenter = rgb2luma( color ); + + float lumaMin = min( lumaCenter, min( min( lumaUp, lumaDown ), min( lumaLeft, lumaRight ) ) ); + float lumaMax = max( lumaCenter, max( max( lumaUp, lumaDown ), max( lumaLeft, lumaRight ) ) ); + + float lumaRange = lumaMax - lumaMin; + + if ( lumaRange < max( EDGE_THRESHOLD_MIN, lumaMax * EDGE_THRESHOLD_MAX ) ) + { + return color; + } + + float lumaDownLeft = rgb2luma( textureLodOffset( sourceColor, uv_interp, 0.0, ivec2( -1, -1 ) ).xyz * exposure * parameters.luminance_multiplier ); + float lumaUpRight = rgb2luma( textureLodOffset( sourceColor, uv_interp, 0.0, ivec2( 1, 1 ) ).xyz * exposure * parameters.luminance_multiplier ); + float lumaUpLeft = rgb2luma( textureLodOffset( sourceColor, uv_interp, 0.0, ivec2( -1, 1 ) ).xyz * exposure * parameters.luminance_multiplier ); + float lumaDownRight = rgb2luma( textureLodOffset( sourceColor, uv_interp, 0.0, ivec2( 1, -1 ) ).xyz * exposure * parameters.luminance_multiplier ); + + float lumaDownUp = lumaDown + lumaUp; + float lumaLeftRight = lumaLeft + lumaRight; + + float lumaLeftCorners = lumaDownLeft + lumaUpLeft; + float lumaDownCorners = lumaDownLeft + lumaDownRight; + float lumaRightCorners = lumaDownRight + lumaUpRight; + float lumaUpCorners = lumaUpRight + lumaUpLeft; + + float edgeHorizontal = abs( -2.0 * lumaLeft + lumaLeftCorners ) + abs( -2.0 * lumaCenter + lumaDownUp ) * 2.0 + abs( -2.0 * lumaRight + lumaRightCorners ); + float edgeVertical = abs( -2.0 * lumaUp + lumaUpCorners ) + abs( -2.0 * lumaCenter + lumaLeftRight ) * 2.0 + abs( -2.0 * lumaDown + lumaDownCorners ); + + bool isHorizontal = ( edgeHorizontal >= edgeVertical ); + + float stepLength = isHorizontal ? pixel_size.y : pixel_size.x; + + float luma1 = isHorizontal ? lumaDown : lumaLeft; + float luma2 = isHorizontal ? lumaUp : lumaRight; + float gradient1 = luma1 - lumaCenter; + float gradient2 = luma2 - lumaCenter; + + bool is1Steepest = abs( gradient1 ) >= abs( gradient2 ); + + float gradientScaled = 0.25 * max( abs( gradient1 ), abs( gradient2 ) ); + + float lumaLocalAverage = 0.0; + if ( is1Steepest ) { + stepLength = -stepLength; + lumaLocalAverage = 0.5 * ( luma1 + lumaCenter ); + } else { + lumaLocalAverage = 0.5 * ( luma2 + lumaCenter ); + } + + vec2 currentUv = uv_interp; + if ( isHorizontal ) { + currentUv.y += stepLength * 0.5; + } else { + currentUv.x += stepLength * 0.5; + } + + vec2 offset = isHorizontal ? vec2( pixel_size.x, 0.0 ) : vec2( 0.0, pixel_size.y ); + vec2 uv1 = currentUv - offset * QUALITY( 0 ); + vec2 uv2 = currentUv + offset * QUALITY( 0 ); + + float lumaEnd1 = rgb2luma( textureLod( sourceColor, uv1, 0.0 ).xyz * exposure * parameters.luminance_multiplier ); + float lumaEnd2 = rgb2luma( textureLod( sourceColor, uv2, 0.0 ).xyz * exposure * parameters.luminance_multiplier ); + lumaEnd1 -= lumaLocalAverage; + lumaEnd2 -= lumaLocalAverage; + + bool reached1 = abs( lumaEnd1 ) >= gradientScaled; + bool reached2 = abs( lumaEnd2 ) >= gradientScaled; + bool reachedBoth = reached1 && reached2; + + if ( !reached1 ) { + uv1 -= offset * QUALITY( 1 ); + } + if ( !reached2 ) { + uv2 += offset * QUALITY( 1 ); + } + + if ( !reachedBoth ) { + for ( int i = 2; i < ITERATIONS; i++ ) { + if ( !reached1 ) { + lumaEnd1 = rgb2luma( textureLod( sourceColor, uv1, 0.0 ).xyz * exposure * parameters.luminance_multiplier ); + lumaEnd1 = lumaEnd1 - lumaLocalAverage; + } + if ( !reached2 ) { + lumaEnd2 = rgb2luma( textureLod( sourceColor, uv2, 0.0 ).xyz * exposure * parameters.luminance_multiplier ); + lumaEnd2 = lumaEnd2 - lumaLocalAverage; + } + reached1 = abs( lumaEnd1 ) >= gradientScaled; + reached2 = abs( lumaEnd2 ) >= gradientScaled; + reachedBoth = reached1 && reached2; + if ( !reached1 ) { + uv1 -= offset * QUALITY( i ); + } + if ( !reached2 ) { + uv2 += offset * QUALITY( i ); + } + if ( reachedBoth ) { + break; + } + } + } + + float distance1 = isHorizontal ? ( uv_interp.x - uv1.x ) : ( uv_interp.y - uv1.y ); + float distance2 = isHorizontal ? ( uv2.x - uv_interp.x ) : ( uv2.y - uv_interp.y ); + + bool isDirection1 = distance1 < distance2; + float distanceFinal = min( distance1, distance2 ); + + float edgeThickness = ( distance1 + distance2 ); + + bool isLumaCenterSmaller = lumaCenter < lumaLocalAverage; + + bool correctVariation1 = ( lumaEnd1 < 0.0 ) != isLumaCenterSmaller; + bool correctVariation2 = ( lumaEnd2 < 0.0 ) != isLumaCenterSmaller; + + bool correctVariation = isDirection1 ? correctVariation1 : correctVariation2; + + float pixelOffset = -distanceFinal / edgeThickness + 0.5; + + float finalOffset = correctVariation ? pixelOffset : 0.0; + + float lumaAverage = ( 1.0 / 12.0 ) * ( 2.0 * ( lumaDownUp + lumaLeftRight ) + lumaLeftCorners + lumaRightCorners ); + + float subPixelOffset1 = clamp( abs( lumaAverage - lumaCenter ) / lumaRange, 0.0, 1.0 ); + float subPixelOffset2 = ( -2.0 * subPixelOffset1 + 3.0 ) * subPixelOffset1 * subPixelOffset1; + + float subPixelOffsetFinal = subPixelOffset2 * subPixelOffset2 * SUBPIXEL_QUALITY; + + finalOffset = max( finalOffset, subPixelOffsetFinal ); + + vec2 finalUv = uv_interp; + if ( isHorizontal ) + { + finalUv.y += finalOffset * stepLength; + } + else + { + finalUv.x += finalOffset * stepLength; + } + + vec3 finalColor = textureLod( sourceColor, finalUv, 0.0 ).xyz * exposure * parameters.luminance_multiplier; + return finalColor; + +} + + +void main() +{ + ivec2 size = imageSize( outputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( xy ) + vec2( 0.5 ) ) / vec2( size ); + + float exposure = parameters.exposure; + + vec4 color = textureLod( sourceColor, uv, 0 ); + vec4 original = color; + + color.rgb = applyFXAA( color.rgb, exposure, uv, 1.0 / size ); + + color = mix( original, color, parameters.amount ); + + imageStore( outputImage, xy, color ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/FXAA.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/FXAA.glsl.import new file mode 100644 index 0000000..7825826 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/FXAA.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://dl2u3wsehqitk" +path="res://.godot/imported/FXAA.glsl-407f27be9c671cc34cba7e9e09b95f3b.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/FXAA.glsl" +dest_files=["res://.godot/imported/FXAA.glsl-407f27be9c671cc34cba7e9e09b95f3b.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/RG_FXAA.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/RG_FXAA.cs new file mode 100644 index 0000000..5af9827 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/RG_FXAA.cs @@ -0,0 +1,18 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_FXAA:CEG_ImageProcessor + { + + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/AntiAliasing/FXAA/FXAA.glsl" ); + + public RG_FXAA( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/RG_FXAA.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/RG_FXAA.cs.uid new file mode 100644 index 0000000..14f6949 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/AntiAliasing/FXAA/RG_FXAA.cs.uid @@ -0,0 +1 @@ +uid://rhe0n5g2d2ee diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/BlendMode_Alpha.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/BlendMode_Alpha.glsl new file mode 100644 index 0000000..1f51576 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/BlendMode_Alpha.glsl @@ -0,0 +1,77 @@ +#[compute] +#version 450 + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc" + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( set = 0, binding = 0 ) +uniform sampler2D topImage; + +layout( set = 1, binding = 0 ) +uniform sampler2D maskImage; + +layout( set = 2, binding = 0 ) +uniform sampler2D bottomImage; + +layout( rgba16f, set = 3, binding = 0 ) +uniform image2D outputImage; + + +layout( push_constant, std430 ) +uniform Parameters +{ + vec4 topTilingOffset; + vec4 maskTilingOffset; + vec4 bottomTilingOffset; + vec4 topTint; + + float opacity; + float topColorConversion; + float maskColorConversion; + float bottomColorConversion; + + float outputColorConversion; + float forceOpaqueBottom; + float p2; + float p3; + +} parameters; + + +void main( ) +{ + ivec2 size = imageSize( outputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( xy ) + vec2( 0.5 ) ) / vec2( size ); + + vec4 topColor = texture( topImage, uv * parameters.topTilingOffset.xy + parameters.topTilingOffset.zw ); + vec4 maskColor = texture( maskImage, uv * parameters.maskTilingOffset.xy + parameters.maskTilingOffset.zw ); + vec4 bottomColor = texture( bottomImage, uv * parameters.bottomTilingOffset.xy + parameters.bottomTilingOffset.zw ); + + topColor *= parameters.topTint; + + topColor = colorSpaceConversion( topColor, int( parameters.topColorConversion ) ); + maskColor = colorSpaceConversion( maskColor, int( parameters.maskColorConversion ) ); + bottomColor = colorSpaceConversion( bottomColor, int( parameters.bottomColorConversion ) ); + + topColor.a *= parameters.opacity * maskColor.r ; + + if ( parameters.forceOpaqueBottom > 0.5 ) + { + bottomColor.a = 1.; + } + + vec4 blended = blendMode_alpha( bottomColor, topColor ); + + blended = colorSpaceConversion( blended, int( parameters.outputColorConversion ) ); + + + imageStore( outputImage, xy, blended ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/BlendMode_Alpha.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/BlendMode_Alpha.glsl.import new file mode 100644 index 0000000..442e83c --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/BlendMode_Alpha.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://cqrsk43lxoh5l" +path="res://.godot/imported/BlendMode_Alpha.glsl-5e1f8702121b27a17fef05a79b94fcf2.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/BlendMode_Alpha.glsl" +dest_files=["res://.godot/imported/BlendMode_Alpha.glsl-5e1f8702121b27a17fef05a79b94fcf2.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/RG_BlendMode_Alpha.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/RG_BlendMode_Alpha.cs new file mode 100644 index 0000000..18f4d97 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/RG_BlendMode_Alpha.cs @@ -0,0 +1,22 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_BlendMode_Alpha:RG_BlendModeBase + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Blend/BlendMode_Alpha/BlendMode_Alpha.glsl" ); + + public RG_BlendMode_Alpha( RDGraph graph ):base( graph, shaderPath ) + {} + + public override RG_BlendModeType GetBlendModeType() + { + return RG_BlendModeType.Alpha; + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/RG_BlendMode_Alpha.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/RG_BlendMode_Alpha.cs.uid new file mode 100644 index 0000000..1a67e5e --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Alpha/RG_BlendMode_Alpha.cs.uid @@ -0,0 +1 @@ +uid://b0k8rl3w6f3ad diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/BlendMode_Screen.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/BlendMode_Screen.glsl new file mode 100644 index 0000000..f84eca7 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/BlendMode_Screen.glsl @@ -0,0 +1,77 @@ +#[compute] +#version 450 + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc" + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( set = 0, binding = 0 ) +uniform sampler2D topImage; + +layout( set = 1, binding = 0 ) +uniform sampler2D maskImage; + +layout( set = 2, binding = 0 ) +uniform sampler2D bottomImage; + +layout( rgba16f, set = 3, binding = 0 ) +uniform image2D outputImage; + + +layout( push_constant, std430 ) +uniform Parameters +{ + vec4 topTilingOffset; + vec4 maskTilingOffset; + vec4 bottomTilingOffset; + vec4 topTint; + + float opacity; + float topColorConversion; + float maskColorConversion; + float bottomColorConversion; + + float outputColorConversion; + float forceOpaqueBottom; + float p2; + float p3; + +} parameters; + + +void main( ) +{ + ivec2 size = imageSize( outputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( xy ) + vec2( 0.5 ) ) / vec2( size ); + + vec4 topColor = texture( topImage, uv * parameters.topTilingOffset.xy + parameters.topTilingOffset.zw ); + vec4 maskColor = texture( maskImage, uv * parameters.maskTilingOffset.xy + parameters.maskTilingOffset.zw ); + vec4 bottomColor = texture( bottomImage, uv * parameters.bottomTilingOffset.xy + parameters.bottomTilingOffset.zw ); + + topColor *= parameters.topTint; + + topColor = colorSpaceConversion( topColor, int( parameters.topColorConversion ) ); + maskColor = colorSpaceConversion( maskColor, int( parameters.maskColorConversion ) ); + bottomColor = colorSpaceConversion( bottomColor, int( parameters.bottomColorConversion ) ); + + topColor.a *= parameters.opacity * maskColor.r ; + + if ( parameters.forceOpaqueBottom > 0.5 ) + { + bottomColor.a = 1.; + } + + vec4 blended = blendMode_screen( bottomColor, topColor ); + + blended = colorSpaceConversion( blended, int( parameters.outputColorConversion ) ); + + + imageStore( outputImage, xy, blended ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/BlendMode_Screen.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/BlendMode_Screen.glsl.import new file mode 100644 index 0000000..617b339 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/BlendMode_Screen.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://147wufofqg3a" +path="res://.godot/imported/BlendMode_Screen.glsl-9e7cd0e6e54b5625a5f1441c8838248e.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/BlendMode_Screen.glsl" +dest_files=["res://.godot/imported/BlendMode_Screen.glsl-9e7cd0e6e54b5625a5f1441c8838248e.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/RG_BlendMode_Screen.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/RG_BlendMode_Screen.cs new file mode 100644 index 0000000..f91e572 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/RG_BlendMode_Screen.cs @@ -0,0 +1,20 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_BlendMode_Screen:RG_BlendModeBase + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Blend/BlendMode_Screen/BlendMode_Screen.glsl" ); + + public RG_BlendMode_Screen( RDGraph graph ):base( graph, shaderPath ) + {} + + public override RG_BlendModeType GetBlendModeType() + { + return RG_BlendModeType.Screen; + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/RG_BlendMode_Screen.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/RG_BlendMode_Screen.cs.uid new file mode 100644 index 0000000..78bc816 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/BlendMode_Screen/RG_BlendMode_Screen.cs.uid @@ -0,0 +1 @@ +uid://pdyp5ufyjlsb diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/RG_BlendModes.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/RG_BlendModes.cs new file mode 100644 index 0000000..ea7b157 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/RG_BlendModes.cs @@ -0,0 +1,60 @@ + +using Godot; +using System.Collections.Generic; +using System.Linq; + +namespace Rokojori +{ + public enum RG_BlendModeType + { + Alpha, + Screen + } + + public class RG_BlendModesTool + { + public static List CreateAll( RDGraph graph ) + { + List blendModes = [ + new RG_BlendMode_Alpha( graph ), + new RG_BlendMode_Screen( graph ) + ]; + + + return blendModes; + } + + public static RG_BlendModeBase ByType( RDGraph graph, RG_BlendModeType type ) + { + if ( RG_BlendModeType.Alpha == type ) + { + return new RG_BlendMode_Alpha( graph ); + } + else if ( RG_BlendModeType.Screen == type ) + { + return new RG_BlendMode_Screen( graph ); + } + + return null; + } + + public static RG_BlendModeBase[] Create( RDGraph graph, params RG_BlendModeType[] types ) + { + return types.Map( t => ByType( graph, t ) ); + } + + public static RG_BlendModeBase GetCurrentBlendMode( IEnumerable blendModes, RG_BlendModeType type ) + { + foreach ( var bm in blendModes ) + { + if ( bm.GetBlendModeType() == type ) + { + return bm; + } + } + + return null; + } + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/RG_BlendModes.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/RG_BlendModes.cs.uid new file mode 100644 index 0000000..2c55840 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Blend/RG_BlendModes.cs.uid @@ -0,0 +1 @@ +uid://b56rouvuui3o1 diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/CrossChannelCurves.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/CrossChannelCurves.glsl new file mode 100644 index 0000000..35dea19 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/CrossChannelCurves.glsl @@ -0,0 +1,92 @@ +#[compute] +#version 450 + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc" + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( rgba16f, set = 0, binding = 0 ) +uniform image2D inputImage; +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + +layout( set = 2, binding = 0 ) +uniform sampler2D curves; + + +layout( push_constant, std430 ) +uniform Parameters +{ + float amount; + float driverChannel; + float targetChannel; + float pad; + + float p0; + float p1; + float p2; + float p3; + +} parameters; + + +void main( ) +{ + ivec2 size = imageSize( inputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( xy ) + 0.5 ) / vec2( size ); + + vec4 color = imageLoad( inputImage, ivec2( uv * size ) ); + + vec4 processedColor = color; + float scale = getRGBScale( color ); + + int driver = int( round( parameters.driverChannel ) ); + int target = int( round( parameters.targetChannel ) ); + + bool driverIsHSL = false; + + vec4 driverColor = color; + + if ( driver >= 3 ) + { + driver -= 3; + driverColor = RGBtoHSL( color, scale ); + driverIsHSL = true; + } + + float driverValue = getRGBByIndex( driverColor.rgb, driver ); + + float offset = texture( curves, vec2( driverValue, 0 ) ).r * 2.0 - 1.0; + + if ( target >= 3 ) + { + processedColor = RGBtoHSL( color, scale ); + + if ( target == 6 ) + { + processedColor.r = changeTemparature( processedColor.r, offset, 30 ); + } + else + { + processedColor.rgb = changeRGBByIndex( processedColor.rgb, target - 3, offset ); + } + + processedColor = HSLtoRGB( processedColor, scale ); + } + else + { + processedColor.rgb = changeRGBByIndex( processedColor.rgb, target, offset ); + } + + + vec4 blended = mix( color, processedColor, parameters.amount ); + + imageStore( outputImage, xy, blended ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/CrossChannelCurves.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/CrossChannelCurves.glsl.import new file mode 100644 index 0000000..76684cc --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/CrossChannelCurves.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://qvwo2mkhower" +path="res://.godot/imported/CrossChannelCurves.glsl-7e2d0ae8aca9253afb53652696608856.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/CrossChannelCurves.glsl" +dest_files=["res://.godot/imported/CrossChannelCurves.glsl-7e2d0ae8aca9253afb53652696608856.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/RG_CrossChannelCurves.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/RG_CrossChannelCurves.cs new file mode 100644 index 0000000..96cb232 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/RG_CrossChannelCurves.cs @@ -0,0 +1,28 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_CrossChannelCurves:CEG_ImageProcessor + { + public readonly CompositorEffectGraphTextureSlot curves; + + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Color/CrossChannelCurves/CrossChannelCurves.glsl" ); + + public RG_CrossChannelCurves( RDGraph graph ):base( graph, shaderPath ) + { + curves = new CompositorEffectGraphTextureSlot( this ); + + _textureSlots.Add( curves ); + } + + public void SetCurvesTextureSlotInputs( RDGraphTextureSlotInput curvesSlotInput ) + { + curvesSlotInput.ConnectTo( curves ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/RG_CrossChannelCurves.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/RG_CrossChannelCurves.cs.uid new file mode 100644 index 0000000..a53b00c --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/CrossChannelCurves/RG_CrossChannelCurves.cs.uid @@ -0,0 +1 @@ +uid://bltsv5s6r2rm6 diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/HDRMapping.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/HDRMapping.glsl new file mode 100644 index 0000000..9b76bc2 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/HDRMapping.glsl @@ -0,0 +1,57 @@ +#[compute] +#version 450 + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( set = 0, binding = 0 ) +uniform sampler2D mapping; + +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + + +layout( push_constant, std430 ) +uniform Parameters +{ + float maximumLevel; + float lumaWeightR; + float lumaWeightG; + float lumaWeightB; + + float power; + float scale; + float maxOutputScale; + float pad2; + +} parameters; + + + +void main( ) +{ + ivec2 size = imageSize( outputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec4 color = imageLoad( outputImage, xy ); + + float luma = color.r * parameters.lumaWeightR + + color.g * parameters.lumaWeightG + + color.b * parameters.lumaWeightB; + + luma = pow( luma, parameters.power ) * parameters.scale; + + + float lookup = min( 1.0, luma / parameters.maximumLevel ); + + float outputScale = textureLod( mapping, vec2( lookup, 0.0 ), 0 ).r * parameters.maxOutputScale; + + + + + imageStore( outputImage, xy, normalize( color ) * outputScale ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/HDRMapping.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/HDRMapping.glsl.import new file mode 100644 index 0000000..6b74868 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/HDRMapping.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://pjnmi36s2w5p" +path="res://.godot/imported/HDRMapping.glsl-2911ebd397856e780c2d328dfdba86d1.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/HDRMapping.glsl" +dest_files=["res://.godot/imported/HDRMapping.glsl-2911ebd397856e780c2d328dfdba86d1.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/RG_HDRMapping.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/RG_HDRMapping.cs new file mode 100644 index 0000000..02bdf72 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/RG_HDRMapping.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_HDRMapping:CEG_ImageProcessor + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Color/HDRMapping/HDRMapping.glsl" ); + + public RG_HDRMapping( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/RG_HDRMapping.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/RG_HDRMapping.cs.uid new file mode 100644 index 0000000..2a8384e --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HDRMapping/RG_HDRMapping.cs.uid @@ -0,0 +1 @@ +uid://bmj6wfut62lhe diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/HSLCurves.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/HSLCurves.glsl new file mode 100644 index 0000000..5e8e216 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/HSLCurves.glsl @@ -0,0 +1,60 @@ +#[compute] +#version 450 + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc" + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( rgba16f, set = 0, binding = 0 ) +uniform image2D inputImage; +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + +layout( set = 2, binding = 0 ) +uniform sampler2D curves; + + +layout( push_constant, std430 ) +uniform Parameters +{ + float amount; + +} parameters; + + +void main( ) +{ + ivec2 size = imageSize( inputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( xy ) + 0.5 ) / vec2( size ); + + vec4 color = imageLoad( inputImage, ivec2( uv * size ) ); + + vec4 processedColor = color; + + float scale = getRGBScale( processedColor ); + + processedColor = RGBtoHSL( processedColor / scale ); + + float r = texture( curves, vec2( processedColor.r, 0 ) ).r; + float g = texture( curves, vec2( processedColor.g, 0 ) ).g; + float b = texture( curves, vec2( processedColor.b, 0 ) ).b; + + processedColor.r = r; + processedColor.g = g; + processedColor.b = b; + + processedColor = HSLtoRGB( processedColor ) * scale; + + + vec4 blended = mix( color, processedColor, parameters.amount ); + + + imageStore( outputImage, xy, blended ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/HSLCurves.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/HSLCurves.glsl.import new file mode 100644 index 0000000..ad81215 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/HSLCurves.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://bu8mm6wlum1rg" +path="res://.godot/imported/HSLCurves.glsl-64e86d68051d5ddb7c3d300e402fa7f8.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/HSLCurves.glsl" +dest_files=["res://.godot/imported/HSLCurves.glsl-64e86d68051d5ddb7c3d300e402fa7f8.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/RG_HSLCurves.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/RG_HSLCurves.cs new file mode 100644 index 0000000..c6e775a --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/RG_HSLCurves.cs @@ -0,0 +1,28 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_HSLCurves:CEG_ImageProcessor + { + public readonly CompositorEffectGraphTextureSlot curves; + + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Color/HSLCurves/HSLCurves.glsl" ); + + public RG_HSLCurves( RDGraph graph ):base( graph, shaderPath ) + { + curves = new CompositorEffectGraphTextureSlot( this ); + + _textureSlots.Add( curves ); + } + + public void SetCurvesTextureSlotInputs( RDGraphTextureSlotInput curvesSlotInput ) + { + curvesSlotInput.ConnectTo( curves ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/RG_HSLCurves.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/RG_HSLCurves.cs.uid new file mode 100644 index 0000000..df59041 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/HSLCurves/RG_HSLCurves.cs.uid @@ -0,0 +1 @@ +uid://bytyww2pamtio diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RGBCurves.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RGBCurves.glsl new file mode 100644 index 0000000..7c42d2e --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RGBCurves.glsl @@ -0,0 +1,52 @@ +#[compute] +#version 450 + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( rgba16f, set = 0, binding = 0 ) +uniform image2D inputImage; +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + +layout( set = 2, binding = 0 ) +uniform sampler2D curves; + + +layout( push_constant, std430 ) +uniform Parameters +{ + float amount; + +} parameters; + + +void main( ) +{ + ivec2 size = imageSize( inputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( xy ) + 0.5 ) / vec2( size ); + + vec4 color = imageLoad( inputImage, ivec2( uv * size ) ); + + vec4 processedColor = color; + + float r = texture( curves, vec2( color.r, 0 ) ).r; + float g = texture( curves, vec2( color.g, 0 ) ).g; + float b = texture( curves, vec2( color.b, 0 ) ).b; + + processedColor.r = r; + processedColor.g = g; + processedColor.b = b; + + + vec4 blended = mix( color, processedColor, parameters.amount ); + + + imageStore( outputImage, xy, blended ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RGBCurves.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RGBCurves.glsl.import new file mode 100644 index 0000000..803236c --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RGBCurves.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://c50yuw0e5wxsm" +path="res://.godot/imported/RGBCurves.glsl-ad2660280b2e3d71a66fa9fe7ef2147b.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RGBCurves.glsl" +dest_files=["res://.godot/imported/RGBCurves.glsl-ad2660280b2e3d71a66fa9fe7ef2147b.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RG_RGBCurves.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RG_RGBCurves.cs new file mode 100644 index 0000000..ef2b0b5 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RG_RGBCurves.cs @@ -0,0 +1,28 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_RGBCurves:CEG_ImageProcessor + { + public readonly CompositorEffectGraphTextureSlot curves; + + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Color/RGBCurves/RGBCurves.glsl" ); + + public RG_RGBCurves( RDGraph graph ):base( graph, shaderPath ) + { + curves = new CompositorEffectGraphTextureSlot( this ); + + _textureSlots.Add( curves ); + } + + public void SetCurvesTextureSlotInputs( RDGraphTextureSlotInput curvesSlotInput ) + { + curvesSlotInput.ConnectTo( curves ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RG_RGBCurves.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RG_RGBCurves.cs.uid new file mode 100644 index 0000000..9172809 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/RGBCurves/RG_RGBCurves.cs.uid @@ -0,0 +1 @@ +uid://b11ueshr6ireg diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/RG_Resize.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/RG_Resize.cs new file mode 100644 index 0000000..6f01392 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/RG_Resize.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_Resize:CEG_ImageProcessor + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Copy/Resize.glsl" ); + + public RG_Resize( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/RG_Resize.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/RG_Resize.cs.uid new file mode 100644 index 0000000..ee2f52b --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/RG_Resize.cs.uid @@ -0,0 +1 @@ +uid://f535xyylnwho diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/Resize.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/Resize.glsl new file mode 100644 index 0000000..5b5e730 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/Resize.glsl @@ -0,0 +1,27 @@ +#[compute] +#version 450 + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( set = 0, binding = 0 ) +uniform sampler2D inputImage; + +layout( rgba16, set = 1, binding = 0 ) +uniform restrict writeonly image2D outputImage; + +void main() +{ + ivec2 size = imageSize( outputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( xy ) + vec2( 0.5 ) ) / vec2( size ); + + vec4 color = texture( inputImage, uv ); + + imageStore( outputImage, xy, color ); +} diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/Resize.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/Resize.glsl.import new file mode 100644 index 0000000..3a56e96 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/Resize.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://bqiybeie3l5u6" +path="res://.godot/imported/Resize.glsl-96f1fb4167d1f455df19f5ae03c66e2e.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Copy/Resize.glsl" +dest_files=["res://.godot/imported/Resize.glsl-96f1fb4167d1f455df19f5ae03c66e2e.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/EdgeDistortion.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/EdgeDistortion.glsl new file mode 100644 index 0000000..8baa83d --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/EdgeDistortion.glsl @@ -0,0 +1,238 @@ +#[compute] +#version 450 + + +float clamp01( float value ) +{ + return clamp( value, 0.0, 1.0 ); +} + +float normalizeToRange( float value, float min, float max ) +{ + return ( value - min ) / ( max - min ); +} + +float normalizeToRange01( float value, float min, float max ) +{ + return clamp01( normalizeToRange( value, min, max ) ); +} + +float map( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange( value, inMin, inMax ) ); +} + +float mapClamped( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange01( value, inMin, inMax ) ); +} + +float random( vec2 uv ) +{ + return fract( sin( dot( uv.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453123 ); +} + +vec2 random_v2( vec2 uv ) +{ + uv = vec2 + ( + dot(uv, vec2( 127.1,311.7 ) ), + dot(uv, vec2( 269.5,183.3 ) ) + ); + + return -1.0 + 2.0 * fract( sin( uv ) * 43758.5453123 ); +} + + +vec3 random_v3( vec3 uvw ) +{ + + uvw = vec3( dot(uvw, vec3(127.1,311.7, 513.7) ), + dot(uvw, vec3(269.5,183.3, 396.5) ), + dot(uvw, vec3(421.3,314.1, 119.7) ) ); + + return -1.0 + 2.0 * fract(sin(uvw) * 43758.5453123); +} + +float perlin(vec2 uv) +{ + vec2 uv_index = floor(uv); + vec2 uv_fract = fract(uv); + + vec2 blur = smoothstep(0.0, 1.0, uv_fract); + + return mix( mix( dot( random_v2(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), + dot( random_v2(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), + mix( dot( random_v2(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), + dot( random_v2(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) + 0.5; +} + +float mirrorValue( float x ) +{ + float t = mod( x, 2.0 ); + return ( t <= 1.0 ) ? t : 2.0 - t; +} + +vec2 mirrorUV( vec2 uv ) +{ + return vec2( mirrorValue( uv.x ), mirrorValue( uv.y ) ); +} + + + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( rgba16f, set = 0, binding = 0 ) +uniform image2D inputImage; + +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + +// layout( rgba16f, set = 2, binding = 0 ) +// uniform image2D noiseImage; + +layout( push_constant, std430 ) +uniform Parameters +{ + float distortionAmount; + float blendAmount; + float horizontalEdge; + float verticalEdge; + + float redScale; + float greenScale; + float blueScale; + + float steps; + float smear; + + float horizontalEdgePower; + float verticalEdgePower; + float horizontalAmount; + float verticalAmount; + float p0; + float p1; + float p2; + +} parameters; + + +vec4 sampleChromatic( vec2 uv, vec2 dir, ivec2 size, int steps, vec3 shifts, float smear ) +{ + vec4 combinedColor = vec4( 0.0 ); + + float weights = 0.0; + + for ( int i = -steps; i <= steps; i++ ) + { + float t = float( i ) / float( steps ); + float w = 1.0 - abs( t ); + vec2 stepDir = dir * pow( smear, t ); + + vec2 rUV = uv + stepDir * shifts.r; + rUV = mirrorUV( rUV ); + + vec2 gUV = uv + stepDir * shifts.g; + gUV = mirrorUV( gUV ); + + vec2 bUV = uv + stepDir * shifts.b; + bUV = mirrorUV( bUV ); + + vec4 colorR = imageLoad( inputImage, ivec2( rUV * size ) ); + vec4 colorG = imageLoad( inputImage, ivec2( gUV * size ) ); + vec4 colorB = imageLoad( inputImage, ivec2( bUV * size ) ); + + combinedColor.r += colorR.r * w; + combinedColor.g += colorG.g * w; + combinedColor.b += colorB.b * w; + combinedColor.a += colorG.a * w; + + weights += w; + } + + combinedColor /= weights; + + return combinedColor; +} + +float triangle( float value ) +{ + float inverted = 1.0 - value; + + return min( value, inverted ) * 2.0; +} + +float ringFunction( float value, float roundness ) +{ + float t = triangle( mod( value, 1.0 ) ); + float c = 0.5 - 0.5 * cos( 6.28318531 * value ); + + return clamp( mix( t, c, roundness ), 0.0, 1.0 ); +} + +void main( ) +{ + ivec2 size = imageSize( inputImage ); + ivec2 texel_coord = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( texel_coord, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( texel_coord ) + 0.5 ) / vec2( size ); + + + + vec2 dirX = vec2( 0.0, 0.0 ); + vec2 dirY = vec2( 0.0, 0.0 ); + + float xAmount = 0.0; + float yAmount = 0.0; + + if ( uv.x < parameters.horizontalEdge ) + { + dirX.x = 1.0; + xAmount = 1.0 - uv.x / parameters.horizontalEdge; + } + else if ( uv.x > ( 1.0 - parameters.horizontalEdge ) ) + { + dirX.x = -1.0; + xAmount = 1.0 - ( 1.0 - uv.x ) / parameters.horizontalEdge; + } + + if ( uv.y < parameters.verticalEdge ) + { + dirY.y = 1.0; + yAmount = 1.0 - uv.y / parameters.verticalEdge; + } + else if ( uv.y > ( 1.0 - parameters.verticalEdge ) ) + { + dirY.y = -1.0; + yAmount = 1.0 - ( 1.0 - uv.y ) / parameters.verticalEdge; + } + + xAmount = pow( xAmount, parameters.horizontalEdgePower ) * parameters.horizontalAmount; + yAmount = pow( yAmount, parameters.verticalEdgePower ) * parameters.verticalAmount; + + vec2 uvOffsetX = dirX * xAmount; + vec2 uvOffsetY = dirY * yAmount; + vec3 distortion = vec3( parameters.redScale, parameters.greenScale, parameters.blueScale ) * parameters.distortionAmount; + + int stepsI = min( 32, int( parameters.steps ) ); + + vec4 originalColor = imageLoad( inputImage, texel_coord ); + + vec2 uvOffset = uvOffsetX; + + if ( yAmount > 0 ) + { + uvOffset = ( xAmount * uvOffsetX + yAmount * uvOffsetY ) / ( yAmount + xAmount ); + } + + vec4 color = sampleChromatic( uv, uvOffset, size, stepsI, distortion, parameters.smear ); + + + color = mix( originalColor, color, parameters.blendAmount ); + imageStore( outputImage, texel_coord, color ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/EdgeDistortion.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/EdgeDistortion.glsl.import new file mode 100644 index 0000000..0e11b4d --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/EdgeDistortion.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://b7wgyhibugic7" +path="res://.godot/imported/EdgeDistortion.glsl-4a6d823c9398c934085bdaf08d289f3f.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/EdgeDistortion.glsl" +dest_files=["res://.godot/imported/EdgeDistortion.glsl-4a6d823c9398c934085bdaf08d289f3f.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/RG_EdgeDistortion.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/RG_EdgeDistortion.cs new file mode 100644 index 0000000..3982c81 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/RG_EdgeDistortion.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_EdgeDistortion:CEG_ImageProcessor + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Distortion/EdgeDistortion/EdgeDistortion.glsl" ); + + public RG_EdgeDistortion( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/RG_EdgeDistortion.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/RG_EdgeDistortion.cs.uid new file mode 100644 index 0000000..6791f04 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EdgeDistortion/RG_EdgeDistortion.cs.uid @@ -0,0 +1 @@ +uid://c4pbglfky8n1o diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EllipseDistortion/EllipseDistortion.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EllipseDistortion/EllipseDistortion.glsl index b978705..c3611d7 100644 --- a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EllipseDistortion/EllipseDistortion.glsl +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/EllipseDistortion/EllipseDistortion.glsl @@ -220,7 +220,7 @@ void main( ) vec2 uvOffset = normalize( dir ) * amount; vec3 distortion = vec3( parameters.redScale, parameters.greenScale, parameters.blueScale ) * parameters.distortionAmount; - int stepsI = min( 10, int( parameters.steps ) ); + int stepsI = min( 32, int( parameters.steps ) ); vec4 originalColor = imageLoad( inputImage, texel_coord ); vec4 color = originalColor; diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/NoiseDistortion/NoiseDistortion.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/NoiseDistortion/NoiseDistortion.glsl index 9c1e879..47578c6 100644 --- a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/NoiseDistortion/NoiseDistortion.glsl +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/NoiseDistortion/NoiseDistortion.glsl @@ -165,7 +165,7 @@ void main( ) vec2 uvNoise = vec2( noiseX, noiseY ) * 2.0 - vec2( 1.0 ); - int stepsI = min( 5, int( parameters.steps ) ); + int stepsI = min( 32, int( parameters.steps ) ); vec3 distortion = vec3( parameters.redScale, parameters.greenScale, parameters.blueScale ) * parameters.distortionAmount; diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/RD_TextureDistortion.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/RD_TextureDistortion.cs new file mode 100644 index 0000000..7be1671 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/RD_TextureDistortion.cs @@ -0,0 +1,32 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RD_TextureDistortion:CEG_ImageProcessor + { + public readonly CompositorEffectGraphTextureSlot distortion; + public readonly CompositorEffectGraphTextureSlot mask; + + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Distortion/TextureDistortion/TextureDistortion.glsl" ); + + public RD_TextureDistortion( RDGraph graph ):base( graph, shaderPath ) + { + distortion = new CompositorEffectGraphTextureSlot( this ); + mask = new CompositorEffectGraphTextureSlot( this ); + + _textureSlots.Add( distortion ); + _textureSlots.Add( mask ); + } + + public void SetDistortionTextureSlotInputs( RDGraphTextureSlotInput distortionSlot, RDGraphTextureSlotInput maskSlot ) + { + distortionSlot.ConnectTo( distortion ); + maskSlot.ConnectTo( mask ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/RD_TextureDistortion.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/RD_TextureDistortion.cs.uid new file mode 100644 index 0000000..becdf8b --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/RD_TextureDistortion.cs.uid @@ -0,0 +1 @@ +uid://d4awr4jaybsum diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/TextureDistortion.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/TextureDistortion.glsl new file mode 100644 index 0000000..b9b54cf --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/TextureDistortion.glsl @@ -0,0 +1,198 @@ +#[compute] +#version 450 + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc" + +float clamp01( float value ) +{ + return clamp( value, 0.0, 1.0 ); +} + +float normalizeToRange( float value, float min, float max ) +{ + return ( value - min ) / ( max - min ); +} + +float normalizeToRange01( float value, float min, float max ) +{ + return clamp01( normalizeToRange( value, min, max ) ); +} + +float map( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange( value, inMin, inMax ) ); +} + +float mapClamped( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange01( value, inMin, inMax ) ); +} + +float random( vec2 uv ) +{ + return fract( sin( dot( uv.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453123 ); +} + +vec2 random_v2( vec2 uv ) +{ + uv = vec2 + ( + dot(uv, vec2( 127.1,311.7 ) ), + dot(uv, vec2( 269.5,183.3 ) ) + ); + + return -1.0 + 2.0 * fract( sin( uv ) * 43758.5453123 ); +} + + +vec3 random_v3( vec3 uvw ) +{ + + uvw = vec3( dot(uvw, vec3(127.1,311.7, 513.7) ), + dot(uvw, vec3(269.5,183.3, 396.5) ), + dot(uvw, vec3(421.3,314.1, 119.7) ) ); + + return -1.0 + 2.0 * fract(sin(uvw) * 43758.5453123); +} + +float perlin(vec2 uv) +{ + vec2 uv_index = floor(uv); + vec2 uv_fract = fract(uv); + + vec2 blur = smoothstep(0.0, 1.0, uv_fract); + + return mix( mix( dot( random_v2(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), + dot( random_v2(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), + mix( dot( random_v2(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), + dot( random_v2(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) + 0.5; +} + +float mirrorValue( float x ) +{ + float t = mod( x, 2.0 ); + return ( t <= 1.0 ) ? t : 2.0 - t; +} + +vec2 mirrorUV( vec2 uv ) +{ + return vec2( mirrorValue( uv.x ), mirrorValue( uv.y ) ); +} + + + + + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( rgba16f, set = 0, binding = 0 ) +uniform image2D inputImage; + +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + +layout( set = 2, binding = 0 ) +uniform sampler2D distortionTexture; + +layout( set = 3, binding = 0 ) +uniform sampler2D maskTexture; + +layout( push_constant, std430 ) +uniform Parameters +{ + vec4 tilingOffsetDistortion; + vec4 tilingOffsetMask; + vec4 pad0; + vec4 pad1; + + float distortionAmount; + float blendAmount; + float redScale; + float greenScale; + + float blueScale; + float steps; + float smear; + float distortionConversion; + + float maskConversion; + float p0; + float p1; + float p2; + +} parameters; + + +vec4 sampleChromatic( vec2 uv, vec2 dir, ivec2 size, int steps, vec3 shifts, float smear ) +{ + vec4 combinedColor = vec4( 0.0 ); + + float weights = 0.0; + + for ( int i = -steps; i <= steps; i++ ) + { + float t = float( i ) / float( steps ); + float w = 1.0 - abs( t ); + vec2 stepDir = dir * pow( smear, t ); + + vec2 rUV = uv + stepDir * shifts.r; + rUV = mirrorUV( rUV ); + + vec2 gUV = uv + stepDir * shifts.g; + gUV = mirrorUV( gUV ); + + vec2 bUV = uv + stepDir * shifts.b; + bUV = mirrorUV( bUV ); + + vec4 colorR = imageLoad( inputImage, ivec2( rUV * size ) ); + vec4 colorG = imageLoad( inputImage, ivec2( gUV * size ) ); + vec4 colorB = imageLoad( inputImage, ivec2( bUV * size ) ); + + combinedColor.r += colorR.r * w; + combinedColor.g += colorG.g * w; + combinedColor.b += colorB.b * w; + combinedColor.a += colorG.a * w; + + weights += w; + } + + combinedColor /= weights; + + return combinedColor; +} + + +void main( ) +{ + ivec2 size = imageSize( inputImage ); + ivec2 texel_coord = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( texel_coord, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( texel_coord ) + 0.5 ) / vec2( size ); + + vec4 direction = texture( distortionTexture, uv * parameters.tilingOffsetDistortion.xy + parameters.tilingOffsetDistortion.zw ); + vec4 mask = texture( maskTexture, uv * parameters.tilingOffsetMask.xy + parameters.tilingOffsetMask.zw ); + + direction = colorSpaceConversion( direction, int( parameters.distortionConversion ) ); + mask = colorSpaceConversion( mask, int( parameters.maskConversion ) ); + + vec2 dir = direction.xy * 2.0 - 1.0; + + vec2 uvOffset = dir * mask.r * direction.z; + vec3 distortion = vec3( parameters.redScale, parameters.greenScale, parameters.blueScale ) * parameters.distortionAmount; + + int stepsI = min( 10, int( parameters.steps ) ); + + vec4 originalColor = imageLoad( inputImage, texel_coord ); + vec4 color = originalColor; + + color = sampleChromatic( uv, uvOffset, size, stepsI, distortion, parameters.smear ); + + + color = mix( originalColor, color, parameters.blendAmount * 1.0 ); + imageStore( outputImage, texel_coord, color ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/TextureDistortion.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/TextureDistortion.glsl.import new file mode 100644 index 0000000..547e250 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/TextureDistortion.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://qo8ldlgiskvs" +path="res://.godot/imported/TextureDistortion.glsl-7fb2b361cd028c8732ecb6bdf2295e96.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Distortion/TextureDistortion/TextureDistortion.glsl" +dest_files=["res://.godot/imported/TextureDistortion.glsl-7fb2b361cd028c8732ecb6bdf2295e96.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/CEG_BufferTexture.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/CEG_BufferTexture.cs index f829841..b4e765e 100644 --- a/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/CEG_BufferTexture.cs +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/CEG_BufferTexture.cs @@ -96,6 +96,11 @@ namespace Rokojori return this; } + public CEG_TextureCreator GetCreator() + { + return _creator; + } + List _connectedSlots = new List(); public void SetConnected( CompositorEffectGraphTextureSlot slot ) diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/CEG_ImageProcessor.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/CEG_ImageProcessor.cs index 056c7d8..f5ee37d 100644 --- a/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/CEG_ImageProcessor.cs +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/CEG_ImageProcessor.cs @@ -29,9 +29,9 @@ namespace Rokojori imageProcessorBefore.output.ConnectTo( output ); } - public void AddTextureSlotInput( RDGraphTextureSlotInput inputSlot ) + public void AddTextureSlotInput( RDGraphTextureSlotInput inputSlot, CompositorEffectGraphTextureSlot slot = null ) { - var slot = new CompositorEffectGraphTextureSlot( this ); + slot = slot != null ? slot : new CompositorEffectGraphTextureSlot( this ); _textureSlots.Add( slot ); inputSlot.ConnectTo( slot ); diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_BlendModeBase.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_BlendModeBase.cs new file mode 100644 index 0000000..ef945c3 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_BlendModeBase.cs @@ -0,0 +1,37 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public abstract class RG_BlendModeBase:RDShaderProcessor + { + public readonly CompositorEffectGraphTextureSlot top; + public readonly CompositorEffectGraphTextureSlot mask; + public readonly CompositorEffectGraphTextureSlot bottom; + public readonly CompositorEffectGraphTextureSlot output; + + public abstract RG_BlendModeType GetBlendModeType(); + + + public RG_BlendModeBase( RDGraph graph, string shaderPath ):base( graph, shaderPath ) + { + top = new CompositorEffectGraphTextureSlot( this ); + mask = new CompositorEffectGraphTextureSlot( this ); + bottom = new CompositorEffectGraphTextureSlot( this ); + output = new CompositorEffectGraphTextureSlot( this ); + + _textureSlots.AddRange( [ top, mask, bottom, output ] ); + } + + + public void SetTextureSlotInputs( RDGraphTextureSlotInput topSlot, RDGraphTextureSlotInput maskSlot, RDGraphTextureSlotInput bottomSlot, RDGraphTextureSlotInput outputSlot ) + { + topSlot.ConnectTo( top ); + maskSlot.ConnectTo( mask ); + bottomSlot.ConnectTo( bottom ); + outputSlot.ConnectTo( output ); + } + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_BlendModeBase.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_BlendModeBase.cs.uid new file mode 100644 index 0000000..f253792 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_BlendModeBase.cs.uid @@ -0,0 +1 @@ +uid://qurvdwca8skm diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_ImageTexture.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_ImageTexture.cs index 567b253..8919fc3 100644 --- a/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_ImageTexture.cs +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Generic/RG_ImageTexture.cs @@ -35,6 +35,21 @@ namespace Rokojori _texture = texture; } + public void SetImageTexture( Texture2D texture2D, bool sRGB = true ) + { + if ( texture2D == null ) + { + // RJLog.Log( "Set Texture: no texture" ); + _texture = null; + return; + } + + var rdTextureRID = RenderingServer.Singleton.TextureGetRdTexture( texture2D.GetRid(), sRGB ); + + // RJLog.Log( "Set Texture:", texture2D.GetRid(), ">>", rdTextureRID ); + SetImageTexture( new RDTexture( graph.context, rdTextureRID ) ); + } + public override void Process() { diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/ChromaticBloom.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/ChromaticBloom.glsl new file mode 100644 index 0000000..ec230b5 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/ChromaticBloom.glsl @@ -0,0 +1,216 @@ +#[compute] +#version 450 + +float clamp01( float value ) +{ + return clamp( value, 0.0, 1.0 ); +} + +float normalizeToRange( float value, float min, float max ) +{ + return ( value - min ) / ( max - min ); +} + +float normalizeToRange01( float value, float min, float max ) +{ + return clamp01( normalizeToRange( value, min, max ) ); +} + +float map( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange( value, inMin, inMax ) ); +} + +float mapClamped( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange01( value, inMin, inMax ) ); +} + +float random( vec2 uv ) +{ + return fract( sin( dot( uv.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453123 ); +} + +vec2 random_v2( vec2 uv ) +{ + uv = vec2 + ( + dot(uv, vec2( 127.1,311.7 ) ), + dot(uv, vec2( 269.5,183.3 ) ) + ); + + return -1.0 + 2.0 * fract( sin( uv ) * 43758.5453123 ); +} + + +vec3 random_v3( vec3 uvw ) +{ + + uvw = vec3( dot(uvw, vec3(127.1,311.7, 513.7) ), + dot(uvw, vec3(269.5,183.3, 396.5) ), + dot(uvw, vec3(421.3,314.1, 119.7) ) ); + + return -1.0 + 2.0 * fract(sin(uvw) * 43758.5453123); +} + +float perlin(vec2 uv) +{ + vec2 uv_index = floor(uv); + vec2 uv_fract = fract(uv); + + vec2 blur = smoothstep(0.0, 1.0, uv_fract); + + return mix( mix( dot( random_v2(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), + dot( random_v2(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), + mix( dot( random_v2(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), + dot( random_v2(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) + 0.5; +} + +float mirrorValue( float x ) +{ + float t = mod( x, 2.0 ); + return ( t <= 1.0 ) ? t : 2.0 - t; +} + +vec2 mirrorUV( vec2 uv ) +{ + return vec2( mirrorValue( uv.x ), mirrorValue( uv.y ) ); +} + + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +layout( set = 0, binding = 0 ) +uniform sampler2D inputImage; + +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + + + +layout( push_constant, std430 ) +uniform Parameters +{ + float amount; + float redScale; + float greenScale; + float blueScale; + + float steps; + float smear; + float distortionAmount; + float distortionAngle; + + float uvOffsetX; + float uvOffsetY; + float p1; + float p2; + +} parameters; + +vec4 sampleChromatic( vec2 uv, vec2 dir, ivec2 size, int steps, vec3 shifts, float smear ) +{ + vec4 combinedColor = vec4( 0.0 ); + + float weights = 0.0; + + for ( int i = -steps; i <= steps; i++ ) + { + float t = float( i ) / float( steps ); + float w = 1.0 - abs( t ); + vec2 stepDir = dir * pow( smear, t ); + + vec2 rUV = uv + stepDir * shifts.r; + rUV = mirrorUV( rUV ); + + vec2 gUV = uv + stepDir * shifts.g; + gUV = mirrorUV( gUV ); + + vec2 bUV = uv + stepDir * shifts.b; + bUV = mirrorUV( bUV ); + + vec4 colorR = textureLod( inputImage, rUV, 0 ); + vec4 colorG = textureLod( inputImage, gUV, 0 ); + vec4 colorB = textureLod( inputImage, bUV, 0 ); + + combinedColor.r += colorR.r * w; + combinedColor.g += colorG.g * w; + combinedColor.b += colorB.b * w; + combinedColor.a += colorG.a * w; + + weights += w; + } + + combinedColor /= weights; + + return combinedColor; +} + + + +vec2 rotate( vec2 uv, float angle ) +{ + float s = sin( angle ); + float c = cos( angle ); + + + float x = uv.x; + float y = uv.y; + + uv.x = c * x - s * y; + uv.y = s * x + c * y; + + return uv; +} + +float rgb2luma( vec3 rgb ) +{ + return sqrt( dot( rgb, vec3( 0.299, 0.587, 0.114 ) ) ); +} + + +void main() +{ + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + ivec2 size = imageSize( outputImage ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( xy ) + 0.5 ) / vec2( size ); + + vec3 distortion = vec3( parameters.redScale, parameters.greenScale, parameters.blueScale ) * parameters.distortionAmount; + + int stepsI = min( 32, int( parameters.steps ) ); + + vec4 originalColor = imageLoad( outputImage, xy ); + + float angle = parameters.distortionAngle; + vec2 ratio = vec2( 1.0, float( size.y ) / float( size.x ) ); + + vec2 uvDir = vec2( cos( angle ), sin( angle ) ); + + + + vec2 uvOffset = vec2( parameters.uvOffsetX, parameters.uvOffsetY ); + + uvOffset += -uvDir * parameters.distortionAmount * parameters.smear; + + vec4 color = sampleChromatic( uv + uvOffset, uvDir, size, stepsI, distortion, parameters.smear ); + + // float luma = rgb2luma( color.rgb ); + // float lumaScale = max( 0.0, luma - parameters.lumaTreshold ) * parameters.lumaScale; + // lumaScale = min( lumaScale, parameters.lumaClamp ) * parameters.lumaStrength; + + // vec3 lumaTint = vec3( parameters.lumaTintR, parameters.lumaTintG, parameters.lumaTintB ); + + // vec4 blendedColor = originalColor; + // blendedColor.rgb += color.rgb * lumaTint * lumaScale * parameters.amount; + + vec4 blendedColor = originalColor; + blendedColor.rgb += color.rgb * parameters.amount; + + imageStore( outputImage, xy, blendedColor ); +} diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/ChromaticBloom.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/ChromaticBloom.glsl.import new file mode 100644 index 0000000..2a03bd8 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/ChromaticBloom.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://crn8mida0pto1" +path="res://.godot/imported/ChromaticBloom.glsl-069da19beb0ed2cc51d7181820a0e4fe.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/ChromaticBloom.glsl" +dest_files=["res://.godot/imported/ChromaticBloom.glsl-069da19beb0ed2cc51d7181820a0e4fe.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/RG_ChromaticBloom.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/RG_ChromaticBloom.cs new file mode 100644 index 0000000..9b0df0a --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/RG_ChromaticBloom.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_ChromaticBloom:CEG_ImageProcessor + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Glow/ChromaticBloom/ChromaticBloom.glsl" ); + + public RG_ChromaticBloom( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/RG_ChromaticBloom.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/RG_ChromaticBloom.cs.uid new file mode 100644 index 0000000..da036d8 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ChromaticBloom/RG_ChromaticBloom.cs.uid @@ -0,0 +1 @@ +uid://d1riqmx5d6s6l diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/ExtractGlow.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/ExtractGlow.glsl new file mode 100644 index 0000000..c49c13d --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/ExtractGlow.glsl @@ -0,0 +1,90 @@ +#[compute] +#version 450 + +float clamp01( float value ) +{ + return clamp( value, 0.0, 1.0 ); +} + +float normalizeToRange( float value, float min, float max ) +{ + return ( value - min ) / ( max - min ); +} + +float normalizeToRange01( float value, float min, float max ) +{ + return clamp01( normalizeToRange( value, min, max ) ); +} + +float map( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange( value, inMin, inMax ) ); +} + +float mapClamped( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange01( value, inMin, inMax ) ); +} + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( set = 0, binding = 0 ) +uniform sampler2D inputImage; + +layout( rgba16, set = 1, binding = 0 ) +uniform restrict writeonly image2D outputImage; + +layout( push_constant, std430 ) +uniform Parameters +{ + float lumaWeightR; + float lumaWeightG; + float lumaWeightB; + float lumaPower; + + float inputRangeMin; + float inputRangeMax; + float normalizationPower; + float outputRangeMin; + + float outputRangeMax; + float desaturation; + float tintR; + float tintG; + + float tintB; + float p0; + float p1; + float p2; + +} parameters; + +void main() +{ + ivec2 size = imageSize( outputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( xy ) + vec2( 0.5 ) ) / vec2( size ); + + + vec4 color = texture( inputImage, uv ); + + vec3 lumaWeight = vec3( parameters.lumaWeightR, parameters.lumaWeightG, parameters.lumaWeightB ); + float luma = pow( dot( lumaWeight, color.rgb ), parameters.lumaPower ); + + luma = normalizeToRange01( luma, parameters.inputRangeMin, parameters.inputRangeMax ); + luma = pow( luma, parameters.normalizationPower ); + luma = mix( parameters.outputRangeMin, parameters.outputRangeMax, luma ); + + color.rgb = mix( color.rgb, vec3( dot( color.rgb, vec3( 1.0/3.0 ) ) ), parameters.desaturation ); + + color.rgb = normalize( color.rgb ); + color.rgb = color.rgb * luma * vec3( parameters.tintR, parameters.tintG, parameters.tintB ); + + imageStore( outputImage, xy, color ); +} diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/ExtractGlow.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/ExtractGlow.glsl.import new file mode 100644 index 0000000..f80b2e1 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/ExtractGlow.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://biptyoinlwq13" +path="res://.godot/imported/ExtractGlow.glsl-66c4b14c99994f0ce77a9c7b94fbba84.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/ExtractGlow.glsl" +dest_files=["res://.godot/imported/ExtractGlow.glsl-66c4b14c99994f0ce77a9c7b94fbba84.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/RG_ExtractGlow.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/RG_ExtractGlow.cs new file mode 100644 index 0000000..c84d83d --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/RG_ExtractGlow.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_ExtractGlow:CEG_ImageProcessor + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Glow/ExtractGlow/ExtractGlow.glsl" ); + + public RG_ExtractGlow( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/RG_ExtractGlow.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/RG_ExtractGlow.cs.uid new file mode 100644 index 0000000..2e99cae --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/ExtractGlow/RG_ExtractGlow.cs.uid @@ -0,0 +1 @@ +uid://ehrnffckqsiy diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/GlowAdd.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/GlowAdd.glsl new file mode 100644 index 0000000..a9f223e --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/GlowAdd.glsl @@ -0,0 +1,124 @@ +#[compute] +#version 450 + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( set = 0, binding = 0 ) +uniform sampler2D inputImage; + +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + + +layout( push_constant, std430 ) +uniform Parameters +{ + float intensity; + float noise; + float kernelOffset; + float kernelRadius; + + float lumaTreshold; + float lumaScale; + float p2; + float p3; + +} parameters; + + +float randomFloat( vec2 uv ) +{ + return fract( sin( dot( uv.xy, vec2( 12.9898,78.233 ) ) ) * 43758.5453123 ); +} + +vec2 random( vec2 uv ) +{ + float x = randomFloat( uv ); + float y = randomFloat( uv + vec2( 10002, -23589 ) ); + + return vec2( x, y ) * 2.0 - vec2( 1.0, 1.0 ); +} + + +float fastGaussianWeight( vec2 p, float radius ) +{ + float r = length( p ) / radius; + return max( 0.0, 1.0 - r * r ); +} + +void main( ) +{ + ivec2 size = imageSize( outputImage ); + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec4 color = vec4( 0.0 ); + + int kernelRadius = int( parameters.kernelRadius ); + int kernelOffset = int( parameters.kernelOffset ); + + vec2 toUV = vec2( 1.0 ) / vec2( size ); + + float weights = 0.0; + + if ( parameters.noise > 0.0 ) + { + for ( int x = -kernelRadius; x <= kernelRadius; x++ ) + { + for ( int y = -kernelRadius; y <= kernelRadius; y++ ) + { + ivec2 kernelXYOffset = ivec2( x, y ) * kernelOffset; + ivec2 kernelXY = xy + kernelXYOffset; + + kernelXY += ivec2( random( kernelXY ) * parameters.noise ); + + kernelXY.x = clamp( kernelXY.x, 0, size.x - 1 ); + kernelXY.y = clamp( kernelXY.y, 0, size.y - 1 ); + + float weight = fastGaussianWeight( vec2( kernelOffset ), kernelRadius ); + color += ( texture( inputImage, kernelXY * toUV ) ) * weight; + weights += weight; + + } + } + } + else + { + for ( int x = -kernelRadius; x <= kernelRadius; x++ ) + { + for ( int y = -kernelRadius; y <= kernelRadius; y++ ) + { + ivec2 kernelXYOffset = ivec2( x, y ) * kernelOffset; + ivec2 kernelXY = xy + kernelXYOffset; + + kernelXY.x = clamp( kernelXY.x, 0, size.x - 1 ); + kernelXY.y = clamp( kernelXY.y, 0, size.y - 1 ); + + float weight = fastGaussianWeight( vec2( kernelOffset ), kernelRadius ); + color += ( texture( inputImage, kernelXY * toUV ) ) * weight; + weights += weight; + } + } + } + + + color /= weights; + + vec4 originalColor = imageLoad( outputImage, xy ); + + vec4 mixedColor = originalColor; + + float luma = length( color.rgb ); + + float lumaAmount = max( luma - parameters.lumaTreshold, 0.0 ) * parameters.lumaScale; + + mixedColor.rgb += color.rgb * lumaAmount * parameters.intensity; + + // mixedColor = color; + + imageStore( outputImage, xy, mixedColor ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/GlowAdd.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/GlowAdd.glsl.import new file mode 100644 index 0000000..15cf38a --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/GlowAdd.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://vkg1ui37j8jd" +path="res://.godot/imported/GlowAdd.glsl-b92449272610ba095ee75cdc813d93c4.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/GlowAdd.glsl" +dest_files=["res://.godot/imported/GlowAdd.glsl-b92449272610ba095ee75cdc813d93c4.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/RG_GlowAdd.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/RG_GlowAdd.cs new file mode 100644 index 0000000..b05b953 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/RG_GlowAdd.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_GlowAdd:CEG_ImageProcessor + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Glow/GlowAdd/GlowAdd.glsl" ); + + public RG_GlowAdd( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/RG_GlowAdd.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/RG_GlowAdd.cs.uid new file mode 100644 index 0000000..02cdcd6 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/GlowAdd/RG_GlowAdd.cs.uid @@ -0,0 +1 @@ +uid://bc2w2dv8gi70x diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/RG_Streaks.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/RG_Streaks.cs new file mode 100644 index 0000000..15280a7 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/RG_Streaks.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_Streaks:CEG_ImageProcessor + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Glow/Streaks/Streaks.glsl" ); + + public RG_Streaks( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/RG_Streaks.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/RG_Streaks.cs.uid new file mode 100644 index 0000000..1a1f74e --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/RG_Streaks.cs.uid @@ -0,0 +1 @@ +uid://by32rnm5qqj60 diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/Streaks.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/Streaks.glsl new file mode 100644 index 0000000..3d616ac --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/Streaks.glsl @@ -0,0 +1,136 @@ +#[compute] +#version 450 + +/* + +The original streaks code was taken from Karl Bittner's streak implementation for his lens-flare-code: +https://github.com/kb173/godot-procedural-lens-flare + + +Licens of the code: + +MIT License + +Copyright (c) 2025 Karl Bittner + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +// Adapted from https://chrisoat.com/papers/Oat-ScenePostprocessing.pdf + + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +layout( set = 0, binding = 0 ) +uniform sampler2D inputImage; + +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + + +layout( push_constant, std430 ) +uniform Parameters +{ + vec2 direction; + vec2 attenuationAmount; + + vec2 samplesIteration; + vec2 lumaOffsetScale; + + vec2 streaksBlur; + vec2 rotationDesaturation; + + +} parameters; + +float mapClamped( float value, float inMin, float inMax, float outMin, float outMax ) +{ + float n = ( value - inMin ) / ( inMax - inMin ); + + n = clamp( n, 0.0, 1.0 ); + + return mix( outMin, outMax, n ); +} + +vec2 rotate( vec2 uv, float angle ) +{ + float s = sin( angle ); + float c = cos( angle ); + + + float x = uv.x; + float y = uv.y; + + uv.x = c * x - s * y; + uv.y = s * x + c * y; + + return uv; +} + + +void main() +{ + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + ivec2 size = imageSize( outputImage ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec4 color = vec4( 0.0, 0.0, 0.0, 1.0 ); + + int samples = int( parameters.samplesIteration.x ); + + float b = pow( samples, parameters.samplesIteration.y ); + + int numStreaks = int( parameters.streaksBlur.x ); + + float blurScale = parameters.streaksBlur.y; + + float streamAmount = 1.0 / float( numStreaks ); + float angleOffset = streamAmount * 6.28318530; + + float rotationOffset = parameters.rotationDesaturation.x; + float desaturation = parameters.rotationDesaturation.y; + + vec2 uv = ( vec2( xy ) + vec2( 0.5 ) ) / vec2( size ); + + for ( int j = 0; j < numStreaks; j++ ) + { + vec2 direction = rotate( parameters.direction, float( j ) * angleOffset + rotationOffset ) ; + direction /= vec2( size ); + + for ( int i = 0; i < samples; i++ ) + { + float weight = pow( parameters.attenuationAmount.x, b * ( i + 1 ) ); + + vec2 offset = vec2( direction * b * i ); + + vec3 sampledColor = texture( inputImage, uv + offset ).rgb; + + float luma = length( sampledColor ); + + float lumaAmount = max( luma - parameters.lumaOffsetScale.x, 0.0 ) * parameters.lumaOffsetScale.y; + + + sampledColor = mix( sampledColor * lumaAmount, vec3( lumaAmount ), desaturation ); + + color.rgb += clamp( weight, 0.0, 1.0) * sampledColor; + } + + } + + vec4 originalColor = texture( inputImage, uv ); + + color.rgb = originalColor.rgb + color.rgb * parameters.attenuationAmount.y; + + // color = mix( originalColor, color, parameters.attenuationAmount.y ); + + imageStore( outputImage, xy, color); +} diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/Streaks.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/Streaks.glsl.import new file mode 100644 index 0000000..6ff9411 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/Streaks.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://b1irhdo5cmt07" +path="res://.godot/imported/Streaks.glsl-5334586b39dfb88b095e8e58377cc3ef.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Glow/Streaks/Streaks.glsl" +dest_files=["res://.godot/imported/Streaks.glsl-5334586b39dfb88b095e8e58377cc3ef.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/ChannelPixelation.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/ChannelPixelation.glsl new file mode 100644 index 0000000..19434d3 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/ChannelPixelation.glsl @@ -0,0 +1,201 @@ +#[compute] +#version 450 + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc" + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +layout(rgba16f, set = 0, binding = 0) +uniform image2D inputImage; + +layout(rgba16f, set = 1, binding = 0) +uniform image2D outputImage; + +layout(push_constant, std430) +uniform Parameters +{ + vec4 noiseSeed; + + float pixelSizeX; + float pixelSizeY; + float amount; + float channel; + + float noiseAmount; + float noiseScale; + float offsetX; + float offsetY; + +} parameters; + +int quantize( int value, int quantization ) +{ + return ( value / quantization ) * quantization; +} + +ivec2 quantize( ivec2 value, ivec2 quantization ) +{ + return ivec2( quantize( value.x, quantization.x ), quantize( value.y, quantization.y ) ); +} + +int mirrorValue( int x, int size ) +{ + int t = x % ( size * 2 ); + return t < size ? t : ( 2 * size ) - t; +} + +ivec2 mirrorUV( ivec2 uv, ivec2 size ) +{ + return ivec2( mirrorValue( uv.x, size.x ), mirrorValue( uv.y, size.y ) ); +} + + +float clamp01( float value ) +{ + return clamp( value, 0.0, 1.0 ); +} + +float normalizeToRange( float value, float min, float max ) +{ + return ( value - min ) / ( max - min ); +} + +float normalizeToRange01( float value, float min, float max ) +{ + return clamp01( normalizeToRange( value, min, max ) ); +} + +float map( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange( value, inMin, inMax ) ); +} + +float mapClamped( float value, float inMin, float inMax, float outMin, float outMax ) +{ + return mix( outMin, outMax, normalizeToRange01( value, inMin, inMax ) ); +} + +float random( vec2 uv ) +{ + return fract( sin( dot( uv.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453123 ); +} + +vec2 random_v2( vec2 uv ) +{ + uv = vec2 + ( + dot(uv, vec2( 127.1,311.7 ) ), + dot(uv, vec2( 269.5,183.3 ) ) + ); + + return -1.0 + 2.0 * fract( sin( uv ) * 43758.5453123 ); +} + + +vec3 random_v3( vec3 uvw ) +{ + + uvw = vec3( dot(uvw, vec3(127.1,311.7, 513.7) ), + dot(uvw, vec3(269.5,183.3, 396.5) ), + dot(uvw, vec3(421.3,314.1, 119.7) ) ); + + return -1.0 + 2.0 * fract(sin(uvw) * 43758.5453123); +} + +float perlin(vec2 uv) +{ + vec2 uv_index = floor(uv); + vec2 uv_fract = fract(uv); + + vec2 blur = smoothstep(0.0, 1.0, uv_fract); + + return mix( mix( dot( random_v2(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), + dot( random_v2(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), + mix( dot( random_v2(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), + dot( random_v2(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) + 0.5; +} + +float mirrorValue( float x ) +{ + float t = mod( x, 2.0 ); + return ( t <= 1.0 ) ? t : 2.0 - t; +} + +vec2 mirrorUV( vec2 uv ) +{ + return vec2( mirrorValue( uv.x ), mirrorValue( uv.y ) ); +} + + +void main() +{ + ivec2 xy = ivec2( gl_GlobalInvocationID.xy ); + ivec2 size = imageSize( outputImage ); + + if ( any( greaterThanEqual( xy, size ) ) ) + { + return; + } + + vec4 originalColor = imageLoad( inputImage, xy ); + + vec2 uv = ( vec2( xy ) + 0.5 ) / vec2( size ); + + int initialPixelsX = int( parameters.pixelSizeX ); + int initialPixelsY = int( parameters.pixelSizeY ); + + ivec2 pixelXY = quantize( xy, ivec2( initialPixelsX, initialPixelsY ) ); + + float noiseX = perlin( pixelXY * parameters.noiseScale + vec2( parameters.noiseSeed.x, parameters.noiseSeed.y ) ); + float noiseY = perlin( pixelXY * parameters.noiseScale + vec2( parameters.noiseSeed.z, parameters.noiseSeed.w ) ); + + noiseX = mix( 1.0, noiseX, parameters.noiseAmount ); + noiseY = mix( 1.0, noiseY, parameters.noiseAmount ); + + int pixelsX = int( parameters.pixelSizeX * noiseX ); + int pixelsY = int( parameters.pixelSizeY * noiseY ); + + ivec2 off = ivec2( parameters.offsetX * pixelsX, parameters.offsetY * pixelsY ); + + pixelXY = quantize( xy + off, ivec2( pixelsX, pixelsY ) ); + pixelXY = mirrorUV( pixelXY, size ); + + vec4 color = imageLoad( inputImage, pixelXY ); + + int colorChannel = int( parameters.channel ); + + float colorScale = 1.0; + float colorScale2 = 1.0; + + int editingChanngel = colorChannel; + + if ( colorChannel != 7 && colorChannel >= 3 ) + { + editingChanngel -= 3; + + colorScale = getRGBScale( color ); + colorScale2 = getRGBScale( originalColor ); + + color = RGBtoHSL( color, colorScale ); + originalColor = RGBtoHSL( originalColor, colorScale2 ); + } + + if ( colorChannel != 7 ) + { + float value = getRGBByIndex( color.rgb, editingChanngel ); + color.rgb = setRGBByIndex( originalColor.rgb, editingChanngel, value ); + } + + if ( colorChannel != 7 && colorChannel >= 3 ) + { + color = HSLtoRGB( color, colorScale ); + originalColor = HSLtoRGB( originalColor, colorScale2 ); + } + + + + color = mix( originalColor, color, parameters.amount ); + + + imageStore( outputImage, xy, color); +} diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/ChannelPixelation.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/ChannelPixelation.glsl.import new file mode 100644 index 0000000..888ea9f --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/ChannelPixelation.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://c1tkolygjt7j7" +path="res://.godot/imported/ChannelPixelation.glsl-dfd46a242b42074c05bed80c9eb5508e.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/ChannelPixelation.glsl" +dest_files=["res://.godot/imported/ChannelPixelation.glsl-dfd46a242b42074c05bed80c9eb5508e.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/RG_ChannelPixelation.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/RG_ChannelPixelation.cs new file mode 100644 index 0000000..ab04599 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/RG_ChannelPixelation.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class RG_ChannelPixelation:CEG_ImageProcessor + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Noise/ChannelPixelation/ChannelPixelation.glsl" ); + + public RG_ChannelPixelation( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/RG_ChannelPixelation.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/RG_ChannelPixelation.cs.uid new file mode 100644 index 0000000..d3bfb73 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Noise/ChannelPixelation/RG_ChannelPixelation.cs.uid @@ -0,0 +1 @@ +uid://b3i8ld2ccr20t diff --git a/Runtime/Rendering/RenderGraph/RDGraph.cs b/Runtime/Rendering/RenderGraph/RDGraph.cs index 4080eca..6a9d097 100644 --- a/Runtime/Rendering/RenderGraph/RDGraph.cs +++ b/Runtime/Rendering/RenderGraph/RDGraph.cs @@ -51,6 +51,11 @@ namespace Rokojori _processOrder.AddRange( order ); } + public void AddToProcessOrder( params RGGraphProcessor[] additional ) + { + _processOrder.AddRange( additional ); + } + public void ProcessForView() { diff --git a/Runtime/Rendering/RenderGraph/RDGraphTextureSlot.cs b/Runtime/Rendering/RenderGraph/RDGraphTextureSlot.cs index 11794bc..14ff515 100644 --- a/Runtime/Rendering/RenderGraph/RDGraphTextureSlot.cs +++ b/Runtime/Rendering/RenderGraph/RDGraphTextureSlot.cs @@ -21,6 +21,11 @@ namespace Rokojori protected RDTexture _texture; + public void UseSampler( RenderingDevice.SamplerFilter filter = RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode repeatMode = RenderingDevice.SamplerRepeatMode.Repeat ) + { + sampler = graph.context.Sampler( filter, repeatMode ); + } + public RDTexture GetTexture() { return _texture; diff --git a/Runtime/Rendering/RenderGraph/RDShaderProcessor.cs b/Runtime/Rendering/RenderGraph/RDShaderProcessor.cs index 8cbf7c7..4b4d086 100644 --- a/Runtime/Rendering/RenderGraph/RDShaderProcessor.cs +++ b/Runtime/Rendering/RenderGraph/RDShaderProcessor.cs @@ -58,13 +58,31 @@ namespace Rokojori } public bool debugging = false; + + public bool hasCustomComputeSize = false; + public Vector2I customComputeSize = new Vector2I( 512, 512 ); + + public void SetCustomComputeSize( Vector2I size ) + { + hasCustomComputeSize = true; + customComputeSize = size; + } public override void Process() { var context = graph.context; context.Clear(); - context.CalculateSceneComputeGroups( _groupSize ); + + if ( hasCustomComputeSize ) + { + context.CalculateComputeGroups( _groupSize, customComputeSize ); + } + else + { + context.CalculateSceneComputeGroups( _groupSize ); + } + context.SetShaderAndPipeline( _shader, _pipeline ); context.Verbose( GetType().Name, "Setting texture uniforms", _textureSlots.Count ); diff --git a/Runtime/Rendering/RenderingManager.cs b/Runtime/Rendering/RenderingManager.cs index 46672fc..139e6f5 100644 --- a/Runtime/Rendering/RenderingManager.cs +++ b/Runtime/Rendering/RenderingManager.cs @@ -27,17 +27,23 @@ namespace Rokojori public Callable updateShadersButton => Callable.From( ()=> { - shaders.ForEach( - ( s )=> - { - var code = RenderingServer.Singleton.ShaderGetCode( s.GetRid() ); - code += "\n "; - - RenderingServer.Singleton.ShaderSetCode( s.GetRid(), code ); - } - ); + UpdateShaders(); } ); + + void UpdateShaders() + { + shaders.ForEach( + ( s )=> + { + var code = RenderingServer.Singleton.ShaderGetCode( s.GetRid() ); + code += "\n "; + + RenderingServer.Singleton.ShaderSetCode( s.GetRid(), code ); + } + ); + } + [Export] public Shader[] shaders; @@ -126,6 +132,9 @@ namespace Rokojori [Export] public bool ensureGlobalShaderPropertiesOnReady = true; + [Export] + public bool updateShadersOnReady = true; + [Export] public RenderingManagerData data = new RenderingManagerData(); @@ -133,12 +142,15 @@ namespace Rokojori public override void _Ready() { - if ( ! ensureGlobalShaderPropertiesOnReady ) + if ( ensureGlobalShaderPropertiesOnReady ) { - return; + EnsureGlobalShaderProperties(); } - EnsureGlobalShaderProperties(); + if ( updateShadersOnReady ) + { + UpdateShaders(); + } } diff --git a/Runtime/Shading/Library/Colors.gdshaderinc b/Runtime/Shading/Library/Colors.gdshaderinc index f6f797c..a046d7a 100644 --- a/Runtime/Shading/Library/Colors.gdshaderinc +++ b/Runtime/Shading/Library/Colors.gdshaderinc @@ -1,7 +1,21 @@ // #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc" -#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" +float _COLORS_mapClamped( float value, float inMin, float inMax, float outMin, float outMax ) +{ + float n = ( value - inMin ) / ( inMax - inMin ); + + n = clamp( n, 0.0, 1.0 ); + + return mix( outMin, outMax, n ); +} + +float _COLORS_triangle( float value ) +{ + float inverted = 1.0 - value; + + return min( value, inverted ) * 2.0; +} const float HCV_EPSILON = 1e-10; const float HSL_EPSILON = 1e-10; @@ -15,6 +29,15 @@ vec3 RGBtoHCV( vec3 rgb ) return vec3( H, C, Q.x ); } +float getRGBScale( vec3 rgb ) +{ + return max( 1.0, max( rgb.r, max( rgb.g, rgb.b ) ) ); +} + +float getRGBScale( vec4 rgb ) +{ + return getRGBScale( rgb.rgb ); +} vec3 RGBtoHSL( vec3 c ) { @@ -65,12 +88,64 @@ vec3 RGBtoHSL( vec3 c ) return vec3( h, s, l ); } +vec4 RGBtoHSL( vec4 c ) +{ + return vec4( RGBtoHSL( c.rgb ), c.a ); +} + +vec4 RGBtoHSL( vec4 c, float scale ) +{ + return vec4( RGBtoHSL( c.rgb / scale ), c.a ); +} + vec3 hueToRGB( float hue ) { float R = abs( hue * 6.0 - 3.0 ) - 1.0; float G = 2.0 - abs( hue * 6.0 - 2.0 ); float B = 2.0 - abs( hue * 6.0 - 4.0 ); return clamp( vec3( R,G,B ), 0, 1 ); +} + +float getRGBByIndex( vec3 rgb, int index ) +{ + return index == 0 ? rgb.r : index == 1 ? rgb.g : rgb.b; +} + + +vec3 changeRGBByIndex( vec3 rgb, int index, float change ) +{ + if ( index == 0 ) + { + rgb.r += change; + } + else if ( index == 1 ) + { + rgb.g += change; + } + else + { + rgb.b += change; + } + + return rgb; +} + +vec3 setRGBByIndex( vec3 rgb, int index, float value ) +{ + if ( index == 0 ) + { + rgb.r = value; + } + else if ( index == 1 ) + { + rgb.g = value; + } + else + { + rgb.b = value; + } + + return rgb; } vec3 HSLtoRGB( vec3 hsl ) @@ -85,6 +160,17 @@ vec3 HSLtoRGB( vec3 hsl ) return ( rgb - 0.5 ) * C + hsl.z; } +vec4 HSLtoRGB( vec4 c ) +{ + return vec4( HSLtoRGB( c.rgb ), c.a ); +} + +vec4 HSLtoRGB( vec4 c, float scale ) +{ + return vec4( HSLtoRGB( c.rgb ) * scale, c.a ); +} + + vec3 adjustHSL( vec3 color, vec3 hslAdjustment ) { vec3 hsl = RGBtoHSL( color ); @@ -101,6 +187,11 @@ vec3 SRGBtoLINEAR( vec3 sRGB ) return mix( pow( (sRGB + vec3( 0.055 )) * ( 1.0 / ( 1.0 + 0.055 )),vec3( 2.4 )),sRGB * ( 1.0 / 12.92 ),lessThan( sRGB,vec3( 0.04045 )) ); } +vec4 SRGBtoLINEAR( vec4 sRGB ) +{ + return vec4( SRGBtoLINEAR( sRGB.rgb ), sRGB.a ); +} + vec3 LINEARtoSRGB( vec3 linear ) { vec3 color = linear; @@ -108,6 +199,21 @@ vec3 LINEARtoSRGB( vec3 linear ) return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f))); } +vec4 LINEARtoSRGB( vec4 linear ) +{ + return vec4( LINEARtoSRGB( linear.rgb ), linear.a ); +} + +vec4 colorSpaceConversion( vec4 color, int mode ) +{ + if ( mode == 0 ) + { + return color; + } + + return mode == 1 ? LINEARtoSRGB( color ) : SRGBtoLINEAR( color ); +} + float modPolarDegrees( float value ) { return mod( value + 180.0, 360.0 ) - 180.0; @@ -150,13 +256,28 @@ vec3 shiftHSL360( vec3 hslWithH360, vec3 offset, float blendRadius ) float distanceToYellow = min( 1.0, abs( hslWithH360.x - 60.0 ) / blendRadius ); float distanceToBlue = min( 1.0, abs( hslWithH360.x - 240.0 ) / blendRadius ); - hslWithH360.x = changeHue360( hslWithH360.x, offset.x ); + hslWithH360.x = changeHue360( hslWithH360.x, offset.x * distanceToYellow * distanceToBlue ); hslWithH360.y = clamp( hslWithH360.y + offset.y, 0, 1 ); hslWithH360.z = clamp( hslWithH360.z + offset.z, 0, 1 ); return hslWithH360; } +float changeTemparature360( float h, float amount, float blendRadius ) +{ + float distanceToYellow = min( 1.0, abs( h - 60.0 ) / blendRadius ); + float distanceToBlue = min( 1.0, abs( h - 240.0 ) / blendRadius ); + + h = changeHue360( h, amount * distanceToYellow * distanceToBlue ); + + return h; +} + +float changeTemparature( float h, float amount, float blendRadius ) +{ + return changeTemparature360( h * 360.0, amount, blendRadius ) / 360.0; +} + vec3 shiftHSL( vec3 hsl, vec3 offset, float blendRadius ) { @@ -197,18 +318,18 @@ vec3 HSVtoRGB( vec3 c ) vec3 mix3( vec3 a, vec3 b, vec3 c, float t ) { - float weightA = mapClamped( t, 0, 0.5, 1, 0 ); - float weightB = triangle( t ); - float weightC = mapClamped( t, 0.5, 1, 0, 1 ); + float weightA = _COLORS_mapClamped( t, 0, 0.5, 1, 0 ); + float weightB = _COLORS_triangle( t ); + float weightC = _COLORS_mapClamped( t, 0.5, 1, 0, 1 ); return a * weightA + b * weightB + c * weightC; } vec4 mix3_v4( vec4 a, vec4 b, vec4 c, float t ) { - float weightA = mapClamped( t, 0, 0.5, 1, 0 ); - float weightB = triangle( t ); - float weightC = mapClamped( t, 0.5, 1, 0, 1 ); + float weightA = _COLORS_mapClamped( t, 0, 0.5, 1, 0 ); + float weightB = _COLORS_triangle( t ); + float weightC = _COLORS_mapClamped( t, 0.5, 1, 0, 1 ); return a * weightA + b * weightB + c * weightC; } @@ -240,9 +361,9 @@ vec4 premultipliedToStraightColor( vec4 color ) vec4 mixThreeColors( vec4 a, vec4 b, vec4 c, float t ) { - float wa = mapClamped( t, 0.0, 0.5, 1.0, 0.0 ); - float wb = triangle( t ); - float wc = mapClamped( t, 0.5, 1, 0.0, 1.0 ); + float wa = _COLORS_mapClamped( t, 0.0, 0.5, 1.0, 0.0 ); + float wb = _COLORS_triangle( t ); + float wc = _COLORS_mapClamped( t, 0.5, 1, 0.0, 1.0 ); return a * wa + b * wb + c * wc; } @@ -329,7 +450,7 @@ vec4 blendMode_alpha( vec4 bottom, vec4 top ) vec4 result = alpha > 0.0 ? vec4( color / alpha, alpha ) : vec4( color, 0 ); - result = clamp( result, 0, 1 ); + // result = clamp( result, 0, 1 ); return result; } @@ -546,7 +667,6 @@ vec4 blendMode_hue( vec4 bottom, vec4 top ) return top; } - return blendMode_alpha( bottom, vec4( blendFunction_hue( bottom.rgb, top.rgb ), top.a ) ); } @@ -568,16 +688,7 @@ vec4 blendMode_colorHSL( vec4 bottom, vec4 top ) return top; } - return blendMode_alpha( bottom, vec4( blendFunction_colorHSL( bottom.rgb, top.rgb ), top.a ) ); - // vec3 topHSL = RGBtoHSL( top.rgb ); - // vec3 bottomHSL = RGBtoHSL( bottom.rgb ); - - // vec3 resultHSL = vec3( topHSL.x, topHSL.y, bottomHSL.z ); - // vec3 resultRBG = clamp( HSLtoRGB( resultHSL ), 0, 1 ); - // vec4 result = bottom.a == 0.0 ? top : vec4( resultRBG, top.a ); - - // return blendMode_alpha( bottom, result ); } vec3 blendFunction_colorHSV( vec3 bottom, vec3 top ) @@ -600,12 +711,5 @@ vec4 blendMode_colorHSV( vec4 bottom, vec4 top ) } return blendMode_alpha( bottom, vec4( blendFunction_colorHSV( bottom.rgb, top.rgb ), top.a ) ); - // vec3 topHSL = RGBtoHSV( top.rgb ); - // vec3 bottomHSL = RGBtoHSV( bottom.rgb ); - // vec3 resultHSL = vec3( topHSL.x, topHSL.y, bottomHSL.z ); - // vec3 resultRBG = clamp( HSVtoRGB( resultHSL ), 0, 1 ); - // vec4 result = bottom.a == 0.0 ? top : vec4( resultRBG, top.a ); - - // return blendMode_alpha( bottom, result ); }