Compare commits
	
		
			No commits in common. "861ffd1a6dccd561cb8264978ae175b49ea73b6c" and "1e2e22f67fc96569bab09036ad7149328018325f" have entirely different histories.
		
	
	
		
			861ffd1a6d
			...
			1e2e22f67f
		
	
		|  | @ -24,30 +24,6 @@ namespace Rokojori | |||
|       return 1f - Mathf.Exp( -coefficient * delta ); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public static float ComputeCoefficient( float delta, float frames ) | ||||
|     { | ||||
|       int floored = Mathf.FloorToInt( frames ); | ||||
| 
 | ||||
|       float low  = ComputeCoefficientInt( delta, floored ); | ||||
|       float high = ComputeCoefficientInt( delta, floored + 1 ); | ||||
| 
 | ||||
|       return Mathf.Lerp( low, high, frames - floored ); | ||||
|     } | ||||
| 
 | ||||
|     public static float ComputeCoefficientInt( float delta, int frames ) | ||||
|     { | ||||
|       frames = Mathf.Clamp( frames, 0, 600 ); | ||||
| 
 | ||||
|       if ( frames <= 0 ) | ||||
|       { | ||||
|         return 1; | ||||
|       }       | ||||
| 
 | ||||
|       var coefficient = GetCoefficientForFrames( frames ); | ||||
|       return 1f - Mathf.Exp( -coefficient * delta ); | ||||
|     } | ||||
| 
 | ||||
