2025-04-23 12:00:43 +00:00
|
|
|
|
|
|
|
using Godot;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
|
|
|
public class CompositorEffectShaderProcessor:CompositorEffectGraphProcessor
|
|
|
|
{
|
|
|
|
protected string _shaderPath;
|
|
|
|
|
|
|
|
public CompositorEffectShaderProcessor( _XX_CompositorEffectGraph graph, string shaderPath ):base( graph )
|
|
|
|
{
|
|
|
|
this._shaderPath = shaderPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected RDShader _shader;
|
|
|
|
protected RDPipeline _pipeline;
|
|
|
|
protected RDPushConstants _constants;
|
2025-04-24 13:39:00 +00:00
|
|
|
public RDPushConstants constants => _constants;
|
|
|
|
protected Vector3I _groupSize = new Vector3I( 8, 8, 0 );
|
|
|
|
protected List<CompositorEffectGraphTextureSlot> _textureSlots = new List<CompositorEffectGraphTextureSlot>();
|
2025-04-23 12:00:43 +00:00
|
|
|
|
|
|
|
protected override void OnInitialize()
|
|
|
|
{
|
|
|
|
graph.Verbose( "Trying to load shader: ", _shaderPath );
|
|
|
|
|
|
|
|
if ( _shaderPath == null )
|
|
|
|
{
|
|
|
|
graph.Error( "_shaderPath == null" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var glslFile = GD.Load<RDShaderFile>( _shaderPath );
|
|
|
|
|
|
|
|
if ( glslFile == null )
|
|
|
|
{
|
|
|
|
graph.Error( "Couldn't load shader at path:", _shaderPath );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_shader = RDShader.CreateFromSpirV( graph, glslFile.GetSpirV() );
|
|
|
|
|
|
|
|
if ( _shader == null )
|
|
|
|
{
|
|
|
|
graph.Error( "Couldn't create shader from code, path:", _shaderPath );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_pipeline = RDPipeline.Create( graph, _shader );
|
|
|
|
|
|
|
|
if ( _shader == null )
|
|
|
|
{
|
|
|
|
graph.Error( "Couldn't create pipeline from compiled shader, path:", _shaderPath );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
graph.Verbose( "Created shader at path: ", _shaderPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Process()
|
|
|
|
{
|
|
|
|
var context = graph.context;
|
|
|
|
|
|
|
|
context.Clear();
|
2025-04-24 13:39:00 +00:00
|
|
|
context.ComputeGroups( _groupSize );
|
2025-04-23 12:00:43 +00:00
|
|
|
context.SetShaderAndPipeline( _shader, _pipeline );
|
|
|
|
|
2025-04-24 13:39:00 +00:00
|
|
|
_textureSlots.ForEach( t =>
|
|
|
|
{
|
|
|
|
t.ResolveTexture();
|
|
|
|
graph.context.AssignUniformSet_Texture( t.GetTexture(), t.sampler );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2025-04-23 12:00:43 +00:00
|
|
|
|
|
|
|
context.pushConstants = _constants;
|
|
|
|
|
|
|
|
context.Render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|