rj-action-library/Runtime/Shading/Generators/Spatial/Albedo/AlbedoModule.cs

86 lines
1.7 KiB
C#
Raw Normal View History

using Godot;
using System.Reflection;
using System.Collections.Generic;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class AlbedoModule:TextureModule
{
public AlbedoModule()
{
_domainName = "albedo";
_domainScaleName = "albedo";
2025-09-17 08:25:03 +00:00
_domainValueName = "albedo";
2025-09-17 08:25:03 +00:00
_target = "ALBEDO";
_srgb = true;
2025-09-17 08:25:03 +00:00
_type = TextureChannelType.RGB;
scaleType = TextureChannelType.RGB;
}
[Export]
public TextureFilter filter = TextureFilter.Linear_MipMap_Anisotropic;
[Export]
public bool useTint = true;
[Export]
public bool srgb = true;
2025-09-17 08:25:03 +00:00
[Export]
public bool writeAlpha = true;
[Export]
public bool repeat = true;
2025-09-17 08:25:03 +00:00
[Export]
public string uvChannel = "UV";
[Export]
public TextureDefault textureDefault = TextureDefault.White;
2025-09-17 08:25:03 +00:00
[Export]
public AssignmentType assignmentType = AssignmentType.Set;
public override void GrabValues()
{
2025-09-17 08:25:03 +00:00
_domainMode = useTint ? DomainMode.Texture_Scale : DomainMode.Texture;
_textureFilter = filter;
_srgb = srgb;
_repeat = repeat;
_textureDefault = textureDefault;
2025-09-17 08:25:03 +00:00
_uvChannel = uvChannel;
_assignmentType = assignmentType;
}
public override List<ShaderVariant> GetVariants( ShaderGenerationContext context )
{
var variants = base.GetVariants( context );
if ( ! writeAlpha || ShaderPhase.Fragment != context.phase )
{
return variants;
}
var value = GetSampledName() + ".a" ;
if ( useTint )
{
value += " * albedo.a";
}
var assignment = " ALPHA *= " + value + ";\n\n";
return ShaderVariant.CombineVariants( variants, ToVariants( ToCode( assignment ) ) );
}
2025-09-17 08:25:03 +00:00
}
}