rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffects/Vignette/VignetteEffect.cs

103 lines
2.1 KiB
C#
Raw Normal View History

2025-07-22 14:08:22 +00:00
using Godot;
using Godot.Collections;
using System.Collections.Generic;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class VignetteEffect:SingleShaderCompositorEffect
{
public static readonly string shaderPath = Path( "Vignette/VignetteShader.glsl" );
2025-12-14 12:18:57 +00:00
[ExportGroup("Vignette")]
2025-07-22 14:08:22 +00:00
[Export( PropertyHint.Range, "0,1")]
public float amount = 1.0f;
2025-12-14 12:18:57 +00:00
[Export( PropertyHint.Range, "-1,1")]
public float fadePosition;
[Export( PropertyHint.Range, "-2,2")]
public float fadeInOffset = -0.1f;
[Export( PropertyHint.Range, "-2,2")]
public float fadeOutOffset= 0.1f;
[Export( PropertyHint.Range, "-10,10")]
public float fadePower= 1f;
[Export( PropertyHint.Range, "0,1")]
public float ellipseToCircle= 0.5f;
[ExportGroup("Colors")]
2025-07-22 14:08:22 +00:00
[Export]
2025-12-14 12:18:57 +00:00
public Color colorTop = Colors.Black;
2025-07-22 14:08:22 +00:00
[Export]
2025-12-14 12:18:57 +00:00
public Color colorBottom = Colors.Black;
[ExportGroup("Blend Mode")]
[Export]
public float replace = 1.0f;
2025-07-22 14:08:22 +00:00
[Export]
2025-12-14 12:18:57 +00:00
public float add = 0.0f;
2025-07-22 14:08:22 +00:00
[Export]
2025-12-14 12:18:57 +00:00
public float multiply = 0.0f;
[Export]
public float colorize = 0.0f;
2025-07-22 14:08:22 +00:00
2025-09-28 08:42:28 +00:00
[Export]
public string info = "";
2025-07-22 14:08:22 +00:00
protected override void OnConfigure()
{
EffectCallbackType = EffectCallbackTypeEnum.PostTransparent;
_shaderPath = shaderPath;
_groupSize = 8;
}
protected override void SetConstants()
{
constants.Set(
2025-12-14 12:18:57 +00:00
colorTop.SrgbToLinear(),
colorBottom.SrgbToLinear(),
(Vector2) context.internalSize,
2025-07-22 14:08:22 +00:00
amount,
2025-12-14 12:18:57 +00:00
fadePosition + fadeInOffset,
fadePosition + fadeOutOffset,
ellipseToCircle,
Mathf.Pow( 10f, fadePower / 10f ),
replace,
add,
multiply,
colorize
2025-07-22 14:08:22 +00:00
);
2025-09-28 08:42:28 +00:00
info = "constants: " + constants.info;
2025-07-22 14:08:22 +00:00
}
2025-09-28 08:42:28 +00:00
public override void ClearCaches()
{
base.ClearCaches();
}
2025-07-22 14:08:22 +00:00
protected override void RenderView()
{
context.AssignScreenColorTexture();
context.pushConstants = constants;
context.ProcessComputeProgram();
}
}
}