From 3b74292b2c4393518c93fdf4e8cf39e2be23aa4d Mon Sep 17 00:00:00 2001 From: Josef Date: Sun, 18 May 2025 19:11:31 +0200 Subject: [PATCH] Shader Library Update --- Runtime/Actions/RJLogMessage.cs | 13 +++- .../EnsureValidFloats/EnsureValidFloats.glsl | 64 +++++++++++++++++++ .../EnsureValidFloats.glsl.import | 14 ++++ .../EnsureValidFloats.import | 14 ++++ .../EnsureValidFloatsEffect.cs | 44 +++++++++++++ .../EnsureValidFloatsEffect.cs.uid | 1 + .../TemporalSmear/TemporalSmear.glsl | 4 +- .../TemporalSmearSimple.glsl | 37 +++++++++++ .../TemporalSmearSimple.glsl.import | 14 ++++ .../TemporalSmearSimpleEffect.cs | 52 +++++++++++++++ .../TemporalSmearSimpleEffect.cs.uid | 1 + .../TemporalSmearWobbly.glsl | 44 +++++++++++++ .../TemporalSmearWobbly.glsl.import | 14 ++++ .../TemporalSmearWobblyEffect.cs | 60 +++++++++++++++++ .../TemporalSmearWobblyEffect.cs.uid | 1 + Runtime/Shading/Library/Cameras.gdshaderinc | 2 + Runtime/Shading/Library/Colors.gdshaderinc | 12 ++++ Runtime/Shading/Library/Depth.gdshaderinc | 2 + ...ering.gdshareinc => Dithering.gdshaderinc} | 2 + .../Shading/Library/Dithering.gdshaderinc.uid | 1 + Runtime/Shading/Library/Light.gdshaderinc | 2 + Runtime/Shading/Library/Line3.gdshaderinc | 2 + Runtime/Shading/Library/Math.gdshaderinc | 2 + Runtime/Shading/Library/NinePatch.gdshaderinc | 2 + Runtime/Shading/Library/Noise.gdshaderinc | 2 + .../Shading/Library/Quaternion.gdshaderinc | 2 + Runtime/Shading/Library/SDF.gdshaderinc | 2 + Runtime/Shading/Library/Textures.gdshaderinc | 2 + Runtime/Shading/Library/Time.gdshaderinc | 2 +- Runtime/Shading/Library/Transform.gdshaderinc | 2 + .../Shading/Library/Validation.gdshaderinc | 38 +++++++++++ .../Library/Validation.gdshaderinc.uid | 1 + 32 files changed, 451 insertions(+), 4 deletions(-) create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.glsl create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.glsl.import create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.import create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloatsEffect.cs create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloatsEffect.cs.uid create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimple.glsl create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimple.glsl.import create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimpleEffect.cs create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimpleEffect.cs.uid create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobbly.glsl create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobbly.glsl.import create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobblyEffect.cs create mode 100644 Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobblyEffect.cs.uid rename Runtime/Shading/Library/{Dithering.gdshareinc => Dithering.gdshaderinc} (86%) create mode 100644 Runtime/Shading/Library/Dithering.gdshaderinc.uid create mode 100644 Runtime/Shading/Library/Validation.gdshaderinc create mode 100644 Runtime/Shading/Library/Validation.gdshaderinc.uid diff --git a/Runtime/Actions/RJLogMessage.cs b/Runtime/Actions/RJLogMessage.cs index d9be67a..3f19fa8 100644 --- a/Runtime/Actions/RJLogMessage.cs +++ b/Runtime/Actions/RJLogMessage.cs @@ -4,15 +4,26 @@ using Godot; namespace Rokojori { + [Tool] [GlobalClass ] public partial class RJLogMessage : Action { [Export] public string message; + [Export] + public bool printPath; + protected override void _OnTrigger() { - RJLog.Log( message ); + if ( printPath ) + { + this.LogInfo( message ); + } + else + { + RJLog.Log( message ); + } } } } \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.glsl b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.glsl new file mode 100644 index 0000000..41cc276 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.glsl @@ -0,0 +1,64 @@ +#[compute] +#version 450 + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +layout(rgba16f, set = 0, binding = 0) +uniform restrict image2D currentImage; + +layout( push_constant, std430 ) +uniform Params +{ + float clamping; + +} parameters; + +float ensureValidFloat( float value ) +{ + if ( isnan( value ) || isinf( value ) ) + { + return 0.0; + } + + return value; +} + +vec4 ensureValidVec4( vec4 value ) +{ + value.r = ensureValidFloat( value.r ); + value.g = ensureValidFloat( value.g ); + value.b = ensureValidFloat( value.b ); + value.a = ensureValidFloat( value.a ); + + return value; +} + + +void main() +{ + ivec2 currentPosition = ivec2( gl_GlobalInvocationID.xy ); + + vec4 currentPixel = imageLoad( currentImage, currentPosition ); + + currentPixel.r = ensureValidFloat( currentPixel.r ); + currentPixel.g = ensureValidFloat( currentPixel.g ); + currentPixel.b = ensureValidFloat( currentPixel.b ); + currentPixel.a = ensureValidFloat( currentPixel.a ); + + if ( parameters.clamping > 0.001 ) + { + currentPixel.r = clamp( currentPixel.r, 0.0, parameters.clamping ); + currentPixel.g = clamp( currentPixel.g, 0.0, parameters.clamping ); + currentPixel.b = clamp( currentPixel.b, 0.0, parameters.clamping ); + currentPixel.a = clamp( currentPixel.a, 0.0, parameters.clamping ); + } + else if ( parameters.clamping < -0.001 ) + { + currentPixel.r = clamp( currentPixel.r, -parameters.clamping, parameters.clamping ); + currentPixel.g = clamp( currentPixel.g, -parameters.clamping, parameters.clamping ); + currentPixel.b = clamp( currentPixel.b, -parameters.clamping, parameters.clamping ); + currentPixel.a = clamp( currentPixel.a, -parameters.clamping, parameters.clamping ); + } + + imageStore( currentImage, currentPosition, currentPixel ); +} diff --git a/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.glsl.import b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.glsl.import new file mode 100644 index 0000000..659933e --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://0kkht5bhowht" +path="res://.godot/imported/EnsureValidFloats.glsl-59be31414366e7772d65bbe705f4d89d.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.glsl" +dest_files=["res://.godot/imported/EnsureValidFloats.glsl-59be31414366e7772d65bbe705f4d89d.res"] + +[params] + diff --git a/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.import b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.import new file mode 100644 index 0000000..2824c4c --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloats.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://dkluasc3h2itv" +path="res://.godot/imported/RemoveInvalid.glsl-c1d3c27c3ad779c1167827e757f40033.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffects/RemoveInvalid/RemoveInvalid.glsl" +dest_files=["res://.godot/imported/RemoveInvalid.glsl-c1d3c27c3ad779c1167827e757f40033.res"] + +[params] + diff --git a/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloatsEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloatsEffect.cs new file mode 100644 index 0000000..99cfae0 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloatsEffect.cs @@ -0,0 +1,44 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class EnsureValidFloatsEffect:SingleShaderCompositorEffect + { + public static readonly string shaderPath = Path( "EnsureValidFloats/EnsureValidFloats.glsl" ); + + [Export( PropertyHint.Range, "-10,10")] + public float clamping = 0f; + + + protected override void OnConfigure() + { + EffectCallbackType = EffectCallbackTypeEnum.PostTransparent; + _shaderPath = shaderPath; + _groupSize = 8; + } + + + protected override void SetConstants() + { + constants.Set( + clamping + ); + } + + + protected override void RenderView() + { + context.AssignScreenColorTexture(); + + context.pushConstants = constants; + + context.ProcessComputeProgram(); + + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloatsEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloatsEffect.cs.uid new file mode 100644 index 0000000..6e6f2ce --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/EnsureValidFloats/EnsureValidFloatsEffect.cs.uid @@ -0,0 +1 @@ +uid://356ufxtti1qp diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmear/TemporalSmear.glsl b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmear/TemporalSmear.glsl index ca822f3..455907c 100644 --- a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmear/TemporalSmear.glsl +++ b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmear/TemporalSmear.glsl @@ -3,10 +3,10 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; -layout(rgba16, set = 0, binding = 0) +layout(rgba16f, set = 0, binding = 0) uniform restrict image2D lastProcessedImage; -layout(rgba16, set = 1, binding = 0) +layout(rgba16f, set = 1, binding = 0) uniform restrict image2D currentImage; layout( push_constant, std430 ) diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimple.glsl b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimple.glsl new file mode 100644 index 0000000..2ffacb4 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimple.glsl @@ -0,0 +1,37 @@ +#[compute] +#version 450 + +#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Validation.gdshaderinc" + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +layout(rgba16f, set = 0, binding = 0) +uniform restrict image2D lastProcessedImage; + +layout(rgba16f, set = 1, binding = 0) +uniform restrict image2D currentImage; + +layout( push_constant, std430 ) +uniform Params +{ + float amount; + float smearing; + +} params; + +void main() +{ + ivec2 currentPosition = ivec2( gl_GlobalInvocationID.xy ); + + vec4 currentPixel = ensureValidVec4( imageLoad( currentImage, currentPosition ) ); + vec4 lastPixel = ensureValidVec4( imageLoad( lastProcessedImage, currentPosition ) ); + + + + vec4 nextPixel = currentPixel + params.smearing * ( lastPixel - currentPixel ); + vec4 combinedPixel = mix( currentPixel, nextPixel, params.amount ); + + + imageStore( currentImage, currentPosition, ensureValidVec4( combinedPixel ) ); + imageStore( lastProcessedImage, currentPosition, ensureValidVec4( nextPixel ) ); +} diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimple.glsl.import b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimple.glsl.import new file mode 100644 index 0000000..44c815e --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimple.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://ctge08k64i4la" +path="res://.godot/imported/TemporalSmearSimple.glsl-5a9ee7695bdb85f5015d509e56453535.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimple.glsl" +dest_files=["res://.godot/imported/TemporalSmearSimple.glsl-5a9ee7695bdb85f5015d509e56453535.res"] + +[params] + diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimpleEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimpleEffect.cs new file mode 100644 index 0000000..de8fa1b --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimpleEffect.cs @@ -0,0 +1,52 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class TemporalSmearSimpleEffect:SingleShaderCompositorEffect + { + public static readonly string shaderPath = Path( "TemporalSmearSimple/TemporalSmearSimple.glsl" ); + + [Export( PropertyHint.Range, "0,1")] + public float amount = 1f; + + [Export( PropertyHint.Range, "0,600")] + public float smearingFrames = 30; + + protected override void OnConfigure() + { + EffectCallbackType = EffectCallbackTypeEnum.PostTransparent; + _shaderPath = shaderPath; + _groupSize = 8; + } + + + protected override void SetConstants() + { + constants.Set( + amount, + 1.0f - FrameSmoothing.ComputeCoefficient( 1f/60f, smearingFrames ) + ); + } + + RDTexture _bufferTexture; + + protected override void RenderView() + { + _bufferTexture = RDTexture.EnsureScreenSizeTexture( _bufferTexture, context ); + + context.AssignTexture( _bufferTexture ); + context.AssignScreenColorTexture(); + + + context.pushConstants = constants; + + context.ProcessComputeProgram(); + + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimpleEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimpleEffect.cs.uid new file mode 100644 index 0000000..059677d --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearSimple/TemporalSmearSimpleEffect.cs.uid @@ -0,0 +1 @@ +uid://bjxayoleund83 diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobbly.glsl b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobbly.glsl new file mode 100644 index 0000000..ee2388c --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobbly.glsl @@ -0,0 +1,44 @@ +#[compute] +#version 450 + +layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; + +layout(rgba16f, set = 0, binding = 0) +uniform restrict image2D lastProcessedImage; + +layout(rgba16f, set = 1, binding = 0) +uniform restrict image2D lastProcessedImage2; + +layout(rgba16f, set = 2, binding = 0) +uniform restrict image2D currentImage; + +layout( push_constant, std430 ) +uniform Params +{ + float amount; + float smearing; + float smearing2; + +} params; + +void main() +{ + ivec2 currentPosition = ivec2( gl_GlobalInvocationID.xy ); + + vec4 currentPixel = imageLoad( currentImage, currentPosition ); + vec4 lastPixel = imageLoad( lastProcessedImage, currentPosition ); + vec4 acceleration = imageLoad( lastProcessedImage2, currentPosition ); + + vec4 difference = currentPixel - lastPixel; + acceleration = mix( acceleration, difference, params.smearing ); + + vec4 nextAcceleration = mix( acceleration, vec4( 0, 0, 0, 0 ), pow( params.smearing, params.smearing2 ) ); + acceleration = mix( nextAcceleration, acceleration, params.smearing ); + + vec4 nextPixel = mix( lastPixel, lastPixel + acceleration, params.smearing ); + + + imageStore( currentImage, currentPosition, mix( currentPixel, nextPixel, params.amount ) ); + imageStore( lastProcessedImage, currentPosition, nextPixel ); + imageStore( lastProcessedImage2, currentPosition, acceleration ); +} diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobbly.glsl.import b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobbly.glsl.import new file mode 100644 index 0000000..d237ebc --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobbly.glsl.import @@ -0,0 +1,14 @@ +[remap] + +importer="glsl" +type="RDShaderFile" +uid="uid://lybi4jv7wky3" +path="res://.godot/imported/TemporalSmearWobbly.glsl-b13fa0c1bd9a842f5cc94ee95d6d6e0f.res" + +[deps] + +source_file="res://addons/rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobbly.glsl" +dest_files=["res://.godot/imported/TemporalSmearWobbly.glsl-b13fa0c1bd9a842f5cc94ee95d6d6e0f.res"] + +[params] + diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobblyEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobblyEffect.cs new file mode 100644 index 0000000..fdfda39 --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobblyEffect.cs @@ -0,0 +1,60 @@ + +using Godot; +using Godot.Collections; +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class TemporalSmearWobblyEffect:SingleShaderCompositorEffect + { + public static readonly string shaderPath = Path( "TemporalSmearWobbly/TemporalSmearWobbly.glsl" ); + + [Export( PropertyHint.Range, "0,1")] + public float amount = 1f; + + [Export( PropertyHint.Range, "0,1")] + public float smearingFrames = 0.1f; + + [Export( PropertyHint.Range, "0,1")] + public float wobblingCoefficient = 0.5f; + + protected override void OnConfigure() + { + EffectCallbackType = EffectCallbackTypeEnum.PostTransparent; + _shaderPath = shaderPath; + _groupSize = 8; + } + + + protected override void SetConstants() + { + constants.Set( + amount, + // 1.0 - FrameSmoothing.ComputeCoefficient( 1f/60f, smearingFrames ), + smearingFrames, + wobblingCoefficient + ); + } + + RDTexture _bufferTexture; + RDTexture _bufferTexture2; + + protected override void RenderView() + { + _bufferTexture = RDTexture.EnsureScreenSizeTexture( _bufferTexture, context ); + _bufferTexture2 = RDTexture.EnsureScreenSizeTexture( _bufferTexture2, context ); + + context.AssignTexture( _bufferTexture ); + context.AssignTexture( _bufferTexture2 ); + context.AssignScreenColorTexture(); + + + context.pushConstants = constants; + + context.ProcessComputeProgram(); + + } + } +} \ No newline at end of file diff --git a/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobblyEffect.cs.uid b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobblyEffect.cs.uid new file mode 100644 index 0000000..e44144c --- /dev/null +++ b/Runtime/Rendering/Compositor/CompositorEffects/TemporalSmearWobbly/TemporalSmearWobblyEffect.cs.uid @@ -0,0 +1 @@ +uid://cbqay1g5qndgr diff --git a/Runtime/Shading/Library/Cameras.gdshaderinc b/Runtime/Shading/Library/Cameras.gdshaderinc index 8dc43c1..df255ba 100644 --- a/Runtime/Shading/Library/Cameras.gdshaderinc +++ b/Runtime/Shading/Library/Cameras.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Cameras.gdshaderinc" + bool cameraContainsLayerIndex( int layerIndex, uint _CAMERA_VISIBLE_LAYERS ) { uint layer = uint( 1 << ( layerIndex - 1 ) ); diff --git a/Runtime/Shading/Library/Colors.gdshaderinc b/Runtime/Shading/Library/Colors.gdshaderinc index ef6612a..c3de4c4 100644 --- a/Runtime/Shading/Library/Colors.gdshaderinc +++ b/Runtime/Shading/Library/Colors.gdshaderinc @@ -1,5 +1,8 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc" + #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" + const float HCV_EPSILON = 1e-10; const float HSL_EPSILON = 1e-10; @@ -195,5 +198,14 @@ vec3 gamma( vec3 color, float gamma ) color.b = pow( color.b, gamma ); return color; +} +vec3 gammaSRGB( vec3 color ) +{ + return gamma( color, 2.2 ); +} + +vec3 gammaSRGBInverse( vec3 color ) +{ + return gamma( color, 1.0/2.2 ); } \ No newline at end of file diff --git a/Runtime/Shading/Library/Depth.gdshaderinc b/Runtime/Shading/Library/Depth.gdshaderinc index d88aa09..4e08152 100644 --- a/Runtime/Shading/Library/Depth.gdshaderinc +++ b/Runtime/Shading/Library/Depth.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Depth.gdshaderinc" + #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc" diff --git a/Runtime/Shading/Library/Dithering.gdshareinc b/Runtime/Shading/Library/Dithering.gdshaderinc similarity index 86% rename from Runtime/Shading/Library/Dithering.gdshareinc rename to Runtime/Shading/Library/Dithering.gdshaderinc index ddb1367..01add82 100644 --- a/Runtime/Shading/Library/Dithering.gdshareinc +++ b/Runtime/Shading/Library/Dithering.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Dithering.gdshaderinc" + const mat4 ditherMatrix = mat4( vec4(0.0625, 0.5625, 0.1875, 0.6875), vec4(0.8125, 0.3125, 0.9375, 0.4375), diff --git a/Runtime/Shading/Library/Dithering.gdshaderinc.uid b/Runtime/Shading/Library/Dithering.gdshaderinc.uid new file mode 100644 index 0000000..a96a3fa --- /dev/null +++ b/Runtime/Shading/Library/Dithering.gdshaderinc.uid @@ -0,0 +1 @@ +uid://cis6wnb86bkfy diff --git a/Runtime/Shading/Library/Light.gdshaderinc b/Runtime/Shading/Library/Light.gdshaderinc index efd9d3b..98abcc9 100644 --- a/Runtime/Shading/Library/Light.gdshaderinc +++ b/Runtime/Shading/Library/Light.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Light.gdshaderinc" + float fresnel( vec3 normal, vec3 view, float amount ) { return pow( ( 1.0 - clamp( dot( normalize( normal ), normalize( view ) ), 0.0, 1.0 ) ), amount ); diff --git a/Runtime/Shading/Library/Line3.gdshaderinc b/Runtime/Shading/Library/Line3.gdshaderinc index 917fb0f..027a674 100644 --- a/Runtime/Shading/Library/Line3.gdshaderinc +++ b/Runtime/Shading/Library/Line3.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Line3.gdshaderinc" + struct Line3 { vec3 start; diff --git a/Runtime/Shading/Library/Math.gdshaderinc b/Runtime/Shading/Library/Math.gdshaderinc index f44c009..b6ed09f 100644 --- a/Runtime/Shading/Library/Math.gdshaderinc +++ b/Runtime/Shading/Library/Math.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" + const float DegreesToRadians = PI/180.0; float clamp01( float value ) diff --git a/Runtime/Shading/Library/NinePatch.gdshaderinc b/Runtime/Shading/Library/NinePatch.gdshaderinc index 7332980..db0f184 100644 --- a/Runtime/Shading/Library/NinePatch.gdshaderinc +++ b/Runtime/Shading/Library/NinePatch.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/NinePatch.gdshaderinc" + #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" void computeNinePatchBorders( vec2 _TEXTURE_PIXEL_SIZE, vec2 renderSize, vec4 pixelBorders, diff --git a/Runtime/Shading/Library/Noise.gdshaderinc b/Runtime/Shading/Library/Noise.gdshaderinc index f10420b..de62ed6 100644 --- a/Runtime/Shading/Library/Noise.gdshaderinc +++ b/Runtime/Shading/Library/Noise.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Noise.gdshaderinc" + float random( vec2 uv ) { return fract( sin( dot( uv.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453123 ); diff --git a/Runtime/Shading/Library/Quaternion.gdshaderinc b/Runtime/Shading/Library/Quaternion.gdshaderinc index d53a2b8..3dfc4cf 100644 --- a/Runtime/Shading/Library/Quaternion.gdshaderinc +++ b/Runtime/Shading/Library/Quaternion.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Qauternion.gdshaderinc" + vec4 quaternionFromMatrix( mat3 m ) { vec4 qa = vec4( 0.0, 0.0, 0.0, 1.0 ); diff --git a/Runtime/Shading/Library/SDF.gdshaderinc b/Runtime/Shading/Library/SDF.gdshaderinc index 1f59af6..8688838 100644 --- a/Runtime/Shading/Library/SDF.gdshaderinc +++ b/Runtime/Shading/Library/SDF.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/SDF.gdshaderinc" + void computeRectangleBounds( float in_offset, float in_radius, float in_maxRadius, vec2 size, out vec2 minP, out vec2 maxP, out float out_radius ) { out_radius = min( in_radius, in_maxRadius ); diff --git a/Runtime/Shading/Library/Textures.gdshaderinc b/Runtime/Shading/Library/Textures.gdshaderinc index 8d7222b..7508632 100644 --- a/Runtime/Shading/Library/Textures.gdshaderinc +++ b/Runtime/Shading/Library/Textures.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Textures.gdshaderinc" + vec4 triplanarTexture( sampler2D sampler, vec3 weights, vec3 triplanerPosition ) { vec4 sample = vec4( 0.0 ); diff --git a/Runtime/Shading/Library/Time.gdshaderinc b/Runtime/Shading/Library/Time.gdshaderinc index 9b32faa..f79426f 100644 --- a/Runtime/Shading/Library/Time.gdshaderinc +++ b/Runtime/Shading/Library/Time.gdshaderinc @@ -1,4 +1,4 @@ - +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Time.gdshaderinc" float timeSine( float _TIME, float duration ) diff --git a/Runtime/Shading/Library/Transform.gdshaderinc b/Runtime/Shading/Library/Transform.gdshaderinc index 9e38c1f..29b6be6 100644 --- a/Runtime/Shading/Library/Transform.gdshaderinc +++ b/Runtime/Shading/Library/Transform.gdshaderinc @@ -1,3 +1,5 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc" + #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Quaternion.gdshaderinc" vec3 applyMatrix( vec3 v, mat4 m ) diff --git a/Runtime/Shading/Library/Validation.gdshaderinc b/Runtime/Shading/Library/Validation.gdshaderinc new file mode 100644 index 0000000..fabeb63 --- /dev/null +++ b/Runtime/Shading/Library/Validation.gdshaderinc @@ -0,0 +1,38 @@ +// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Validation.gdshaderinc" + +float ensureValidFloat( float value ) +{ + if ( isnan( value ) || isinf( value ) ) + { + return 0.0; + } + + return value; +} + +vec2 ensureValidVec2( vec2 value ) +{ + value.x = ensureValidFloat( value.x ); + value.y = ensureValidFloat( value.y ); + + return value; +} + +vec3 ensureValidVec3( vec3 value ) +{ + value.x = ensureValidFloat( value.x ); + value.y = ensureValidFloat( value.y ); + value.z = ensureValidFloat( value.z ); + + return value; +} + +vec4 ensureValidVec4( vec4 value ) +{ + value.x = ensureValidFloat( value.x ); + value.y = ensureValidFloat( value.y ); + value.z = ensureValidFloat( value.z ); + value.w = ensureValidFloat( value.w ); + + return value; +} diff --git a/Runtime/Shading/Library/Validation.gdshaderinc.uid b/Runtime/Shading/Library/Validation.gdshaderinc.uid new file mode 100644 index 0000000..d6478c3 --- /dev/null +++ b/Runtime/Shading/Library/Validation.gdshaderinc.uid @@ -0,0 +1 @@ +uid://f1fmi1v8gqqm