rj-action-library/Runtime/Rendering/RenderingManager.cs

126 lines
2.6 KiB
C#
Raw Normal View History

2025-08-31 06:05:39 +00:00
using System.Diagnostics;
2024-12-01 17:07:41 +00:00
using System.Collections;
using System.Collections.Generic;
2025-08-31 06:05:39 +00:00
using System;
using Godot;
2025-10-24 11:38:51 +00:00
using System.Linq;
2025-08-31 06:05:39 +00:00
2024-12-01 17:07:41 +00:00
namespace Rokojori
{
2025-10-24 11:38:51 +00:00
[Tool]
2025-09-21 07:35:17 +00:00
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/RenderingManager.svg") ]
2025-08-31 06:05:39 +00:00
public partial class RenderingManager:Node
{
2025-10-24 11:38:51 +00:00
[ExportToolButton( "Ensure Global Shader Properties")]
public Callable ensureGlobalShaderPropertiesButton => Callable.From(
()=>
{
EnsureGlobalShaderProperties();
}
);
void EnsureGlobalShaderProperties()
{
for ( int i = 0; i < data.numGlobalShaderProperties; i++ )
{
var p = data.GetGlobalShaderPropertyAt( i );
if ( p == null )
{
continue;
}
p.AddAsGlobalUniform();
}
}
2024-12-01 17:07:41 +00:00
[Export]
2025-10-24 11:38:51 +00:00
public bool ensureGlobalShaderPropertiesOnReady = true;
[Export]
public RenderingManagerData data = new RenderingManagerData();
List<AssignedShaderProperty> _assignedProperties = new List<AssignedShaderProperty>();
public override void _Ready()
{
if ( ! ensureGlobalShaderPropertiesOnReady )
{
return;
}
EnsureGlobalShaderProperties();
}
public override void _Process( double delta )
{
UpdateProperties();
}
void UpdateProperties()
{
if ( data == null )
{
return;
}
if ( _assignedProperties.Count != data.numGlobalShaderProperties )
{
CreatePropertyList();
}
for ( int i = 0; i < data.numGlobalShaderProperties; i++ )
{
var p = data.GetGlobalShaderPropertyAt( i );
if ( p != _assignedProperties[ i ].property )
{
_assignedProperties.Clear();
CreatePropertyList();
UpdateProperties();
return;
}
_assignedProperties[ i ].Update();
}
}
void CreatePropertyList()
{
_assignedProperties.Clear();
for ( int i = 0; i < data.numGlobalShaderProperties; i++ )
{
_assignedProperties.Add( AssignedShaderProperty.From( data.GetGlobalShaderPropertyAt( i ) ) );
}
}
2025-09-17 08:25:03 +00:00
public static int GetStencilReferenceIndex( StencilLayer stencilLayer )
{
if ( stencilLayer == null )
{
return -1;
}
var rm = Unique<RenderingManager>.Get();
if ( rm == null )
{
return stencilLayer.fallBackIndex;
}
var rmIndex = rm.data.stencilLayers.IndexOf( stencilLayer );
return rmIndex == -1 ? stencilLayer.fallBackIndex : ( rmIndex + 1 );
}
2024-12-01 17:07:41 +00:00
}
}