From d2f1bd512ed23a4d7c8be2df72a8d713f7cdabf7 Mon Sep 17 00:00:00 2001 From: Josef Date: Fri, 25 Apr 2025 10:13:22 +0200 Subject: [PATCH] Compositor Graph Update --- Runtime/Animation/Smoothing/FrameSmoothing.cs | 24 ++++ Runtime/Procedural/Baking/GrabTexture.cs | 73 ++++++++++++ Runtime/Procedural/Baking/GrabTexture.cs.uid | 1 + .../AlphaGrabTest/AlphaGrabTestEffect.cs | 70 ++++++++++++ .../AlphaGrabTest/AlphaGrabTestEffect.cs.uid | 1 + .../AlphaGrabTest/AlphaGrabTestShader.glsl | 18 +++ .../AlphaGrabTestShader.glsl.import | 14 +++ .../DepthAntiAliasingEffect.cs | 4 +- .../DepthView/DepthViewEffect.cs | 4 +- .../GreyScale/GreyScaleEffect.cs | 2 +- .../Pixelation/PixelationEffect.cs | 2 +- .../RadialBlur/RadialBlurEffect.cs | 2 +- .../RadialBlur2/RadialBlur2.cs | 7 +- .../TemporalSmear/TemporalSmearEffect.cs | 23 ++-- .../TextureDilationCompositerEffect.cs | 8 +- .../CompositorEffectShaderProcessor.cs | 12 +- .../Nodes/Processors/Copy/CEG_Copy.cs | 2 +- .../_XX_CompositorEffectGraph.cs | 12 +- Runtime/Rendering/Objects/RDPushConstants.cs | 2 + Runtime/Rendering/Objects/RDTexture.cs | 23 +++- .../Objects/RokojoriCompositorContext.cs | 18 ++- .../Objects/RokojoriCompositorEffect.cs | 108 +++++++++++------- 22 files changed, 341 insertions(+), 89 deletions(-) create mode 100644 Runtime/Procedural/Baking/GrabTexture.cs create mode 100644 Runtime/Procedural/Baking/GrabTexture.cs.uid create mode 100644 Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestEffect.cs create mode 100644 Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestEffect.cs.uid create mode 100644 Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl create mode 100644 Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl.import diff --git a/Runtime/Animation/Smoothing/FrameSmoothing.cs b/Runtime/Animation/Smoothing/FrameSmoothing.cs index 8d97209..4b71df3 100644 --- a/Runtime/Animation/Smoothing/FrameSmoothing.cs +++ b/Runtime/Animation/Smoothing/FrameSmoothing.cs @@ -24,6 +24,30 @@ 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 ); diff --git a/Runtime/Procedural/Baking/GrabTexture.cs b/Runtime/Procedural/Baking/GrabTexture.cs new file mode 100644 index 0000000..8b29cd6 --- /dev/null +++ b/Runtime/Procedural/Baking/GrabTexture.cs @@ -0,0 +1,73 @@ +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 ]; + + } + + } +} \ No newline at end of file diff --git a/Runtime/Procedural/Baking/GrabTexture.cs.uid b/Runtime/Procedural/Baking/GrabTexture.cs.uid new file mode 100644 index 0000000..b9fd396 --- /dev/null +++ b/Runtime/Procedural/Baking/GrabTexture.cs.uid @@ -0,0 +1 @@ +uid://ex3dmdni5p8r diff --git a/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestEffect.cs b/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestEffect.cs new file mode 100644 index 0000000..bcb0fcb --- /dev/null +++ b/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestEffect.cs @@ -0,0 +1,70 @@ + +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 GetImageTexture( System.Func 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(); + + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestEffect.cs.uid b/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestEffect.cs.uid new file mode 100644 index 0000000..032886f --- /dev/null +++ b/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestEffect.cs.uid @@ -0,0 +1 @@ +uid://bl3gywiag6qpu diff --git a/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl b/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl new file mode 100644 index 0000000..0fe9a57 --- /dev/null +++ b/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl @@ -0,0 +1,18 @@ +#[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 ); +} diff --git a/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl.import b/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl.import new file mode 100644 index 0000000..773a099 --- /dev/null +++ b/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl.import @@ -0,0 +1,14 @@ +[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] + diff --git a/Runtime/Rendering/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingEffect.cs b/Runtime/Rendering/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingEffect.cs index 7365ef4..ac3626f 100644 --- a/Runtime/Rendering/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingEffect.cs +++ b/Runtime/Rendering/CompositorEffects/DepthAntiAliasing/DepthAntiAliasingEffect.cs @@ -71,8 +71,8 @@ namespace Rokojori protected override void RenderView() { - context.Assign_ScreenColorTexture(); - context.Assign_ScreenDepthTexture( sampler ); + context.AssignScreenColorTexture(); + context.AssignScreenDepthTexture( sampler ); context.pushConstants = constants; diff --git a/Runtime/Rendering/CompositorEffects/DepthView/DepthViewEffect.cs b/Runtime/Rendering/CompositorEffects/DepthView/DepthViewEffect.cs index 210cf65..02c4d8c 100644 --- a/Runtime/Rendering/CompositorEffects/DepthView/DepthViewEffect.cs +++ b/Runtime/Rendering/CompositorEffects/DepthView/DepthViewEffect.cs @@ -50,8 +50,8 @@ namespace Rokojori protected override void RenderView() { - context.Assign_ScreenColorTexture(); - context.Assign_ScreenDepthTexture( sampler ); + context.AssignScreenColorTexture(); + context.AssignScreenDepthTexture( sampler ); context.pushConstants = constants; diff --git a/Runtime/Rendering/CompositorEffects/GreyScale/GreyScaleEffect.cs b/Runtime/Rendering/CompositorEffects/GreyScale/GreyScaleEffect.cs index 3c9bb47..7afc836 100644 --- a/Runtime/Rendering/CompositorEffects/GreyScale/GreyScaleEffect.cs +++ b/Runtime/Rendering/CompositorEffects/GreyScale/GreyScaleEffect.cs @@ -30,7 +30,7 @@ namespace Rokojori protected override void RenderView() { - context.Assign_ScreenColorTexture(); + context.AssignScreenColorTexture(); context.pushConstants = constants; diff --git a/Runtime/Rendering/CompositorEffects/Pixelation/PixelationEffect.cs b/Runtime/Rendering/CompositorEffects/Pixelation/PixelationEffect.cs index 27fb69b..ac49280 100644 --- a/Runtime/Rendering/CompositorEffects/Pixelation/PixelationEffect.cs +++ b/Runtime/Rendering/CompositorEffects/Pixelation/PixelationEffect.cs @@ -35,7 +35,7 @@ namespace Rokojori protected override void RenderView() { - context.Assign_ScreenColorTexture(); + context.AssignScreenColorTexture(); context.pushConstants = constants; diff --git a/Runtime/Rendering/CompositorEffects/RadialBlur/RadialBlurEffect.cs b/Runtime/Rendering/CompositorEffects/RadialBlur/RadialBlurEffect.cs index 57ff7a8..1e9e668 100644 --- a/Runtime/Rendering/CompositorEffects/RadialBlur/RadialBlurEffect.cs +++ b/Runtime/Rendering/CompositorEffects/RadialBlur/RadialBlurEffect.cs @@ -45,7 +45,7 @@ namespace Rokojori protected override void RenderView() { - context.Assign_ScreenColorTexture(); + context.AssignScreenColorTexture(); context.pushConstants = constants; diff --git a/Runtime/Rendering/CompositorEffects/RadialBlur2/RadialBlur2.cs b/Runtime/Rendering/CompositorEffects/RadialBlur2/RadialBlur2.cs index 45d35e3..5ee3a7d 100644 --- a/Runtime/Rendering/CompositorEffects/RadialBlur2/RadialBlur2.cs +++ b/Runtime/Rendering/CompositorEffects/RadialBlur2/RadialBlur2.cs @@ -11,7 +11,7 @@ namespace Rokojori { public RadialBlur2() { - CreateGraphNodes(); + Initialize(); } [Export] @@ -47,7 +47,10 @@ namespace Rokojori bufferTexture = CEG_BufferTexture.ScreenSize( this ); copy = new CEG_Copy( this ); - radialBlur = new CEG_RadialBlur( this ); + radialBlur = new CEG_RadialBlur( this ); + + _processors = new List{ screenColorTexture, bufferTexture, copy, radialBlur }; + _processors.ForEach( p => p.Initialize() ); } void ConnectGraph() diff --git a/Runtime/Rendering/CompositorEffects/TemporalSmear/TemporalSmearEffect.cs b/Runtime/Rendering/CompositorEffects/TemporalSmear/TemporalSmearEffect.cs index 70dd1bd..4b90a24 100644 --- a/Runtime/Rendering/CompositorEffects/TemporalSmear/TemporalSmearEffect.cs +++ b/Runtime/Rendering/CompositorEffects/TemporalSmear/TemporalSmearEffect.cs @@ -15,8 +15,8 @@ namespace Rokojori [Export( PropertyHint.Range, "0,1")] public float amount = 1f; - [Export( PropertyHint.Range, "0,1")] - public float smearing = 0.5f; + [Export( PropertyHint.Range, "0,600")] + public float smearingFrames = 30; [Export( PropertyHint.Range, "0,1")] public float lumaAmount = 0.5f; @@ -40,7 +40,7 @@ namespace Rokojori { constants.Set( amount, - smearing, + 1.0f - FrameSmoothing.ComputeCoefficient( 1f/60f, smearingFrames ), lumaAmount, lumaTreshold, lumaSaturate @@ -51,19 +51,10 @@ namespace Rokojori protected override void RenderView() { - if ( _bufferTexture == null || _bufferTexture.size != context.internalSize ) - { - if ( _bufferTexture != null ) - { - rd.FreeRid( _bufferTexture.rid ); - _bufferTexture = null; - } - - _bufferTexture = RDTexture.Create( this, context.internalSize ); - } - - context.AssignUniformSet_Texture( _bufferTexture ); - context.Assign_ScreenColorTexture(); + _bufferTexture = RDTexture.EnsureScreenSizeTexture( _bufferTexture, this ); + + context.AssignTexture( _bufferTexture ); + context.AssignScreenColorTexture(); context.pushConstants = constants; diff --git a/Runtime/Rendering/CompositorEffects/TextureDilation/TextureDilationCompositerEffect.cs b/Runtime/Rendering/CompositorEffects/TextureDilation/TextureDilationCompositerEffect.cs index 641fb07..3543cee 100644 --- a/Runtime/Rendering/CompositorEffects/TextureDilation/TextureDilationCompositerEffect.cs +++ b/Runtime/Rendering/CompositorEffects/TextureDilation/TextureDilationCompositerEffect.cs @@ -17,13 +17,7 @@ namespace Rokojori { CreateGraph(); } - - RDTexture color; - RDTexture bufferA; - RDTexture bufferB; - - CEG_Copy copy; - + void CreateGraph() { diff --git a/Runtime/Rendering/Objects/CompositorEffectGraph/CompositorEffectShaderProcessor.cs b/Runtime/Rendering/Objects/CompositorEffectGraph/CompositorEffectShaderProcessor.cs index e86e785..375db27 100644 --- a/Runtime/Rendering/Objects/CompositorEffectGraph/CompositorEffectShaderProcessor.cs +++ b/Runtime/Rendering/Objects/CompositorEffectGraph/CompositorEffectShaderProcessor.cs @@ -15,7 +15,7 @@ namespace Rokojori protected RDShader _shader; protected RDPipeline _pipeline; - protected RDPushConstants _constants; + protected RDPushConstants _constants = new RDPushConstants(); public RDPushConstants constants => _constants; protected Vector3I _groupSize = new Vector3I( 8, 8, 0 ); protected List _textureSlots = new List(); @@ -68,12 +68,14 @@ namespace Rokojori _textureSlots.ForEach( t => { t.ResolveTexture(); - graph.context.AssignUniformSet_Texture( t.GetTexture(), t.sampler ); + graph.context.AssignTexture( t.GetTexture(), t.sampler ); } - ); - + ); - context.pushConstants = _constants; + if ( _constants.size > 0 ) + { + context.pushConstants = _constants; + } context.Render(); } diff --git a/Runtime/Rendering/Objects/CompositorEffectGraph/Nodes/Processors/Copy/CEG_Copy.cs b/Runtime/Rendering/Objects/CompositorEffectGraph/Nodes/Processors/Copy/CEG_Copy.cs index b979283..af6fe0f 100644 --- a/Runtime/Rendering/Objects/CompositorEffectGraph/Nodes/Processors/Copy/CEG_Copy.cs +++ b/Runtime/Rendering/Objects/CompositorEffectGraph/Nodes/Processors/Copy/CEG_Copy.cs @@ -7,7 +7,7 @@ namespace Rokojori public class CEG_Copy:CEG_ImageProcessor { public static readonly string shaderPath = - _XX_CompositorEffectGraph.Path( "Nodes/Processors/Copy/CopyShader.glsl" ); + _XX_CompositorEffectGraph.Path( "Nodes/Processors/Copy/Copy.glsl" ); public CEG_Copy( _XX_CompositorEffectGraph graph ):base( graph, shaderPath ) {} diff --git a/Runtime/Rendering/Objects/CompositorEffectGraph/_XX_CompositorEffectGraph.cs b/Runtime/Rendering/Objects/CompositorEffectGraph/_XX_CompositorEffectGraph.cs index 23810f0..ccecba0 100644 --- a/Runtime/Rendering/Objects/CompositorEffectGraph/_XX_CompositorEffectGraph.cs +++ b/Runtime/Rendering/Objects/CompositorEffectGraph/_XX_CompositorEffectGraph.cs @@ -18,8 +18,6 @@ namespace Rokojori protected List _processors = new List(); protected List _processOrder = new List(); - - protected void SetProcessOrder( List order ) { _processOrder.Clear(); @@ -35,7 +33,15 @@ namespace Rokojori protected override void RenderView() { OnPreProcess(); - _processOrder.ForEach( p => p.Process() ); + + _processOrder.ForEach( + p => + { + Verbose( p.GetType() ); + p.Process(); + } + ); + OnPostProcess(); } diff --git a/Runtime/Rendering/Objects/RDPushConstants.cs b/Runtime/Rendering/Objects/RDPushConstants.cs index 369db90..5d0cefc 100644 --- a/Runtime/Rendering/Objects/RDPushConstants.cs +++ b/Runtime/Rendering/Objects/RDPushConstants.cs @@ -21,6 +21,8 @@ namespace Rokojori _intIndex = 0; } + public int size => _floatIndex + _intIndex; + public void Set( params object[] objects ) { Reset(); diff --git a/Runtime/Rendering/Objects/RDTexture.cs b/Runtime/Rendering/Objects/RDTexture.cs index 13048a3..1b343d8 100644 --- a/Runtime/Rendering/Objects/RDTexture.cs +++ b/Runtime/Rendering/Objects/RDTexture.cs @@ -43,6 +43,23 @@ 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(); @@ -57,7 +74,11 @@ namespace Rokojori format.Width = (uint) w; format.Height = (uint) h; format.Format = dataFormat; - format.UsageBits = RenderingDevice.TextureUsageBits.StorageBit | RenderingDevice.TextureUsageBits.SamplingBit; + format.UsageBits = RenderingDevice.TextureUsageBits.StorageBit | + RenderingDevice.TextureUsageBits.SamplingBit | + RenderingDevice.TextureUsageBits.CanCopyFromBit | + RenderingDevice.TextureUsageBits.CpuReadBit + ; return format; } diff --git a/Runtime/Rendering/Objects/RokojoriCompositorContext.cs b/Runtime/Rendering/Objects/RokojoriCompositorContext.cs index 196a91e..000475e 100644 --- a/Runtime/Rendering/Objects/RokojoriCompositorContext.cs +++ b/Runtime/Rendering/Objects/RokojoriCompositorContext.cs @@ -17,6 +17,14 @@ 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; @@ -54,17 +62,17 @@ namespace Rokojori return RDTexture.Depth( this ); } - public void Assign_ScreenColorTexture( RDSampler sampler = null, int setIndex = -1 ) + public void AssignScreenColorTexture( RDSampler sampler = null, int setIndex = -1 ) { - AssignUniformSet_Texture( GetScreenColorTexture(), sampler, setIndex ); + AssignTexture( GetScreenColorTexture(), sampler, setIndex ); } - public void Assign_ScreenDepthTexture( RDSampler sampler = null, int setIndex = -1 ) + public void AssignScreenDepthTexture( RDSampler sampler = null, int setIndex = -1 ) { - AssignUniformSet_Texture( GetScreenDepthTexture(), sampler, setIndex ); + AssignTexture( GetScreenDepthTexture(), sampler, setIndex ); } - public void AssignUniformSet_Texture( RDTexture texture, RDSampler sampler = null, int setIndex = -1 ) + public void AssignTexture( RDTexture texture, RDSampler sampler = null, int setIndex = -1 ) { // effect.Verbose( "Incoming Uniform Index", setIndex ); diff --git a/Runtime/Rendering/Objects/RokojoriCompositorEffect.cs b/Runtime/Rendering/Objects/RokojoriCompositorEffect.cs index dd6cbec..59293be 100644 --- a/Runtime/Rendering/Objects/RokojoriCompositorEffect.cs +++ b/Runtime/Rendering/Objects/RokojoriCompositorEffect.cs @@ -22,7 +22,7 @@ namespace Rokojori protected List _messages = new List(); public List messages => _messages; public bool logMessages = true; - public int messageLogLevel = Messages.GetLevel( MessageType.Verbose ); + public int messageLogLevel = Messages.GetLevel( MessageType.Info ); protected virtual void OnConfigure(){} protected virtual void OnInitialize(){} @@ -55,57 +55,81 @@ 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; - if ( rd == null ) + try { - Error( "No render device" ); - return; + + if ( rd == null ) + { + Error( "No render device" ); + return; + } + + var sceneBuffers = ( RenderSceneBuffersRD ) renderData.GetRenderSceneBuffers(); + var sceneData = ( RenderSceneDataRD ) renderData.GetRenderSceneData(); + + if ( sceneBuffers == null && sceneData == null ) + { + Error( "sceneBuffers == null && sceneData == null" ); + return; + } + + + + var size = sceneBuffers.GetInternalSize(); + + if ( size.X == 0 || size.Y == 0 ) + { + Warning( "InternalSize.X == 0 || InternalSize.Y == 0" ); + return; + } + + _context.SetRenderData( renderData, sceneBuffers, sceneData ); + _context.SetView( -1 ); + + _hasContext = true; + + ForAllViews(); + + + + int viewCount = ( int ) sceneBuffers.GetViewCount(); + + for ( int i = 0; i < viewCount; i++ ) + { + _context.SetView( i ); + RenderView(); + } + } - - var sceneBuffers = ( RenderSceneBuffersRD ) renderData.GetRenderSceneBuffers(); - var sceneData = ( RenderSceneDataRD ) renderData.GetRenderSceneData(); - - if ( sceneBuffers == null && sceneData == null ) + catch( System.Exception e ) { - Error( "sceneBuffers == null && sceneData == null" ); - return; + this.LogError( e ); + _hasError = true; } - - - var size = sceneBuffers.GetInternalSize(); - - if ( size.X == 0 || size.Y == 0 ) + if ( HasError() ) { - Warning( "InternalSize.X == 0 || InternalSize.Y == 0" ); - return; - } - - _context.SetRenderData( renderData, sceneBuffers, sceneData ); - _context.SetView( -1 ); - - _context.SetGroups( new Vector3I( 1, 1, 1 ) ); - - - - _hasContext = true; - // var groups = ComputeGroups(); - // _context.SetGroups( groups ); - - ForAllViews(); - - - - int viewCount = ( int ) sceneBuffers.GetViewCount(); - - for ( int i = 0; i < viewCount; i++ ) - { - _context.SetView( i ); - RenderView(); + _hasError = true; } _hasContext = false;