|     public static float GetCoefficientForFrames( int frames ) | ||||
|     { | ||||
|       return FrameSmoothingTable.Get( frames ); | ||||
|  |  | |||
|  | @ -1,73 +0,0 @@ | |||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using Godot; | ||||
| using System; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| namespace Rokojori | ||||
| { | ||||
|   [Tool] | ||||
|   [GlobalClass] | ||||
|   public partial class GrabTexture:Node | ||||
|   {  | ||||
|      | ||||
|      | ||||
| 
 | ||||
|     [Export] | ||||
|     public Compositor compositor; | ||||
| 
 | ||||
|     [Export] | ||||
|     public WorldEnvironment environment; | ||||
| 
 | ||||
|     [Export] | ||||
|     public Camera3D camera3D; | ||||
| 
 | ||||
|     [ExportToolButton( "Grab Compositor From Camera")] | ||||
|     public Callable GrabCompositorButton => Callable.From(  | ||||
|       () =>  | ||||
|       { | ||||
|         if ( camera3D != null ) | ||||
|         { | ||||
|           compositor = camera3D.Compositor; | ||||
|         } | ||||
| 
 | ||||
|         if ( environment != null ) | ||||
|         { | ||||
|           compositor = environment.Compositor; | ||||
|         } | ||||
|          | ||||
| 
 | ||||
|         alphaGrabTestEffect = (AlphaGrabTestEffect) compositor.CompositorEffects[ compositorIndex ]; | ||||
|       }  | ||||
|     ); | ||||
| 
 | ||||
| 
 | ||||
|     [Export] | ||||
|     public int compositorIndex; | ||||
| 
 | ||||
|     [Export] | ||||
|     public AlphaGrabTestEffect alphaGrabTestEffect; | ||||
| 
 | ||||
|     [ExportToolButton( "Grab Texture")] | ||||
|     public Callable GrabTextureButton => Callable.From(  | ||||
|       async () =>  | ||||
|       { | ||||
|         texture2D = await alphaGrabTestEffect.GetImageTexture( async ()=> await this.RequestNextFrame() ); | ||||
|       }  | ||||
|     ); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     [Export] | ||||
|     public Texture2D texture2D; | ||||
| 
 | ||||
|     public void Grab() | ||||
|     { | ||||
|       var effect = compositor.CompositorEffects[ compositorIndex ]; | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|   } | ||||
| } | ||||
|  | @ -1 +0,0 @@ | |||
| uid://ex3dmdni5p8r | ||||
|  | @ -1,70 +0,0 @@ | |||
| 
 | ||||
| using Godot; | ||||
| using Godot.Collections; | ||||
| using System.Collections.Generic; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace Rokojori | ||||
| {   | ||||
|   [Tool] | ||||
|   [GlobalClass] | ||||
|   public partial class AlphaGrabTestEffect:SingleShaderCompositorEffect | ||||
|   { | ||||
|     public static readonly string shaderPath =  | ||||
|       RokojoriPlugin.Path( "Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl" ); | ||||
| 
 | ||||
|     | ||||
| 
 | ||||
|     protected override void OnConfigure() | ||||
|     { | ||||
|       EffectCallbackType = EffectCallbackTypeEnum.PostTransparent; | ||||
|       _shaderPath = shaderPath; | ||||
|       _groupSize = 32; | ||||
|     } | ||||
| 
 | ||||
|     RDTexture _bufferTexture; | ||||
|     RDTexture _copyTexture; | ||||
| 
 | ||||
|     bool _grabFlag; | ||||
|     byte[] _data; | ||||
|     bool _ready = false; | ||||
|     bool _canDraw = true; | ||||
|     public async Task<Texture2D> GetImageTexture( System.Func<Task> waiter ) | ||||
|     { | ||||
|       var fmt = _bufferTexture.format; | ||||
|       var imgF = Image.Format.Rgbah; | ||||
| 
 | ||||
|       var data = _rd.TextureGetData( _bufferTexture.rid, 0 ); | ||||
|       var image = Image.CreateFromData( (int) fmt.Width, (int)fmt.Height, false, imgF, data ); | ||||
|      | ||||
|       return ImageTexture.CreateFromImage( image ); | ||||
|        | ||||
|     } | ||||
| 
 | ||||
|     protected override void SetConstants() | ||||
|     {      | ||||
|       // constants.Set( | ||||
|       //   center,  | ||||
|       //   radius,  | ||||
|       //   intensity, | ||||
|       //   samples, | ||||
|       //   Vector2.Zero | ||||
|       // ); | ||||
|     } | ||||
|      | ||||
|     protected override void RenderView() | ||||
|     {      | ||||
|       _bufferTexture = RDTexture.EnsureScreenSizeTexture( _bufferTexture, this ); | ||||
|       _copyTexture   = RDTexture.EnsureScreenSizeTexture( _copyTexture, this ); | ||||
| 
 | ||||
|       context.AssignScreenColorTexture(); | ||||
|       context.AssignTexture( _bufferTexture ); | ||||
|        | ||||
| 
 | ||||
|       // context.pushConstants = constants; | ||||
| 
 | ||||
|       context.Render(); | ||||
| 
 | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | @ -1 +0,0 @@ | |||
| uid://bl3gywiag6qpu | ||||
|  | @ -1,18 +0,0 @@ | |||
| #[compute] | ||||
| #version 450 | ||||
| 
 | ||||
| layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; | ||||
| 
 | ||||
| layout(rgba16, set = 0, binding = 0)  | ||||
| uniform restrict readonly image2D inputImage; | ||||
| 
 | ||||
| layout(rgba16, set = 1, binding = 0)  | ||||
| uniform restrict writeonly image2D outputImage; | ||||
| 
 | ||||
| void main()  | ||||
| { | ||||
| 	ivec2 currentPosition = ivec2( gl_GlobalInvocationID.xy ); | ||||
| 	vec4 currentPixel = imageLoad( inputImage, currentPosition ); | ||||
|    | ||||
| 	imageStore( outputImage, currentPosition, currentPixel ); | ||||
| } | ||||
|  | @ -1,14 +0,0 @@ | |||
| [remap] | ||||
| 
 | ||||
| importer="glsl" | ||||
| type="RDShaderFile" | ||||
| uid="uid://b0sbxsqka4svp" | ||||
| path="res://.godot/imported/AlphaGrabTestShader.glsl-6c0893a67e5a07d0f4ca62efdf6123e9.res" | ||||
| 
 | ||||
| [deps] | ||||
| 
 | ||||
| source_file="res://addons/rokojori_action_library/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl" | ||||
| dest_files=["res://.godot/imported/AlphaGrabTestShader.glsl-6c0893a67e5a07d0f4ca62efdf6123e9.res"] | ||||
| 
 | ||||
| [params] | ||||
| 
 | ||||
|  | @ -71,8 +71,8 @@ namespace Rokojori | |||
|      | ||||
|     protected override void RenderView() | ||||
|     { | ||||
|       context.AssignScreenColorTexture(); | ||||
|       context.AssignScreenDepthTexture( sampler ); | ||||
|       context.Assign_ScreenColorTexture(); | ||||
|       context.Assign_ScreenDepthTexture( sampler ); | ||||
| 
 | ||||
|       context.pushConstants = constants; | ||||
| 
 | ||||
|  |  | |||
|  | @ -50,8 +50,8 @@ namespace Rokojori | |||
|      | ||||
|     protected override void RenderView() | ||||
|     { | ||||
|       context.AssignScreenColorTexture(); | ||||
|       context.AssignScreenDepthTexture( sampler ); | ||||
|       context.Assign_ScreenColorTexture(); | ||||
|       context.Assign_ScreenDepthTexture( sampler ); | ||||
| 
 | ||||
|       context.pushConstants = constants; | ||||
| 
 | ||||
|  |  | |||
|  | @ -30,7 +30,7 @@ namespace Rokojori | |||
|      | ||||
|     protected override void RenderView() | ||||
|     { | ||||
|       context.AssignScreenColorTexture(); | ||||
|       context.Assign_ScreenColorTexture(); | ||||
| 
 | ||||
|       context.pushConstants = constants; | ||||
| 
 | ||||
|  |  | |||
|  | @ -35,7 +35,7 @@ namespace Rokojori | |||
|      | ||||
|     protected override void RenderView() | ||||
|     { | ||||
|       context.AssignScreenColorTexture(); | ||||
|       context.Assign_ScreenColorTexture(); | ||||
| 
 | ||||
|       context.pushConstants = constants; | ||||
| 
 | ||||
|  |  | |||
|  | @ -45,7 +45,7 @@ namespace Rokojori | |||
|      | ||||
|     protected override void RenderView() | ||||
|     { | ||||
|       context.AssignScreenColorTexture(); | ||||
|       context.Assign_ScreenColorTexture(); | ||||
| 
 | ||||
|       context.pushConstants = constants; | ||||
| 
 | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ namespace Rokojori | |||
|   { | ||||
|     public RadialBlur2() | ||||
|     { | ||||
|       Initialize(); | ||||
|       CreateGraphNodes(); | ||||
|     } | ||||
| 
 | ||||
|     [Export] | ||||
|  | @ -48,9 +48,6 @@ namespace Rokojori | |||
| 
 | ||||
|       copy = new CEG_Copy( this ); | ||||
|       radialBlur = new CEG_RadialBlur( this );       | ||||
| 
 | ||||
|       _processors = new List<CompositorEffectGraphProcessor>{ screenColorTexture, bufferTexture, copy, radialBlur }; | ||||
|       _processors.ForEach( p => p.Initialize() ); | ||||
|     } | ||||
| 
 | ||||
|     void ConnectGraph() | ||||
|  |  | |||
|  | @ -15,8 +15,8 @@ namespace Rokojori | |||
|     [Export( PropertyHint.Range, "0,1")] | ||||
|     public float amount = 1f; | ||||
| 
 | ||||
|     [Export( PropertyHint.Range, "0,600")] | ||||
|     public float smearingFrames = 30; | ||||
|     [Export( PropertyHint.Range, "0,1")] | ||||
|     public float smearing = 0.5f; | ||||
| 
 | ||||
|     [Export( PropertyHint.Range, "0,1")] | ||||
|     public float lumaAmount = 0.5f; | ||||
|  | @ -45,7 +45,7 @@ namespace Rokojori | |||
|     {      | ||||
|       constants.Set( | ||||
|         amount, | ||||
|         1.0f - FrameSmoothing.ComputeCoefficient( 1f/60f, smearingFrames ), | ||||
|         smearing, | ||||
|         lumaAmount, | ||||
|         lumaTreshold, | ||||
|         lumaSaturate, | ||||
|  | @ -58,10 +58,19 @@ namespace Rokojori | |||
|      | ||||
|     protected override void RenderView() | ||||
|     { | ||||
|       _bufferTexture = RDTexture.EnsureScreenSizeTexture( _bufferTexture, this ); | ||||
|       if ( _bufferTexture == null || _bufferTexture.size != context.internalSize ) | ||||
|       { | ||||
|         if ( _bufferTexture != null ) | ||||
|         { | ||||
|           rd.FreeRid( _bufferTexture.rid ); | ||||
|           _bufferTexture = null; | ||||
|         } | ||||
| 
 | ||||
|       context.AssignTexture( _bufferTexture ); | ||||
|       context.AssignScreenColorTexture(); | ||||
|         _bufferTexture = RDTexture.Create( this, context.internalSize ); | ||||
|       } | ||||
| 
 | ||||
|       context.AssignUniformSet_Texture( _bufferTexture ); | ||||
|       context.Assign_ScreenColorTexture(); | ||||
|        | ||||
| 
 | ||||
|       context.pushConstants = constants; | ||||
|  |  | |||
|  | @ -18,6 +18,12 @@ namespace Rokojori | |||
|       CreateGraph(); | ||||
|     } | ||||
| 
 | ||||
|     RDTexture color; | ||||
|     RDTexture bufferA; | ||||
|     RDTexture bufferB; | ||||
| 
 | ||||
|     CEG_Copy copy; | ||||
| 
 | ||||
|     void CreateGraph() | ||||
|     { | ||||
|        | ||||
|  |  | |||
|  | @ -15,7 +15,7 @@ namespace Rokojori | |||
| 
 | ||||
|     protected RDShader _shader; | ||||
|     protected RDPipeline _pipeline; | ||||
|     protected RDPushConstants _constants = new RDPushConstants(); | ||||
|     protected RDPushConstants _constants; | ||||
|     public RDPushConstants constants => _constants; | ||||
|     protected Vector3I _groupSize = new Vector3I( 8, 8, 0 ); | ||||
|     protected List<CompositorEffectGraphTextureSlot> _textureSlots = new List<CompositorEffectGraphTextureSlot>();  | ||||
|  | @ -68,14 +68,12 @@ namespace Rokojori | |||
|       _textureSlots.ForEach( t =>  | ||||
|         {  | ||||
|           t.ResolveTexture(); | ||||
|           graph.context.AssignTexture( t.GetTexture(), t.sampler );  | ||||
|           graph.context.AssignUniformSet_Texture( t.GetTexture(), t.sampler );  | ||||
|         }  | ||||
|       ); | ||||
|        | ||||
|       if ( _constants.size > 0 ) | ||||
|       { | ||||
| 
 | ||||
|       context.pushConstants = _constants; | ||||
|       }       | ||||
| 
 | ||||
|       context.Render(); | ||||
|     } | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ namespace Rokojori | |||
|   public class CEG_Copy:CEG_ImageProcessor | ||||
|   { | ||||
|     public static readonly string shaderPath =  | ||||
|       _XX_CompositorEffectGraph.Path( "Nodes/Processors/Copy/Copy.glsl" ); | ||||
|       _XX_CompositorEffectGraph.Path( "Nodes/Processors/Copy/CopyShader.glsl" ); | ||||
| 
 | ||||
|     public CEG_Copy( _XX_CompositorEffectGraph graph ):base( graph, shaderPath ) | ||||
|     {}  | ||||
|  |  | |||
|  | @ -18,6 +18,8 @@ namespace Rokojori | |||
|     protected List<CompositorEffectGraphProcessor> _processors = new List<CompositorEffectGraphProcessor>(); | ||||
|     protected List<CompositorEffectGraphProcessor> _processOrder = new List<CompositorEffectGraphProcessor>(); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     protected void SetProcessOrder( List<CompositorEffectGraphProcessor> order ) | ||||
|     { | ||||
|       _processOrder.Clear(); | ||||
|  | @ -33,15 +35,7 @@ namespace Rokojori | |||
|     protected override void RenderView() | ||||
|     { | ||||
|       OnPreProcess(); | ||||
|        | ||||
|       _processOrder.ForEach(  | ||||
|         p =>  | ||||
|         {  | ||||
|           Verbose( p.GetType() ); | ||||
|           p.Process(); | ||||
|         } | ||||
|       ); | ||||
| 
 | ||||
|       _processOrder.ForEach( p => p.Process() ); | ||||
|       OnPostProcess(); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -21,8 +21,6 @@ namespace Rokojori | |||
|       _intIndex = 0; | ||||
|     } | ||||
| 
 | ||||
|     public int size => _floatIndex + _intIndex; | ||||
| 
 | ||||
|     public void Set( params object[] objects ) | ||||
|     {  | ||||
|       Reset(); | ||||
|  |  | |||
|  | @ -43,23 +43,6 @@ namespace Rokojori | |||
|       } | ||||
|     } | ||||
| 
 | ||||
|     public static RDTexture EnsureScreenSizeTexture( RDTexture texture, RokojoriCompositorEffect effect, bool cleanUp = true ) | ||||
|     { | ||||
|       var size = effect.context.internalSize; | ||||
| 
 | ||||
|       if ( texture == null || texture.size != size ) | ||||
|       { | ||||
|         if ( cleanUp && texture != null ) | ||||
|         { | ||||
|           effect.rd.FreeRid( texture.rid ); | ||||
|         } | ||||
| 
 | ||||
|         texture = Create( effect, size ); | ||||
|       } | ||||
| 
 | ||||
|       return texture; | ||||
|     } | ||||
| 
 | ||||
|     public static RDTexture Create( RokojoriCompositorEffect effect, RDTextureFormat format ) | ||||
|     { | ||||
|       var view = new RDTextureView(); | ||||
|  | @ -74,11 +57,7 @@ namespace Rokojori | |||
|       format.Width  = (uint) w; | ||||
|       format.Height = (uint) h; | ||||
|       format.Format = dataFormat; | ||||
|       format.UsageBits = RenderingDevice.TextureUsageBits.StorageBit |  | ||||
|                          RenderingDevice.TextureUsageBits.SamplingBit | | ||||
|                          RenderingDevice.TextureUsageBits.CanCopyFromBit |  | ||||
|                          RenderingDevice.TextureUsageBits.CpuReadBit | ||||
|                         ; | ||||
|       format.UsageBits = RenderingDevice.TextureUsageBits.StorageBit | RenderingDevice.TextureUsageBits.SamplingBit; | ||||
| 
 | ||||
|       return format; | ||||
|     } | ||||
|  |  | |||
|  | @ -17,14 +17,6 @@ namespace Rokojori | |||
| 
 | ||||
|     public void SetShaderAndPipeline( RDShader shader, RDPipeline pipeline ) | ||||
|     { | ||||
|       if ( shader == null || pipeline == null ) | ||||
|       { | ||||
|         _shader = null; | ||||
|         _pipeline = null; | ||||
|         effect.Error( "Shader Pipeline is null", shader, pipeline ); | ||||
|         return;  | ||||
|       } | ||||
| 
 | ||||
|       effect.Verbose( "Set Shader Pipeline", shader, pipeline ); | ||||
|       _shader = shader; | ||||
|       _pipeline = pipeline; | ||||
|  | @ -62,17 +54,17 @@ namespace Rokojori | |||
|       return RDTexture.Depth( this ); | ||||
|     } | ||||
| 
 | ||||
|     public void AssignScreenColorTexture( RDSampler sampler = null, int setIndex = -1 ) | ||||
|     public void Assign_ScreenColorTexture( RDSampler sampler = null, int setIndex = -1 ) | ||||
|     { | ||||
|       AssignTexture( GetScreenColorTexture(), sampler, setIndex ); | ||||
|       AssignUniformSet_Texture( GetScreenColorTexture(), sampler, setIndex ); | ||||
|     } | ||||
| 
 | ||||
|     public void AssignScreenDepthTexture( RDSampler sampler = null, int setIndex = -1 ) | ||||
|     public void Assign_ScreenDepthTexture( RDSampler sampler = null, int setIndex = -1 ) | ||||
|     { | ||||
|       AssignTexture( GetScreenDepthTexture(), sampler, setIndex ); | ||||
|       AssignUniformSet_Texture( GetScreenDepthTexture(), sampler, setIndex ); | ||||
|     } | ||||
| 
 | ||||
|     public void AssignTexture( RDTexture texture, RDSampler sampler = null, int setIndex = -1 ) | ||||
|     public void AssignUniformSet_Texture( RDTexture texture, RDSampler sampler = null, int setIndex = -1 ) | ||||
|     { | ||||
|       // effect.Verbose( "Incoming Uniform Index", setIndex ); | ||||
| 
 | ||||
|  |  | |||
|  | @ -22,7 +22,7 @@ namespace Rokojori | |||
|     protected List<Message> _messages = new List<Message>(); | ||||
|     public List<Message> messages => _messages; | ||||
|     public bool logMessages = true; | ||||
|     public int messageLogLevel = Messages.GetLevel( MessageType.Info ); | ||||
|     public int messageLogLevel = Messages.GetLevel( MessageType.Verbose ); | ||||
| 
 | ||||
|     protected virtual void OnConfigure(){} | ||||
|     protected virtual void OnInitialize(){} | ||||
|  | @ -55,29 +55,11 @@ namespace Rokojori | |||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     bool _hasError = false; | ||||
| 
 | ||||
|     protected bool HasError() | ||||
|     { | ||||
|       return Messages.HasError( _messages ); | ||||
|     } | ||||
| 
 | ||||
|     public override void _RenderCallback( int effectCallbackType, RenderData renderData ) | ||||
|     {   | ||||
|             | ||||
|        | ||||
|       if ( _hasError || HasError() ) | ||||
|       { | ||||
|         this.LogInfo( _messages ); | ||||
|         return;  | ||||
|       } | ||||
| 
 | ||||
|       _messages.Clear();  | ||||
|       _hasContext = false; | ||||
| 
 | ||||
|       try | ||||
|       { | ||||
| 
 | ||||
|       if ( rd == null ) | ||||
|       { | ||||
|         Error( "No render device" ); | ||||
|  | @ -106,7 +88,13 @@ namespace Rokojori | |||
|       _context.SetRenderData( renderData, sceneBuffers, sceneData ); | ||||
|       _context.SetView( -1 ); | ||||
| 
 | ||||
|       _context.SetGroups( new Vector3I( 1, 1, 1 ) ); | ||||
| 
 | ||||
|       | ||||
| 
 | ||||
|       _hasContext = true; | ||||
|       // var groups = ComputeGroups(); | ||||
|       // _context.SetGroups( groups ); | ||||
| 
 | ||||
|       ForAllViews(); | ||||
| 
 | ||||
|  | @ -120,18 +108,6 @@ namespace Rokojori | |||
|         RenderView(); | ||||
|       } | ||||
| 
 | ||||
|       } | ||||
|       catch( System.Exception e ) | ||||
|       { | ||||
|         this.LogError( e ); | ||||
|         _hasError = true; | ||||
|       } | ||||
| 
 | ||||
|       if ( HasError() ) | ||||
|       { | ||||
|         _hasError = true; | ||||
|       } | ||||
| 
 | ||||
|       _hasContext = false; | ||||
|     } | ||||
|      | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue