Shader Library Update

This commit is contained in:
Josef 2025-05-18 19:11:31 +02:00
parent 7de06b4bcd
commit 3b74292b2c
32 changed files with 451 additions and 4 deletions

View File

@ -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 );
}
}
}
}

View File

@ -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 );
}

View File

@ -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]

View File

@ -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]

View File

@ -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();
}
}
}

View File

@ -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 )

View File

@ -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 ) );
}

View File

@ -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]

View File

@ -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();
}
}
}

View File

@ -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 );
}

View File

@ -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]

View File

@ -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();
}
}
}

View File

@ -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 ) );

View File

@ -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 );
}

View File

@ -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"

View File

@ -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),

View File

@ -0,0 +1 @@
uid://cis6wnb86bkfy

View File

@ -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 );

View File

@ -1,3 +1,5 @@
// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Line3.gdshaderinc"
struct Line3
{
vec3 start;

View File

@ -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 )

View File

@ -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,

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -1,4 +1,4 @@
// #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Time.gdshaderinc"
float timeSine( float _TIME, float duration )

View File

@ -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 )

View File

@ -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;
}

View File

@ -0,0 +1 @@
uid://f1fmi1v8gqqm