126 lines
2.6 KiB
C#
126 lines
2.6 KiB
C#
|
|
using System.Diagnostics;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using Godot;
|
|
using System.Linq;
|
|
|
|
|
|
namespace Rokojori
|
|
{
|
|
|
|
[Tool]
|
|
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/RenderingManager.svg") ]
|
|
public partial class RenderingManager:Node
|
|
{
|
|
[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();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
[Export]
|
|
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 ) ) );
|
|
}
|
|
}
|
|
|
|
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 );
|
|
}
|
|
}
|
|
} |