rj-action-library/Runtime/Rendering/Compositor/SingleShaderCompositorEffec...

72 lines
1.6 KiB
C#
Raw Normal View History

2025-04-23 12:00:43 +00:00
using Godot;
using System.Collections.Generic;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class SingleShaderCompositorEffect:RokojoriCompositorEffect
{
protected string _shaderPath;
protected RDShader _shader;
protected RDPipeline _pipeline;
2025-04-24 13:39:00 +00:00
protected int _groupSize = 16;
2025-04-23 12:00:43 +00:00
protected override void OnInitialize()
{
2025-04-26 20:04:11 +00:00
context.Verbose( "Trying to load shader: ", _shaderPath );
2025-04-23 12:00:43 +00:00
if ( _shaderPath == null )
{
2025-04-26 20:04:11 +00:00
context.Error( "_shaderPath == null" );
2025-04-23 12:00:43 +00:00
return;
}
var glslFile = GD.Load<RDShaderFile>( _shaderPath );
if ( glslFile == null )
{
2025-04-26 20:04:11 +00:00
context.Error( "Couldn't load shader at path:", _shaderPath );
2025-04-23 12:00:43 +00:00
return;
}
2025-04-26 20:04:11 +00:00
_shader = RDShader.CreateFromSpirV( context, glslFile.GetSpirV() );
2025-04-23 12:00:43 +00:00
if ( _shader == null )
{
2025-04-26 20:04:11 +00:00
context.Error( "Couldn't create shader from code, path:", _shaderPath );
2025-04-23 12:00:43 +00:00
return;
}
2025-04-26 20:04:11 +00:00
_pipeline = RDPipeline.Create( context, _shader );
2025-04-23 12:00:43 +00:00
if ( _shader == null )
{
2025-04-26 20:04:11 +00:00
context.Error( "Couldn't create pipeline from compiled shader, path:", _shaderPath );
2025-04-23 12:00:43 +00:00
return;
}
2025-04-26 20:04:11 +00:00
context.Verbose( "Created shader at path: ", _shaderPath );
2025-04-23 12:00:43 +00:00
context.SetShaderAndPipeline( _shader, _pipeline );
}
2025-04-24 13:39:00 +00:00
protected RDPushConstants _constants = new RDPushConstants();
public RDPushConstants constants => _constants;
protected override void ForAllViews()
{
2025-04-26 20:04:11 +00:00
context.CalculateComputeGroups( _groupSize );
2025-04-24 13:39:00 +00:00
SetConstants();
}
protected virtual void SetConstants()
{
}
2025-04-23 12:00:43 +00:00
}
}