rj-action-library/Runtime/Rendering/CompositorEffects/DepthView/DepthViewEffect.cs

64 lines
1.4 KiB
C#

using Godot;
using Godot.Collections;
using System.Collections.Generic;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class DepthViewEffect:SingleShaderCompositorEffect
{
public static readonly string shaderPath =
RokojoriPlugin.Path( "Runtime/Rendering/CompositorEffects/DepthView/DepthViewShader.glsl" );
RDPushConstants constants = new RDPushConstants();
RDSampler sampler;
[Export( PropertyHint.Range, "0,1") ]
public float greyAmount;
[Export( PropertyHint.Range, "0,1") ]
public float depthAmount;
[Export( PropertyHint.Range, "0.001,3") ]
public float depthPower;
protected override void OnConfigure()
{
EffectCallbackType = EffectCallbackTypeEnum.PostTransparent;
_shaderPath = shaderPath;
_groupSize = 8;
}
protected override void OnInitialize()
{
base.OnInitialize();
sampler = Sampler( RenderingDevice.SamplerFilter.Nearest, RenderingDevice.SamplerRepeatMode.ClampToEdge );
}
protected override void ForAllViews()
{
constants.Set(
(Vector2)context.internalSize,
new Vector2( greyAmount, depthAmount ),
depthPower
);
}
protected override void RenderView()
{
context.Assign_ScreenColorTexture();
context.Assign_ScreenDepthTexture( sampler );
context.pushConstants = constants;
context.Render();
}
}
}