2025-09-21 07:35:17 +00:00
|
|
|
using Godot;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
|
|
|
[Tool]
|
|
|
|
[GlobalClass]
|
|
|
|
public partial class VertexUVSource:UVSource
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public VertexTransformSpace space;
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public VertexSwizzleType dimensions;
|
|
|
|
|
2025-09-26 12:00:59 +00:00
|
|
|
[Export]
|
|
|
|
public bool useDimensionsOffset = false;
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public VertexSwizzleType dimensionsOffset;
|
|
|
|
|
2025-09-21 07:35:17 +00:00
|
|
|
[Export]
|
|
|
|
public string sizeCustomName;
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public string centerCustomName;
|
|
|
|
|
|
|
|
public override List<ShaderCode> GetUV( ShaderGenerationContext context, string target, int offsetIndex )
|
|
|
|
{
|
2025-09-26 12:00:59 +00:00
|
|
|
var size = sizeCustomName == null || sizeCustomName == "" ? "vertexUVSourceSize" : sizeCustomName;
|
|
|
|
var center = centerCustomName == null || centerCustomName == "" ? "vertexUVSourceCenter" : centerCustomName;
|
2025-09-21 07:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
var suffix = offsetIndex == 0 ? "" : ( "_" + ( offsetIndex + 1 ) );
|
|
|
|
|
|
|
|
size += suffix;
|
|
|
|
center += suffix;
|
|
|
|
|
|
|
|
if ( ShaderPhase.Includes == context.phase )
|
|
|
|
{
|
2025-09-26 12:00:59 +00:00
|
|
|
return ShaderGenerationModule.IncludeUVLibrary().Concat( IncludeTransformLibrary() );
|
2025-09-21 07:35:17 +00:00
|
|
|
}
|
|
|
|
else if ( ShaderPhase.Variables == context.phase )
|
|
|
|
{
|
|
|
|
var uniforms =
|
|
|
|
@$"
|
|
|
|
|
|
|
|
uniform vec2 {size};
|
|
|
|
uniform vec2 {center};
|
|
|
|
|
|
|
|
";
|
|
|
|
|
|
|
|
return ShaderGenerationModule.ToCode( uniforms.Indent( "" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ShaderPhase.Vertex != context.phase )
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var member = ( dimensions + "" ).ToLower();
|
2025-09-26 12:00:59 +00:00
|
|
|
var offset = " + vertex." + ( dimensionsOffset + "" ).ToLower();
|
|
|
|
|
|
|
|
if ( ! useDimensionsOffset )
|
|
|
|
{
|
|
|
|
offset = "";
|
|
|
|
}
|
2025-09-21 07:35:17 +00:00
|
|
|
var vertex = "VERTEX";
|
|
|
|
|
|
|
|
if ( VertexTransformSpace.World == space )
|
|
|
|
{
|
|
|
|
vertex = "localToWorld( VERTEX, MODEL_MATRIX )";
|
|
|
|
}
|
|
|
|
else if ( VertexTransformSpace.View == space )
|
|
|
|
{
|
|
|
|
vertex = "localToView( VERTEX, MODELVIEW_MATRIX )";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var code =
|
|
|
|
@$"
|
|
|
|
|
|
|
|
{{
|
|
|
|
vec3 vertex = {vertex};
|
2025-09-26 12:00:59 +00:00
|
|
|
{target} = mapUV( vertex.{member}{offset}, {size}, {center} );
|
2025-09-21 07:35:17 +00:00
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
";
|
|
|
|
|
|
|
|
return ShaderGenerationModule.ToCode( code.Indent( " ") );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|