using Godot; using System.Collections.Generic; namespace Rokojori { public class RDShaderProcessor:RGGraphProcessor { protected string _shaderPath; public RDShaderProcessor( RDGraph graph, string shaderPath ):base( graph ) { this._shaderPath = shaderPath; } protected RDShader _shader; protected RDPipeline _pipeline; protected RDPushConstants _constants = new RDPushConstants(); public RDPushConstants constants => _constants; protected Vector3I _groupSize = new Vector3I( 8, 8, 0 ); protected List _textureSlots = new List(); protected override void OnInitialize() { graph.context.Verbose( "Trying to load shader: ", _shaderPath ); if ( _shaderPath == null ) { graph.context.Error( "_shaderPath == null" ); return; } var glslFile = GD.Load( _shaderPath ); if ( glslFile == null ) { graph.context.Error( "Couldn't load shader at path:", _shaderPath ); return; } _shader = RDShader.CreateFromSpirV( graph.context, glslFile.GetSpirV() ); if ( _shader == null ) { graph.context.Error( "Couldn't create shader from code, path:", _shaderPath ); return; } _pipeline = RDPipeline.Create( graph.context, _shader ); if ( _shader == null ) { graph.context.Error( "Couldn't create pipeline from compiled shader, path:", _shaderPath ); return; } graph.context.Verbose( "Created shader at path: ", _shaderPath ); } public override void Process() { var context = graph.context; context.Clear(); context.CalculateComputeGroups( _groupSize ); context.SetShaderAndPipeline( _shader, _pipeline ); _textureSlots.ForEach( t => { t.ResolveTexture(); graph.context.AssignTexture( t.GetTexture(), t.sampler ); } ); if ( _constants.size > 0 ) { context.pushConstants = _constants; } context.ProcessComputeProgram(); } } }