Compositor Graph Update
This commit is contained in:
parent
89138f1a1c
commit
d2f1bd512e
|
@ -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 );
|
||||
|
|
|
@ -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 ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
uid://ex3dmdni5p8r
|
|
@ -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<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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
uid://bl3gywiag6qpu
|
|
@ -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 );
|
||||
}
|
|
@ -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]
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Rokojori
|
|||
|
||||
protected override void RenderView()
|
||||
{
|
||||
context.Assign_ScreenColorTexture();
|
||||
context.AssignScreenColorTexture();
|
||||
|
||||
context.pushConstants = constants;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Rokojori
|
|||
|
||||
protected override void RenderView()
|
||||
{
|
||||
context.Assign_ScreenColorTexture();
|
||||
context.AssignScreenColorTexture();
|
||||
|
||||
context.pushConstants = constants;
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Rokojori
|
|||
|
||||
protected override void RenderView()
|
||||
{
|
||||
context.Assign_ScreenColorTexture();
|
||||
context.AssignScreenColorTexture();
|
||||
|
||||
context.pushConstants = constants;
|
||||
|
||||
|
|
|
@ -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<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,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;
|
||||
|
|
|
@ -17,13 +17,7 @@ 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;
|
||||
protected RDPushConstants _constants = new RDPushConstants();
|
||||
public RDPushConstants constants => _constants;
|
||||
protected Vector3I _groupSize = new Vector3I( 8, 8, 0 );
|
||||
protected List<CompositorEffectGraphTextureSlot> _textureSlots = new List<CompositorEffectGraphTextureSlot>();
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
{}
|
||||
|
|
|
@ -18,8 +18,6 @@ namespace Rokojori
|
|||
protected List<CompositorEffectGraphProcessor> _processors = new List<CompositorEffectGraphProcessor>();
|
||||
protected List<CompositorEffectGraphProcessor> _processOrder = new List<CompositorEffectGraphProcessor>();
|
||||
|
||||
|
||||
|
||||
protected void SetProcessOrder( List<CompositorEffectGraphProcessor> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ namespace Rokojori
|
|||
_intIndex = 0;
|
||||
}
|
||||
|
||||
public int size => _floatIndex + _intIndex;
|
||||
|
||||
public void Set( params object[] objects )
|
||||
{
|
||||
Reset();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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.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;
|
||||
|
|
Loading…
Reference in New Issue