From 966cb7e28cca5a32fa5135bf26541bba819739d6 Mon Sep 17 00:00:00 2001 From: Josef Date: Sun, 27 Apr 2025 14:55:54 +0200 Subject: [PATCH] Chromatic Aberation --- .../ChromaticAberation/ChromaticAberation.cs | 82 +++++++++++++++++++ .../ChromaticAberation.cs.uid | 1 + .../CEG_ChromaticAberation.cs | 17 ++++ .../CEG_ChromaticAberation.cs.uid | 1 + .../ChromaticAberation.glsl | 52 ++++++++++++ .../ChromaticAberation.glsl.import | 14 ++++ Runtime/Rendering/RenderGraph/RDGraph.cs | 2 +- 7 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/ChromaticAberation/ChromaticAberation.cs create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/ChromaticAberation/ChromaticAberation.cs.uid create mode 100644 Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/CEG_ChromaticAberation.cs create mode 100644 Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/CEG_ChromaticAberation.cs.uid create mode 100644 Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl create mode 100644 Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl.import diff --git a/Runtime/Rendering/Compositor/CompositorEffects/ChromaticAberation/ChromaticAberation.cs b/Runtime/Rendering/Compositor/CompositorEffects/ChromaticAberation/ChromaticAberation.cs new file mode 100644 index 0000000..b6a5c76 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/ChromaticAberation/ChromaticAberation.cs @@ -0,0 +1,82 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class ChromaticAberation:RDGraphCompositorEffect + { + public ChromaticAberation():base() + { + Initialize(); + } + + + [Export] + public float intensity = 0.5f; + + [Export] + public float shiftAll = 0.5f; + + [Export] + public float unshiftCenter = 16f; + + [Export] + public Vector2 rShift = new Vector2( -0.001f, 0.0f ); + + [Export] + public Vector2 gShift = new Vector2( 0.0f, 0.0f ); + + [Export] + public Vector2 bShift = new Vector2( 0.001f, 0.0f ); + + + + CEG_ScreenColorTexure screenColorTexture; + CEG_BufferTexture bufferTexture; + + CEG_Copy copy; + CEG_ChromaticAberation chromaticAberation; + + void Initialize() + { + screenColorTexture = new CEG_ScreenColorTexure( graph ); + bufferTexture = CEG_BufferTexture.ScreenSize( graph ); + + copy = new CEG_Copy( graph ); + chromaticAberation = new CEG_ChromaticAberation( graph ); + + + graph.InitializeNodes(); + + + + copy.SetTextureSlotInputs( screenColorTexture, bufferTexture ); + chromaticAberation.SetTextureSlotInputs( copy.output, copy.input ); + + + graph.SetProcessOrder( + screenColorTexture, bufferTexture, + copy, chromaticAberation + ); + } + + + protected override void ForAllViews() + { + chromaticAberation.constants.Set( + intensity, + shiftAll, + unshiftCenter, + rShift, + gShift, + bShift + ); + } + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/ChromaticAberation/ChromaticAberation.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/ChromaticAberation/ChromaticAberation.cs.uid new file mode 100644 index 0000000..0de9651 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/ChromaticAberation/ChromaticAberation.cs.uid @@ -0,0 +1 @@ +uid://cghyn18utdfl diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/CEG_ChromaticAberation.cs b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/CEG_ChromaticAberation.cs new file mode 100644 index 0000000..0a5eeab --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/CEG_ChromaticAberation.cs @@ -0,0 +1,17 @@ + +using Godot; +using System.Collections.Generic; + +namespace Rokojori +{ + public class CEG_ChromaticAberation:CEG_ImageProcessor + { + public static readonly string shaderPath = + RDGraph.Path( "Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl" ); + + public CEG_ChromaticAberation( RDGraph graph ):base( graph, shaderPath ) + {} + + + } +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/CEG_ChromaticAberation.cs.uid b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/CEG_ChromaticAberation.cs.uid new file mode 100644 index 0000000..6402a3c --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/CEG_ChromaticAberation.cs.uid @@ -0,0 +1 @@ +uid://cse0v4j8d7e1w diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl new file mode 100644 index 0000000..23e9df0 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl @@ -0,0 +1,52 @@ +#[compute] +#version 450 + +layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in; + +layout( rgba16f, set = 0, binding = 0 ) +uniform image2D inputImage; +layout( rgba16f, set = 1, binding = 0 ) +uniform image2D outputImage; + + +layout( push_constant, std430 ) +uniform Params +{ + float amount; + float shiftAll; + float unshiftCenter; + vec2 rShift; + vec2 gShift; + vec2 bShift; + +} params; + +void main( ) +{ + ivec2 size = imageSize( inputImage ); + ivec2 texel_coord = ivec2( gl_GlobalInvocationID.xy ); + + if ( any( greaterThanEqual( texel_coord, size ) ) ) + { + return; + } + + vec2 uv = ( vec2( texel_coord ) + 0.5 ) / vec2( size ); + + + vec2 uvR = uv + params.rShift * params.shiftAll; + vec2 uvG = uv + params.gShift * params.shiftAll; + vec2 uvB = uv + params.bShift * params.shiftAll; + + float r = imageLoad( inputImage, ivec2( uvR * size ) ).r; + float g = imageLoad( inputImage, ivec2( uvG * size ) ).g; + float b = imageLoad( inputImage, ivec2( uvB * size ) ).b; + + vec4 chromaticColor = vec4( r, g, b, 1 ); + + vec4 color = imageLoad( inputImage, ivec2( uv * size ) ); + vec4 blended = mix( color, chromaticColor, params.amount ); + + + imageStore( outputImage, texel_coord, blended ); +} \ No newline at end of file diff --git a/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl.import b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl.import new file mode 100644 index 0000000..17275a2 --- /dev/null +++ b/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://dnd8b80wfam5n" +path="res://.godot/imported/ChromaticAberation.glsl-71eb2b3b033550490408285e80a1dcf1.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph/Nodes/Processors/Color/ChromaticAberation/ChromaticAberation.glsl" +dest_files=["res://.godot/imported/ChromaticAberation.glsl-71eb2b3b033550490408285e80a1dcf1.res"] + +[params] + diff --git a/Runtime/Rendering/RenderGraph/RDGraph.cs b/Runtime/Rendering/RenderGraph/RDGraph.cs index 0df1adb..665c612 100644 --- a/Runtime/Rendering/RenderGraph/RDGraph.cs +++ b/Runtime/Rendering/RenderGraph/RDGraph.cs @@ -13,7 +13,7 @@ namespace Rokojori protected RDContext _context; public RDContext context => _context; - public static readonly string path = "res://addons/rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffectGraph"; + public static readonly string path = "res://addons/rokojori_action_library/Runtime/Rendering/RenderGraph"; public static string Path( string subPath ) { return path + "/" + subPath;