KST-1
This commit is contained in:
parent
927a387756
commit
f3c42733cf
|
|
@ -1,8 +1,18 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
namespace KarrotStarterTemplate.Common.CameraController;
|
||||
|
||||
public enum ECameraControllerInputType
|
||||
{
|
||||
None,
|
||||
TopDown,
|
||||
FirstPerson,
|
||||
ThirdPerson
|
||||
|
||||
}
|
||||
|
||||
[GlobalClass]
|
||||
public partial class CharacterCameraController : Node3D
|
||||
{
|
||||
|
|
@ -11,7 +21,7 @@ public partial class CharacterCameraController : Node3D
|
|||
|
||||
[ExportCategory("Properties")]
|
||||
[ExportGroup("Mouse input")]
|
||||
[Export] public bool enableInput = true;
|
||||
[Export] public ECameraControllerInputType inputType = ECameraControllerInputType.None;
|
||||
[Export] public float mouseSensitivity { get; set; } = .5f;
|
||||
[Export] public Vector2 cameraTiltLimit { get; set; } = new(-45f, 45f);
|
||||
|
||||
|
|
@ -52,7 +62,7 @@ public partial class CharacterCameraController : Node3D
|
|||
return;
|
||||
}
|
||||
|
||||
if (!enableInput)
|
||||
if (inputType == ECameraControllerInputType.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -83,18 +93,36 @@ public partial class CharacterCameraController : Node3D
|
|||
{
|
||||
float weight = Mathf.Clamp(20 * (1 - rotateDelay) * (float)delta, 0,1 );
|
||||
Vector3 v = characterToFollow.GlobalRotation;
|
||||
characterToFollow.GlobalRotation = new Vector3(v.X, Mathf.LerpAngle(v.Y, _springArm.GlobalRotation.Y, weight) , v.Z);
|
||||
|
||||
switch (inputType)
|
||||
{
|
||||
|
||||
case ECameraControllerInputType.None:
|
||||
break;
|
||||
case ECameraControllerInputType.TopDown:
|
||||
var (x, y, z) = GetMouseIntersectedDirection();
|
||||
characterToFollow.GlobalRotation = new Vector3(v.X, Mathf.LerpAngle(v.Y, -Mathf.Atan2(-x, z), weight) , v.Z);
|
||||
break;
|
||||
case ECameraControllerInputType.FirstPerson:
|
||||
case ECameraControllerInputType.ThirdPerson:
|
||||
characterToFollow.GlobalRotation = new Vector3(v.X, Mathf.LerpAngle(v.Y, _springArm.GlobalRotation.Y, weight) , v.Z);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (enableInput)
|
||||
switch (inputType)
|
||||
{
|
||||
_springArm.Rotation += new Vector3(_mouseInput.Y * (float)delta, 0f, 0f);
|
||||
Rotation += new Vector3(0f, _mouseInput.X * (float)delta, characterToFollow.GlobalPosition.Y);
|
||||
|
||||
var (x, y, z) = _springArm.RotationDegrees;
|
||||
_springArm.RotationDegrees = new Vector3(Mathf.Clamp(x, cameraTiltLimit.X, cameraTiltLimit.Y), y, z);
|
||||
case ECameraControllerInputType.FirstPerson:
|
||||
case ECameraControllerInputType.ThirdPerson:
|
||||
_springArm.Rotation += new Vector3(_mouseInput.Y * (float)delta, 0f, 0f);
|
||||
Rotation += new Vector3(0f, _mouseInput.X * (float)delta, characterToFollow.GlobalPosition.Y);
|
||||
|
||||
_mouseInput = Vector2.Zero;
|
||||
var (x, y, z) = _springArm.RotationDegrees;
|
||||
_springArm.RotationDegrees = new Vector3(Mathf.Clamp(x, cameraTiltLimit.X, cameraTiltLimit.Y), y, z);
|
||||
|
||||
_mouseInput = Vector2.Zero;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,30 +133,21 @@ public partial class CharacterCameraController : Node3D
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed("click"))
|
||||
{
|
||||
var position2D = GetViewport().GetMousePosition();
|
||||
var dropPlane = new Plane(new Vector3(0, 10f, 0), 0f);
|
||||
var position3D =
|
||||
dropPlane.IntersectsRay(camera.ProjectRayOrigin(position2D), camera.ProjectRayNormal(position2D));
|
||||
if (position3D != null)
|
||||
{
|
||||
GD.Print(position3D);
|
||||
DebugDraw3D.DrawSphere(position3D ?? Vector3.Zero, .5f, Colors.Aqua, 2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Vector3 GetMouseIntersectedPosition()
|
||||
{
|
||||
var position2D = GetViewport().GetMousePosition();
|
||||
var dropPlane = new Plane(new Vector3(0, 10f, 0), 0f);
|
||||
var position3D =
|
||||
dropPlane.IntersectsRay(camera.ProjectRayOrigin(position2D), camera.ProjectRayNormal(position2D));
|
||||
|
||||
|
||||
return position3D ?? Vector3.Zero;
|
||||
}
|
||||
|
||||
public virtual Vector3 GetMouseIntersectedDirection()
|
||||
{
|
||||
return (characterToFollow.GlobalPosition - GetMouseIntersectedPosition()).Normalized();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
TODO:
|
||||
1. Zrobić enuma z presetami
|
||||
|
||||
if Input.is_action_pressed("click"):
|
||||
var position2D = get_viewport().get_mouse_position()
|
||||
var dropPlane = Plane(Vector3(0, 0, 10), z)
|
||||
var position3D = dropPlane.intersects_ray(camera.project_ray_origin(position2D),camera.project_ray_normal(position2D))
|
||||
print(position3D)
|
||||
|
||||
*/
|
||||
|
|
@ -11,10 +11,10 @@ shader_parameter/point_size = 0.0
|
|||
shader_parameter/roughness = 0.7
|
||||
shader_parameter/metallic_texture_channel = null
|
||||
shader_parameter/specular = 0.5
|
||||
shader_parameter/metallic = null
|
||||
shader_parameter/metallic = 1.0
|
||||
shader_parameter/uv1_blend_sharpness = 1.0
|
||||
shader_parameter/uv1_scale = Vector3(0.5, 0.5, 0.5)
|
||||
shader_parameter/uv1_offset = null
|
||||
shader_parameter/uv2_scale = Vector3(1, 1, 1)
|
||||
shader_parameter/uv2_scale = Vector3(0.5, 0.5, 0.5)
|
||||
shader_parameter/uv2_offset = null
|
||||
shader_parameter/texture_albedo = ExtResource("2_nnk68")
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ ignoreUpDirection = true
|
|||
acceleration = 1.0
|
||||
deceleration = 1.0
|
||||
gravityScale = 1.0
|
||||
rotationRate = 360.0
|
||||
rotationRate = 0.0
|
||||
|
||||
[sub_resource type="Resource" id="Resource_gjtqv"]
|
||||
script = ExtResource("2_bpavf")
|
||||
|
|
@ -125,7 +125,7 @@ input_2/reset = true
|
|||
"nodes/Animation 2/node" = SubResource("AnimationNodeAnimation_dj5mk")
|
||||
"nodes/Animation 2/position" = Vector2(-508.316, 402.128)
|
||||
nodes/LocomotionBlendspace/node = SubResource("AnimationNodeBlendSpace2D_4j2fv")
|
||||
nodes/LocomotionBlendspace/position = Vector2(-600, -140)
|
||||
nodes/LocomotionBlendspace/position = Vector2(-1000, -220)
|
||||
"nodes/Roll anim/node" = SubResource("AnimationNodeAnimation_er75r")
|
||||
"nodes/Roll anim/position" = Vector2(-520, 200)
|
||||
nodes/TimeScale/node = SubResource("AnimationNodeTimeScale_3il3w")
|
||||
|
|
@ -197,8 +197,7 @@ unique_name_in_owner = true
|
|||
top_level = true
|
||||
script = ExtResource("1_8tlkf")
|
||||
characterToFollow = NodePath("..")
|
||||
enableInput = false
|
||||
rotatePlayer = false
|
||||
inputType = 1
|
||||
|
||||
[node name="SpringArm3D" type="SpringArm3D" parent="CameraController"]
|
||||
transform = Transform3D(0.707107, -0.5, 0.5, 0, 0.707107, 0.707107, -0.707107, -0.5, 0.5, 0, 0.9, 0)
|
||||
|
|
@ -218,81 +217,81 @@ transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0,
|
|||
|
||||
[node name="Skeleton3D" parent="XBot2/XBot" index="0"]
|
||||
bones/0/position = Vector3(-0.0094865, 1.25185e-09, 0.0105013)
|
||||
bones/1/position = Vector3(-6.98528e-08, 1.0277, 0.0153483)
|
||||
bones/1/rotation = Quaternion(-0.0299539, -0.36772, -0.0121686, 0.929374)
|
||||
bones/1/position = Vector3(-6.41051e-08, 1.01664, 0.0152059)
|
||||
bones/1/rotation = Quaternion(-0.00179556, 0.0132419, -0.0480843, 0.998754)
|
||||
bones/1/scale = Vector3(1, 1, 1)
|
||||
bones/2/rotation = Quaternion(-0.029804, 0.0412832, -0.00444647, 0.998693)
|
||||
bones/3/rotation = Quaternion(0.100643, 0.0829519, -0.00643562, 0.991438)
|
||||
bones/4/rotation = Quaternion(0.11341, 0.082862, -0.00750396, 0.990058)
|
||||
bones/5/rotation = Quaternion(-0.03756, -0.0112204, 0.000859207, 0.999231)
|
||||
bones/6/rotation = Quaternion(-0.0544206, 0.177227, 0.00865648, 0.982626)
|
||||
bones/8/rotation = Quaternion(-0.579974, 0.502586, -0.515842, -0.380717)
|
||||
bones/2/rotation = Quaternion(-0.0736139, -0.0134737, 0.0248121, 0.996887)
|
||||
bones/3/rotation = Quaternion(-0.00239047, -0.00699569, 0.0513199, 0.998655)
|
||||
bones/4/rotation = Quaternion(0.0104128, -0.000845129, 0.0512795, 0.99863)
|
||||
bones/5/rotation = Quaternion(0.00871049, -0.000173571, -0.0189319, 0.999783)
|
||||
bones/6/rotation = Quaternion(0.0126036, 0.0132224, -0.0693042, 0.997428)
|
||||
bones/8/rotation = Quaternion(-0.499466, 0.604869, -0.464923, -0.410503)
|
||||
bones/8/scale = Vector3(1, 1, 1)
|
||||
bones/9/rotation = Quaternion(0.477713, 0.052378, 0.0945921, 0.871837)
|
||||
bones/9/rotation = Quaternion(0.560569, -0.0574147, -0.0996368, 0.820084)
|
||||
bones/9/scale = Vector3(1, 1, 1)
|
||||
bones/10/rotation = Quaternion(0.0446996, 0.029114, -0.359539, 0.931604)
|
||||
bones/11/rotation = Quaternion(0.106754, -0.0646036, -0.10112, 0.987018)
|
||||
bones/12/rotation = Quaternion(0.233202, 0.145699, -0.20617, 0.939086)
|
||||
bones/13/rotation = Quaternion(-0.0431753, 0.000711064, 0.1877, 0.981277)
|
||||
bones/14/rotation = Quaternion(-0.0016657, -0.000807656, 0.00691934, 0.999974)
|
||||
bones/10/rotation = Quaternion(1.8569e-07, 0.0161147, -0.153321, 0.988045)
|
||||
bones/11/rotation = Quaternion(0.0963542, 0.0892781, 0.0727252, 0.988664)
|
||||
bones/12/rotation = Quaternion(0.20961, -0.115532, -0.245184, 0.939468)
|
||||
bones/13/rotation = Quaternion(-0.0328722, 0.117535, 0.240875, 0.962852)
|
||||
bones/14/rotation = Quaternion(0.0098325, 0.00866698, 0.0611068, 0.998045)
|
||||
bones/15/rotation = Quaternion(0.00577591, -0.11751, -0.0487442, 0.991858)
|
||||
bones/16/rotation = Quaternion(0.0395755, 0.00997601, 0.0100787, 0.999116)
|
||||
bones/17/rotation = Quaternion(0.147281, 0.000491134, 0.0101569, 0.989042)
|
||||
bones/18/rotation = Quaternion(1.05725e-05, -1.8822e-07, -8.80717e-05, 1)
|
||||
bones/16/rotation = Quaternion(0.076983, 0.000872834, 0.0413773, 0.996173)
|
||||
bones/17/rotation = Quaternion(0.187029, 0.00118425, 0.0259622, 0.982011)
|
||||
bones/18/rotation = Quaternion(0.129271, 0.00198141, 0.00248517, 0.991604)
|
||||
bones/19/rotation = Quaternion(-4.38752e-06, 0.00100281, 8.70747e-05, 0.999999)
|
||||
bones/19/scale = Vector3(1, 1, 1)
|
||||
bones/20/rotation = Quaternion(0.11099, 0.00848848, 0.0240655, 0.993494)
|
||||
bones/21/rotation = Quaternion(0.263547, 0.00145656, -0.0162155, 0.964509)
|
||||
bones/22/rotation = Quaternion(2.01072e-06, -2.82134e-07, -0.000321912, 1)
|
||||
bones/20/rotation = Quaternion(0.145602, 0.000472066, 0.0766729, 0.986368)
|
||||
bones/21/rotation = Quaternion(0.295346, 0.00265771, 0.0372965, 0.954658)
|
||||
bones/22/rotation = Quaternion(0.146972, 0.000127494, 0.0154105, 0.989021)
|
||||
bones/23/rotation = Quaternion(-4.20033e-06, 0.000929157, 0.000166562, 1)
|
||||
bones/24/rotation = Quaternion(0.186998, -0.00841205, 0.0675611, 0.979998)
|
||||
bones/25/rotation = Quaternion(0.320396, -0.00244664, -0.0342687, 0.946661)
|
||||
bones/24/rotation = Quaternion(0.207537, -0.00143193, 0.101306, 0.972966)
|
||||
bones/25/rotation = Quaternion(0.321751, -0.00227888, 0.0346621, 0.946187)
|
||||
bones/25/scale = Vector3(1, 1, 1)
|
||||
bones/26/rotation = Quaternion(2.07526e-06, 2.07746e-08, -0.000112557, 1)
|
||||
bones/26/rotation = Quaternion(0.132543, 0.00115782, -0.00290896, 0.991172)
|
||||
bones/27/rotation = Quaternion(1.16963e-07, 0.000146031, -0.000799608, 1)
|
||||
bones/27/scale = Vector3(1, 1, 1)
|
||||
bones/28/rotation = Quaternion(0.207746, -0.020696, 0.0882186, 0.973977)
|
||||
bones/29/rotation = Quaternion(0.349305, -0.0117833, -0.067892, 0.934472)
|
||||
bones/30/rotation = Quaternion(5.61877e-06, -2.38827e-07, -0.00049686, 1)
|
||||
bones/28/rotation = Quaternion(0.286267, -0.0114882, 0.143446, 0.947282)
|
||||
bones/29/rotation = Quaternion(0.366356, 0.00288045, 0.0361342, 0.929769)
|
||||
bones/30/rotation = Quaternion(0.169731, 0.0059579, -0.00192036, 0.985471)
|
||||
bones/31/rotation = Quaternion(-5.56963e-06, 0.00156976, -4.12096e-05, 0.999999)
|
||||
bones/31/scale = Vector3(1, 1, 1)
|
||||
bones/32/rotation = Quaternion(0.525951, 0.544071, -0.54701, 0.35797)
|
||||
bones/32/rotation = Quaternion(0.543159, 0.554221, -0.424813, 0.46621)
|
||||
bones/32/scale = Vector3(1, 1, 1)
|
||||
bones/33/rotation = Quaternion(0.510818, -0.0627656, 0.138661, 0.846108)
|
||||
bones/34/rotation = Quaternion(-0.0125484, 0.0578293, 0.404985, 0.912406)
|
||||
bones/35/rotation = Quaternion(-0.162766, 0.140065, 0.0151678, 0.976555)
|
||||
bones/36/rotation = Quaternion(0.307937, -0.0089344, 0.161255, 0.937599)
|
||||
bones/37/rotation = Quaternion(-0.00937778, 0.00174634, -0.00701192, 0.99993)
|
||||
bones/33/rotation = Quaternion(0.676318, 0.0859955, 0.0300173, 0.730956)
|
||||
bones/34/rotation = Quaternion(7.64858e-07, -0.0131976, 0.125566, 0.991998)
|
||||
bones/35/rotation = Quaternion(0.0846856, -0.232848, -0.0325239, 0.968273)
|
||||
bones/36/rotation = Quaternion(0.209579, 0.11587, 0.244299, 0.939664)
|
||||
bones/37/rotation = Quaternion(-0.0324759, -0.117633, -0.239861, 0.963107)
|
||||
bones/37/scale = Vector3(1, 1, 1)
|
||||
bones/38/rotation = Quaternion(-0.00153038, 0.000745069, -0.0060738, 0.99998)
|
||||
bones/38/rotation = Quaternion(0.002646, -0.00797333, -0.0674098, 0.99769)
|
||||
bones/39/rotation = Quaternion(0.00515115, 0.122683, 0.0416519, 0.991558)
|
||||
bones/39/scale = Vector3(1, 1, 1)
|
||||
bones/40/rotation = Quaternion(0.0326842, -0.005891, 0.0610618, 0.997581)
|
||||
bones/41/rotation = Quaternion(0.142788, -0.000761521, -0.00690043, 0.989729)
|
||||
bones/42/rotation = Quaternion(2.20277e-06, -7.01971e-08, -6.63367e-05, 1)
|
||||
bones/40/rotation = Quaternion(0.076984, -0.000888905, -0.0415842, 0.996164)
|
||||
bones/41/rotation = Quaternion(0.187036, -0.00111654, -0.0256068, 0.982019)
|
||||
bones/42/rotation = Quaternion(0.0974016, -0.000353537, -0.00808231, 0.995212)
|
||||
bones/43/rotation = Quaternion(-4.301e-06, -0.000377563, -1.30879e-05, 1)
|
||||
bones/44/rotation = Quaternion(0.124651, 0.00607029, -0.0858307, 0.988463)
|
||||
bones/45/rotation = Quaternion(0.189666, -0.00166462, 0.0146905, 0.981737)
|
||||
bones/46/rotation = Quaternion(-4.03633e-06, -2.86042e-07, 2.04936e-05, 1)
|
||||
bones/44/rotation = Quaternion(0.145602, -0.000549914, -0.0771981, 0.986327)
|
||||
bones/45/rotation = Quaternion(0.295354, -0.00240048, -0.036463, 0.954689)
|
||||
bones/46/rotation = Quaternion(0.115547, 9.80968e-05, -0.0139298, 0.993204)
|
||||
bones/47/rotation = Quaternion(2.8699e-08, -0.00102401, 2.80073e-05, 0.999999)
|
||||
bones/48/rotation = Quaternion(0.264953, -0.013301, -0.130867, 0.955247)
|
||||
bones/49/rotation = Quaternion(0.27558, 0.00173527, 0.0235541, 0.960988)
|
||||
bones/50/rotation = Quaternion(-4.04939e-06, -4.14508e-07, -6.19588e-07, 1)
|
||||
bones/52/rotation = Quaternion(0.290944, -0.0134275, -0.162034, 0.942823)
|
||||
bones/53/rotation = Quaternion(0.33612, 0.0116337, 0.049425, 0.94045)
|
||||
bones/54/rotation = Quaternion(8.52048e-06, 4.23118e-07, -6.65489e-05, 1)
|
||||
bones/48/rotation = Quaternion(0.207545, 0.00146526, -0.101148, 0.972981)
|
||||
bones/49/rotation = Quaternion(0.321757, 0.00220729, -0.0348695, 0.946177)
|
||||
bones/50/rotation = Quaternion(0.14565, 0.00178051, -0.0143766, 0.98923)
|
||||
bones/52/rotation = Quaternion(0.286229, 0.012221, -0.141014, 0.947649)
|
||||
bones/53/rotation = Quaternion(0.366355, -0.00264843, -0.0355409, 0.929793)
|
||||
bones/54/rotation = Quaternion(0.155789, -0.000245093, -0.0231177, 0.98752)
|
||||
bones/55/scale = Vector3(1, 1, 1)
|
||||
bones/56/rotation = Quaternion(-0.125185, 0.041323, 0.983712, 0.122192)
|
||||
bones/57/rotation = Quaternion(-0.321478, 0.0760856, -0.0240363, 0.943549)
|
||||
bones/58/rotation = Quaternion(0.605812, 0.0642597, 0.129458, 0.78237)
|
||||
bones/56/rotation = Quaternion(-0.0408944, 0.023228, 0.994313, -0.0955542)
|
||||
bones/57/rotation = Quaternion(-0.138434, 0.0462629, 0.0241615, 0.988996)
|
||||
bones/58/rotation = Quaternion(0.532354, -0.0301416, -0.062088, 0.843703)
|
||||
bones/58/scale = Vector3(1, 1, 1)
|
||||
bones/59/rotation = Quaternion(0.349854, 0.00382453, -0.00189273, 0.936795)
|
||||
bones/59/rotation = Quaternion(0.340057, 5.86679e-08, -2.64737e-07, 0.940405)
|
||||
bones/60/rotation = Quaternion(3.66699e-08, 0.0116081, 4.25779e-10, 0.999933)
|
||||
bones/61/rotation = Quaternion(0.07882, 0.224764, 0.965855, -0.101941)
|
||||
bones/61/rotation = Quaternion(0.114339, 0.173645, 0.970395, -0.122915)
|
||||
bones/61/scale = Vector3(1, 1, 1)
|
||||
bones/62/rotation = Quaternion(-0.324811, 0.11812, -0.0338818, 0.937762)
|
||||
bones/63/rotation = Quaternion(0.500957, -0.0282444, -0.0572155, 0.863117)
|
||||
bones/64/rotation = Quaternion(0.354274, 0.0164946, -0.0237669, 0.934694)
|
||||
bones/62/rotation = Quaternion(-0.24838, -0.0782927, 0.0351752, 0.964852)
|
||||
bones/63/rotation = Quaternion(0.487247, -0.0631822, -0.0782306, 0.867455)
|
||||
bones/64/rotation = Quaternion(0.339131, 1.59574e-07, -4.75502e-07, 0.940739)
|
||||
bones/65/rotation = Quaternion(4.9911e-08, -0.0118692, -5.92394e-10, 0.99993)
|
||||
|
||||
[node name="AnimationTree" type="AnimationTree" parent="."]
|
||||
|
|
@ -304,9 +303,9 @@ anim_player = NodePath("../XBot2/AnimationPlayer")
|
|||
parameters/LocomotionBlendspace/blend_position = Vector2(0, 0)
|
||||
parameters/TimeScale/scale = 2.0
|
||||
"parameters/TimeScale 2/scale" = 2.0
|
||||
parameters/Transition/current_state = "roll"
|
||||
parameters/Transition/current_state = "locomotion"
|
||||
parameters/Transition/transition_request = ""
|
||||
parameters/Transition/current_index = 1
|
||||
parameters/Transition/current_index = 0
|
||||
|
||||
[node name="RootMotionView" type="RootMotionView" parent="."]
|
||||
animation_path = NodePath("../AnimationTree")
|
||||
|
|
|
|||
|
|
@ -1,227 +0,0 @@
|
|||
extends CompositorEffect
|
||||
|
||||
var rd: RenderingDevice
|
||||
|
||||
var linear_sampler: RID
|
||||
|
||||
var nearest_sampler : RID
|
||||
|
||||
var context: StringName = "PostProcess"
|
||||
|
||||
var all_shader_stages : Dictionary
|
||||
|
||||
@export var debug : bool = false:
|
||||
set(value):
|
||||
if(debug == value):
|
||||
return
|
||||
|
||||
debug = value
|
||||
free_shaders.call_deferred()
|
||||
generate_shaders.call_deferred()
|
||||
|
||||
var debug_1 : String = "debug_1"
|
||||
var debug_2 : String = "debug_2"
|
||||
var debug_3 : String = "debug_3"
|
||||
var debug_4 : String = "debug_4"
|
||||
var debug_5 : String = "debug_5"
|
||||
var debug_6 : String = "debug_6"
|
||||
var debug_7 : String = "debug_7"
|
||||
var debug_8 : String = "debug_8"
|
||||
|
||||
var all_debug_images : Array[RID]
|
||||
|
||||
func _init():
|
||||
RenderingServer.call_on_render_thread(_initialize_compute)
|
||||
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_PREDELETE:
|
||||
if !rd:
|
||||
return
|
||||
if linear_sampler.is_valid():
|
||||
rd.free_rid(linear_sampler)
|
||||
if nearest_sampler.is_valid():
|
||||
rd.free_rid(nearest_sampler)
|
||||
for shader_stage in all_shader_stages.keys():
|
||||
if shader_stage.pipeline.is_valid():
|
||||
rd.free_rid(shader_stage.pipeline)
|
||||
if shader_stage.shader.is_valid():
|
||||
rd.free_rid(shader_stage.shader)
|
||||
|
||||
func free_shaders():
|
||||
for shader_stage in all_shader_stages.keys():
|
||||
if shader_stage.pipeline.is_valid():
|
||||
rd.free_rid(shader_stage.pipeline)
|
||||
if shader_stage.shader.is_valid():
|
||||
rd.free_rid(shader_stage.shader)
|
||||
|
||||
func generate_shaders():
|
||||
for shader_stage in all_shader_stages.keys():
|
||||
generate_shader_stage(shader_stage)
|
||||
|
||||
|
||||
func subscirbe_shader_stage(shader_stage : ShaderStageResource):
|
||||
if all_shader_stages.has(shader_stage):
|
||||
return
|
||||
|
||||
all_shader_stages[shader_stage] = 1
|
||||
|
||||
if rd:
|
||||
generate_shader_stage(shader_stage)
|
||||
|
||||
func unsubscribe_shader_stage(shader_stage : ShaderStageResource):
|
||||
if all_shader_stages.has(shader_stage):
|
||||
all_shader_stages.erase(shader_stage)
|
||||
if !rd:
|
||||
return
|
||||
|
||||
if shader_stage.shader.is_valid():
|
||||
rd.free_rid(shader_stage.shader)
|
||||
if shader_stage.pipeline.is_valid():
|
||||
rd.free_rid(shader_stage.pipeline)
|
||||
|
||||
func _initialize_compute():
|
||||
rd = RenderingServer.get_rendering_device()
|
||||
|
||||
if !rd:
|
||||
return
|
||||
|
||||
var sampler_state := RDSamplerState.new()
|
||||
|
||||
sampler_state.min_filter = RenderingDevice.SAMPLER_FILTER_LINEAR
|
||||
sampler_state.mag_filter = RenderingDevice.SAMPLER_FILTER_LINEAR
|
||||
sampler_state.repeat_u = RenderingDevice.SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE
|
||||
sampler_state.repeat_v = RenderingDevice.SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE
|
||||
|
||||
linear_sampler = rd.sampler_create(sampler_state)
|
||||
|
||||
sampler_state.min_filter = RenderingDevice.SAMPLER_FILTER_NEAREST
|
||||
sampler_state.mag_filter = RenderingDevice.SAMPLER_FILTER_NEAREST
|
||||
sampler_state.repeat_u = RenderingDevice.SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE
|
||||
sampler_state.repeat_v = RenderingDevice.SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE
|
||||
|
||||
nearest_sampler = rd.sampler_create(sampler_state)
|
||||
|
||||
generate_shaders()
|
||||
|
||||
|
||||
func generate_shader_stage(shader_stage : ShaderStageResource):
|
||||
var shader_spirv : RDShaderSPIRV
|
||||
if debug:
|
||||
var file = FileAccess.open(shader_stage.shader_file.resource_path, FileAccess.READ)
|
||||
var split_shader : PackedStringArray = file.get_as_text().split("#[compute]", true, 1)
|
||||
var content : String = split_shader[min(1, split_shader.size() - 1)]
|
||||
var all_split_parts : PackedStringArray = content.split("#version 450", true, 1)
|
||||
content = str(all_split_parts[0],
|
||||
"#version 450
|
||||
#define DEBUG
|
||||
layout(rgba16f, set = 0, binding = 10) uniform image2D debug_1_image;
|
||||
layout(rgba16f, set = 0, binding = 11) uniform image2D debug_2_image;
|
||||
layout(rgba16f, set = 0, binding = 12) uniform image2D debug_3_image;
|
||||
layout(rgba16f, set = 0, binding = 13) uniform image2D debug_4_image;
|
||||
layout(rgba16f, set = 0, binding = 14) uniform image2D debug_5_image;
|
||||
layout(rgba16f, set = 0, binding = 15) uniform image2D debug_6_image;
|
||||
layout(rgba16f, set = 0, binding = 16) uniform image2D debug_7_image;
|
||||
layout(rgba16f, set = 0, binding = 17) uniform image2D debug_8_image;",
|
||||
all_split_parts[1])
|
||||
var shader_source : RDShaderSource = RDShaderSource.new()
|
||||
shader_source.set_stage_source(RenderingDevice.SHADER_STAGE_COMPUTE, content)
|
||||
shader_spirv = rd.shader_compile_spirv_from_source(shader_source, false)
|
||||
print(content)
|
||||
else:
|
||||
shader_spirv = shader_stage.shader_file.get_spirv()
|
||||
|
||||
shader_stage.shader = rd.shader_create_from_spirv(shader_spirv)
|
||||
shader_stage.pipeline = rd.compute_pipeline_create(shader_stage.shader)
|
||||
|
||||
func _render_callback(p_effect_callback_type, p_render_data):
|
||||
if !rd:
|
||||
return
|
||||
|
||||
var render_scene_buffers: RenderSceneBuffersRD = p_render_data.get_render_scene_buffers()
|
||||
var render_scene_data: RenderSceneDataRD = p_render_data.get_render_scene_data()
|
||||
if !render_scene_buffers or !render_scene_data:
|
||||
return
|
||||
|
||||
var render_size: Vector2i = render_scene_buffers.get_internal_size()
|
||||
|
||||
if render_size.x == 0 or render_size.y == 0:
|
||||
return
|
||||
|
||||
if debug:
|
||||
ensure_texture(debug_1, render_scene_buffers)
|
||||
ensure_texture(debug_2, render_scene_buffers)
|
||||
ensure_texture(debug_3, render_scene_buffers)
|
||||
ensure_texture(debug_4, render_scene_buffers)
|
||||
ensure_texture(debug_5, render_scene_buffers)
|
||||
ensure_texture(debug_6, render_scene_buffers)
|
||||
ensure_texture(debug_7, render_scene_buffers)
|
||||
ensure_texture(debug_8, render_scene_buffers)
|
||||
|
||||
var view_count = render_scene_buffers.get_view_count()
|
||||
|
||||
for view in range(view_count):
|
||||
all_debug_images.append(render_scene_buffers.get_texture_slice(context, debug_1, view, 0, 1, 1))
|
||||
all_debug_images.append(render_scene_buffers.get_texture_slice(context, debug_2, view, 0, 1, 1))
|
||||
all_debug_images.append(render_scene_buffers.get_texture_slice(context, debug_3, view, 0, 1, 1))
|
||||
all_debug_images.append(render_scene_buffers.get_texture_slice(context, debug_4, view, 0, 1, 1))
|
||||
all_debug_images.append(render_scene_buffers.get_texture_slice(context, debug_5, view, 0, 1, 1))
|
||||
all_debug_images.append(render_scene_buffers.get_texture_slice(context, debug_6, view, 0, 1, 1))
|
||||
all_debug_images.append(render_scene_buffers.get_texture_slice(context, debug_7, view, 0, 1, 1))
|
||||
all_debug_images.append(render_scene_buffers.get_texture_slice(context, debug_8, view, 0, 1, 1))
|
||||
|
||||
_render_callback_2(render_size, render_scene_buffers, render_scene_data)
|
||||
|
||||
all_debug_images.clear()
|
||||
|
||||
func _render_callback_2(render_size : Vector2i, render_scene_buffers : RenderSceneBuffersRD, render_scene_data : RenderSceneDataRD):
|
||||
pass
|
||||
|
||||
func ensure_texture(texture_name : StringName, render_scene_buffers : RenderSceneBuffersRD, texture_format : RenderingDevice.DataFormat = RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, render_size_multiplier : Vector2 = Vector2(1, 1)):
|
||||
var render_size : Vector2i = Vector2(render_scene_buffers.get_internal_size()) * render_size_multiplier
|
||||
|
||||
if render_scene_buffers.has_texture(context, texture_name):
|
||||
var tf: RDTextureFormat = render_scene_buffers.get_texture_format(context, texture_name)
|
||||
if tf.width != render_size.x or tf.height != render_size.y:
|
||||
render_scene_buffers.clear_context(context)
|
||||
|
||||
if !render_scene_buffers.has_texture(context, texture_name):
|
||||
var usage_bits: int = RenderingDevice.TEXTURE_USAGE_SAMPLING_BIT | RenderingDevice.TEXTURE_USAGE_STORAGE_BIT
|
||||
render_scene_buffers.create_texture(context, texture_name, texture_format, usage_bits, RenderingDevice.TEXTURE_SAMPLES_1, render_size, 1, 1, true)
|
||||
|
||||
func get_image_uniform(image: RID, binding: int) -> RDUniform:
|
||||
var uniform: RDUniform = RDUniform.new()
|
||||
uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_IMAGE
|
||||
uniform.binding = binding
|
||||
uniform.add_id(image)
|
||||
return uniform
|
||||
|
||||
func get_sampler_uniform(image: RID, binding: int, linear : bool = true) -> RDUniform:
|
||||
var uniform: RDUniform = RDUniform.new()
|
||||
uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_SAMPLER_WITH_TEXTURE
|
||||
uniform.binding = binding
|
||||
uniform.add_id(linear_sampler if linear else nearest_sampler)
|
||||
uniform.add_id(image)
|
||||
return uniform
|
||||
|
||||
func dispatch_stage(stage : ShaderStageResource, uniforms : Array[RDUniform], push_constants : PackedByteArray, dispatch_size : Vector3i, label : String = "DefaultLabel", view : int = 0, color : Color = Color(1, 1, 1, 1)):
|
||||
rd.draw_command_begin_label(label + " " + str(view), color)
|
||||
|
||||
if debug:
|
||||
for i in 8:
|
||||
var debug_image_index = i + view * 8;
|
||||
uniforms.append(get_image_uniform(all_debug_images[debug_image_index], 10 + i))
|
||||
|
||||
var tex_uniform_set = UniformSetCacheRD.get_cache(stage.shader, 0, uniforms)
|
||||
|
||||
var compute_list = rd.compute_list_begin()
|
||||
rd.compute_list_bind_compute_pipeline(compute_list, stage.pipeline)
|
||||
rd.compute_list_bind_uniform_set(compute_list, tex_uniform_set, 0)
|
||||
|
||||
if !push_constants.is_empty():
|
||||
rd.compute_list_set_push_constant(compute_list, push_constants, push_constants.size())
|
||||
|
||||
rd.compute_list_dispatch(compute_list, dispatch_size.x, dispatch_size.y, dispatch_size.z)
|
||||
|
||||
rd.compute_list_end()
|
||||
|
||||
rd.draw_command_end_label()
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
extends Compositor
|
||||
class_name MotionBlurCompositor
|
||||
|
||||
@export_group("Motion Blur")
|
||||
# diminishing returns over 16
|
||||
@export_range(4, 64) var samples: int = 16 :
|
||||
set(value):
|
||||
for effect in compositor_effects:
|
||||
effect.set("samples", value)
|
||||
samples = value
|
||||
# you really don't want this over 0.5, but you can if you want to try
|
||||
@export_range(0, 0.5, 0.001, "or_greater") var intensity: float = 1 :
|
||||
set(value):
|
||||
for effect in compositor_effects:
|
||||
effect.set("intensity", value)
|
||||
intensity = value
|
||||
@export_range(0, 1) var center_fade: float = 0.0 :
|
||||
set(value):
|
||||
for effect in compositor_effects:
|
||||
effect.set("center_fade", value)
|
||||
center_fade = value
|
||||
|
||||
## wether this motion blur stays the same intensity below
|
||||
## target_constant_framerate
|
||||
@export var framerate_independent : bool = true :
|
||||
set(value):
|
||||
for effect in compositor_effects:
|
||||
effect.set("framerate_independent", value)
|
||||
framerate_independent = value
|
||||
|
||||
## Description: Removes clamping on motion blur scale to allow framerate independent motion
|
||||
## blur to scale longer than realistically possible when render framerate is higher
|
||||
## than target framerate.[br][br]
|
||||
## [color=yellow]Warning:[/color] Turning this on would allow over-blurring of pixels, which
|
||||
## produces inaccurate results, and would likely cause nausea in players over
|
||||
## long exposure durations, use with caution and out of artistic intent
|
||||
@export var uncapped_independence : bool = false :
|
||||
set(value):
|
||||
for effect in compositor_effects:
|
||||
effect.set("uncapped_independence", value)
|
||||
uncapped_independence = value
|
||||
|
||||
## if framerate_independent is enabled, the blur would simulate
|
||||
## sutter speeds at that framerate, and up.
|
||||
@export var target_constant_framerate : float = 30 :
|
||||
set(value):
|
||||
for effect in compositor_effects:
|
||||
effect.set("target_constant_framerate", value)
|
||||
target_constant_framerate = value
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/BaseClasses/enhanced_compositor_effect.gd"
|
||||
|
||||
# diminishing returns over 16
|
||||
var samples: int = 16
|
||||
# you really don't want this over 0.5, but you can if you want to try
|
||||
var intensity: float = 1
|
||||
var center_fade: float = 0.0
|
||||
|
||||
## wether this motion blur stays the same intensity below
|
||||
## target_constant_framerate
|
||||
var framerate_independent : bool = true
|
||||
|
||||
## Description: Removes clamping on motion blur scale to allow framerate independent motion
|
||||
## blur to scale longer than realistically possible when render framerate is higher
|
||||
## than target framerate.[br][br]
|
||||
## [color=yellow]Warning:[/color] Turning this on would allow over-blurring of pixels, which
|
||||
## produces inaccurate results, and would likely cause nausea in players over
|
||||
## long exposure durations, use with caution and out of artistic intent
|
||||
var uncapped_independence : bool = false
|
||||
|
||||
## if framerate_independent is enabled, the blur would simulate
|
||||
## sutter speeds at that framerate, and up.
|
||||
var target_constant_framerate : float = 30
|
||||
|
||||
func _init():
|
||||
needs_motion_vectors = true
|
||||
set_deferred("context", "MotionBlur")
|
||||
super()
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
extends Resource
|
||||
class_name ShaderStageResource
|
||||
|
||||
@export var shader_file : RDShaderFile
|
||||
|
||||
var shader : RID
|
||||
var pipeline : RID
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define DBL_MAX 1.7976931348623158e+308
|
||||
#define DBL_MIN 2.2250738585072014e-308
|
||||
|
||||
layout(rgba16f, set = 0, binding = 0) uniform image2D past_color_image;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform image2D output_color_image;
|
||||
layout(set = 0, binding = 2) uniform sampler2D color_sampler;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan_fl_1;
|
||||
float nan_fl_2;
|
||||
float nan_fl_3;
|
||||
float nan_fl_4;
|
||||
int freeze;
|
||||
int draw_debug;
|
||||
int debug_page;
|
||||
int nan3;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// show past image for freeze frame
|
||||
if(params.freeze > 0)
|
||||
{
|
||||
imageStore(output_color_image, uvi, imageLoad(past_color_image, uvi));
|
||||
return;
|
||||
}
|
||||
// must be on pixel center for whole values (tested)
|
||||
vec2 uvn = vec2(uvi + vec2(0.5)) / render_size;
|
||||
|
||||
vec4 source = textureLod(color_sampler, uvn, 0.0);
|
||||
|
||||
if (params.draw_debug == 0)
|
||||
{
|
||||
imageStore(output_color_image, uvi, source);
|
||||
imageStore(past_color_image, uvi, source);
|
||||
return;
|
||||
}
|
||||
|
||||
vec4 tl_col;
|
||||
|
||||
vec4 tr_col;
|
||||
|
||||
vec4 bl_col;
|
||||
|
||||
vec4 br_col;
|
||||
|
||||
#ifdef DEBUG
|
||||
if(params.debug_page == 0)
|
||||
{
|
||||
tl_col = imageLoad(debug_1_image, uvi);
|
||||
tr_col = imageLoad(debug_2_image, uvi);
|
||||
bl_col = imageLoad(debug_3_image, uvi);
|
||||
br_col = imageLoad(debug_4_image, uvi);
|
||||
}
|
||||
if(params.debug_page == 1)
|
||||
{
|
||||
tl_col = imageLoad(debug_5_image, uvi);
|
||||
tr_col = imageLoad(debug_6_image, uvi);
|
||||
bl_col = imageLoad(debug_7_image, uvi);
|
||||
br_col = imageLoad(debug_8_image, uvi);
|
||||
}
|
||||
#endif
|
||||
|
||||
imageStore(output_color_image, uvi / 2, tl_col);
|
||||
imageStore(output_color_image, uvi / 2 + ivec2(vec2(0.5, 0.5) * render_size), br_col);
|
||||
imageStore(output_color_image, uvi / 2 + ivec2(vec2(0.0, 0.5) * render_size), bl_col);
|
||||
imageStore(output_color_image, uvi / 2 + ivec2(vec2(0.5, 0.0) * render_size), tr_col);
|
||||
imageStore(past_color_image, uvi / 2, tl_col);
|
||||
imageStore(past_color_image, uvi / 2 + ivec2(vec2(0.5, 0.5) * render_size), br_col);
|
||||
imageStore(past_color_image, uvi / 2 + ivec2(vec2(0.0, 0.5) * render_size), bl_col);
|
||||
imageStore(past_color_image, uvi / 2 + ivec2(vec2(0.5, 0.0) * render_size), tr_col);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://dyxn6g5gvoge7"
|
||||
path="res://.godot/imported/debug_overlay.glsl-5ad15477a64c7f484bc494103ad163b6.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/Debug/ShaderFiles/debug_overlay.glsl"
|
||||
dest_files=["res://.godot/imported/debug_overlay.glsl-5ad15477a64c7f484bc494103ad163b6.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://o2bivm33b0v4"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_rqnmr"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://dyxn6g5gvoge7" path="res://addons/SphynxMotionBlurToolkit/Debug/ShaderFiles/debug_overlay.glsl" id="2_qgd1y"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_rqnmr")
|
||||
shader_file = ExtResource("2_qgd1y")
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/BaseClasses/enhanced_compositor_effect.gd"
|
||||
class_name DebugCompositorEffect
|
||||
|
||||
@export var overlay_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Debug/debug_overlay_shader_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(overlay_stage)
|
||||
overlay_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
## wether to display debug views for velocity and depth
|
||||
## buffers
|
||||
@export var draw_debug : bool = false
|
||||
|
||||
## currently 0 - 1, flip between velocity buffers
|
||||
## and depth buffers debug views
|
||||
@export var debug_page : int = 0
|
||||
|
||||
var past_color : StringName = "past_color"
|
||||
|
||||
var freeze : bool = false
|
||||
|
||||
func _init():
|
||||
set_deferred("context", "MotionBlur")
|
||||
set_deferred("debug", true)
|
||||
super()
|
||||
|
||||
func _render_callback_2(render_size : Vector2i, render_scene_buffers : RenderSceneBuffersRD, render_scene_data : RenderSceneDataRD):
|
||||
ensure_texture(past_color, render_scene_buffers)
|
||||
ensure_texture(debug_1, render_scene_buffers)
|
||||
ensure_texture(debug_2, render_scene_buffers)
|
||||
ensure_texture(debug_3, render_scene_buffers)
|
||||
ensure_texture(debug_4, render_scene_buffers)
|
||||
ensure_texture(debug_5, render_scene_buffers)
|
||||
ensure_texture(debug_6, render_scene_buffers)
|
||||
ensure_texture(debug_7, render_scene_buffers)
|
||||
ensure_texture(debug_8, render_scene_buffers)
|
||||
|
||||
rd.draw_command_begin_label("Debug", Color(1.0, 1.0, 1.0, 1.0))
|
||||
|
||||
if Input.is_action_just_pressed("freeze"):
|
||||
freeze = !freeze
|
||||
|
||||
if Input.is_action_just_pressed("Z"):
|
||||
draw_debug = !draw_debug
|
||||
|
||||
if Input.is_action_just_pressed("C"):
|
||||
debug_page = 1 if debug_page == 0 else 0
|
||||
|
||||
var push_constant: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
]
|
||||
var int_push_constant : PackedInt32Array = [
|
||||
freeze,
|
||||
draw_debug,
|
||||
debug_page,
|
||||
0
|
||||
]
|
||||
var byte_array = push_constant.to_byte_array()
|
||||
byte_array.append_array(int_push_constant.to_byte_array())
|
||||
|
||||
var view_count = render_scene_buffers.get_view_count()
|
||||
for view in range(view_count):
|
||||
var color_image := render_scene_buffers.get_color_layer(view)
|
||||
var past_color_image := render_scene_buffers.get_texture_slice(context, past_color, view, 0, 1, 1)
|
||||
var debug_1_image := render_scene_buffers.get_texture_slice(context, debug_1, view, 0, 1, 1)
|
||||
var debug_2_image := render_scene_buffers.get_texture_slice(context, debug_2, view, 0, 1, 1)
|
||||
var debug_3_image := render_scene_buffers.get_texture_slice(context, debug_3, view, 0, 1, 1)
|
||||
var debug_4_image := render_scene_buffers.get_texture_slice(context, debug_4, view, 0, 1, 1)
|
||||
var debug_5_image := render_scene_buffers.get_texture_slice(context, debug_5, view, 0, 1, 1)
|
||||
var debug_6_image := render_scene_buffers.get_texture_slice(context, debug_6, view, 0, 1, 1)
|
||||
var debug_7_image := render_scene_buffers.get_texture_slice(context, debug_7, view, 0, 1, 1)
|
||||
var debug_8_image := render_scene_buffers.get_texture_slice(context, debug_8, view, 0, 1, 1)
|
||||
|
||||
var x_groups := floori((render_size.x - 1) / 16 + 1)
|
||||
var y_groups := floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(overlay_stage,
|
||||
[
|
||||
get_image_uniform(past_color_image, 0),
|
||||
get_image_uniform(color_image, 1),
|
||||
get_sampler_uniform(color_image, 2),
|
||||
get_sampler_uniform(debug_1_image, 3),
|
||||
get_sampler_uniform(debug_2_image, 4),
|
||||
get_sampler_uniform(debug_3_image, 5),
|
||||
get_sampler_uniform(debug_4_image, 6),
|
||||
get_sampler_uniform(debug_5_image, 7),
|
||||
get_sampler_uniform(debug_6_image, 8),
|
||||
get_sampler_uniform(debug_7_image, 9),
|
||||
get_sampler_uniform(debug_8_image, 10),
|
||||
],
|
||||
byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Debug Overlay",
|
||||
view)
|
||||
|
||||
rd.draw_command_end_label()
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D depth_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D neighbor_max;
|
||||
layout(set = 0, binding = 4) uniform sampler2D tile_variance;
|
||||
layout(rgba16f, set = 0, binding = 5) uniform writeonly image2D output_color;
|
||||
layout(rgba16f, set = 0, binding = 6) uniform image2D debug_1_image;
|
||||
layout(rgba16f, set = 0, binding = 7) uniform image2D debug_2_image;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float minimum_user_threshold;
|
||||
float importance_bias;
|
||||
float maximum_jitter_value;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int sample_count;
|
||||
int frame;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - abs(T) / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, abs(T));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b)
|
||||
{
|
||||
return clamp(1. - (a - b) / min(a, b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv, int FrameId){
|
||||
uv += float(FrameId) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
vec2 sample_random_offset(vec2 uv, float j)
|
||||
{
|
||||
return vec2(0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 tile_render_size = ivec2(textureSize(neighbor_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
float j = interleaved_gradient_noise(uvi, params.frame) * 2. - 1.;
|
||||
|
||||
vec2 vn = textureLod(neighbor_max, x, 0.0).xy * render_size / 2;
|
||||
|
||||
float vn_length = max(0.5, length(vn));
|
||||
|
||||
vec4 base_color = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
if(vn_length <= 0.5)
|
||||
{
|
||||
imageStore(output_color, uvi, base_color);
|
||||
imageStore(debug_1_image, uvi, base_color);
|
||||
imageStore(debug_2_image, uvi, vec4(vn / render_size * 2, 0, 1));
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 wn = normalize(vn);
|
||||
|
||||
vec2 vx = textureLod(velocity_sampler, x, 0.0).xy * render_size / 2;
|
||||
|
||||
float vx_length = max(0.5, length(vx));
|
||||
|
||||
vec2 wp = vec2(-wn.y, wn.x);
|
||||
|
||||
if(dot(wp, vx) < 0)
|
||||
{
|
||||
wp = -wp;
|
||||
}
|
||||
|
||||
vec2 wc = normalize(mix(wp, normalize(vx), (vx_length - 0.5) / params.minimum_user_threshold));
|
||||
|
||||
float zx = -0.05 / textureLod(depth_sampler, x, 0.0).x;
|
||||
|
||||
float weight = params.sample_count / (params.importance_bias * vx_length);
|
||||
|
||||
vec4 sum = base_color * weight;
|
||||
|
||||
for(int i = 0; i < params.sample_count; i++)
|
||||
{
|
||||
float t = mix(-1.0, 1.0, (i + j * params.maximum_jitter_value + 1.0) / (params.sample_count + 1.0));
|
||||
|
||||
vec2 d = ((i % 2) > 0) ? vx : vn;
|
||||
|
||||
float T = t * vn_length;
|
||||
|
||||
vec2 y = x + t * d / render_size;
|
||||
|
||||
vec2 vy = textureLod(velocity_sampler, y, 0.0).xy * render_size / 2;
|
||||
|
||||
float vy_length = max(0.5, length(vy));
|
||||
|
||||
float zy = -0.05 / textureLod(depth_sampler, y, 0.0).x;
|
||||
|
||||
float f = z_compare(zx, zy);
|
||||
float b = z_compare(zy, zx);
|
||||
|
||||
float wa = dot(wc, d);
|
||||
float wb = dot(normalize(vy), d);
|
||||
|
||||
float ay = f * cone(T, 1. / vy_length) * max(FLT_MIN, abs(wb))
|
||||
+ b * cone(T, 1. / vx_length) * max(FLT_MIN, abs(wa))
|
||||
+ cylinder(T, min(vx_length, vy_length)) * 2 * max(FLT_MIN, max(abs(wa), abs(wb)));
|
||||
|
||||
weight += abs(ay);
|
||||
sum += ay * textureLod(color_sampler, y, 0.0);
|
||||
}
|
||||
|
||||
sum /= weight;
|
||||
|
||||
imageStore(output_color, uvi, sum);
|
||||
imageStore(debug_1_image, uvi, sum);
|
||||
imageStore(debug_2_image, uvi, vec4(vn / render_size * 2, 0, 1));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://cbdyfuhewqag8"
|
||||
path="res://.godot/imported/guertin_blur.glsl-bc647b2d965e982b702f0e036903e801.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_blur.glsl"
|
||||
dest_files=["res://.godot/imported/guertin_blur.glsl-bc647b2d965e982b702f0e036903e801.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,200 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D neighbor_max;
|
||||
layout(set = 0, binding = 3) uniform sampler2D tile_variance;
|
||||
layout(rgba16f, set = 0, binding = 4) uniform writeonly image2D output_color;
|
||||
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float minimum_user_threshold;
|
||||
float importance_bias;
|
||||
float maximum_jitter_value;
|
||||
float motion_blur_intensity;
|
||||
int tile_size;
|
||||
int sample_count;
|
||||
int frame;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - T / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, T);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float sze)
|
||||
{
|
||||
return clamp(1. - sze * (a - b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv){
|
||||
uv += float(params.frame) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://github.com/bradparks/KinoMotion__unity_motion_blur/tree/master
|
||||
// ----------------------------------------------------------
|
||||
vec2 safenorm(vec2 v)
|
||||
{
|
||||
float l = max(length(v), 1e-6);
|
||||
return v / l * int(l >= 0.5);
|
||||
}
|
||||
|
||||
vec2 jitter_tile(vec2 uvi)
|
||||
{
|
||||
float rx, ry;
|
||||
float angle = interleaved_gradient_noise(uvi + vec2(2, 0)) * M_PI * 2;
|
||||
rx = cos(angle);
|
||||
ry = sin(angle);
|
||||
return vec2(rx, ry) / textureSize(neighbor_max, 0) / 4;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 tile_render_size = ivec2(textureSize(neighbor_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
vec4 vnzw = textureLod(neighbor_max, x + vec2(params.tile_size / 2) / vec2(render_size) + jitter_tile(uvi), 0.0) * vec4(render_size / 2., 1, 1) * params.motion_blur_intensity;
|
||||
|
||||
vec2 vn = vnzw.xy;
|
||||
|
||||
float vn_length = length(vn);
|
||||
|
||||
vec4 base_color = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
vec4 vxzw = textureLod(velocity_sampler, x, 0.0) * vec4(render_size / 2., 1, 1) * params.motion_blur_intensity;
|
||||
|
||||
if(vn_length < 0.5)
|
||||
{
|
||||
imageStore(output_color, uvi, base_color);
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, base_color);
|
||||
imageStore(debug_2_image, uvi, vec4(vn / render_size * 2, 0, 1));
|
||||
imageStore(debug_3_image, uvi, vec4(vxzw.xy / render_size * 2, 0, 1));
|
||||
imageStore(debug_4_image, uvi, vec4(0));
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 wn = safenorm(vn);
|
||||
|
||||
vec2 vx = vxzw.xy;
|
||||
|
||||
float vx_length = max(0.5, length(vx));
|
||||
|
||||
vec2 wx = safenorm(vx);
|
||||
|
||||
float j = interleaved_gradient_noise(uvi) * 2. - 1.;
|
||||
|
||||
float zx = vxzw.w;
|
||||
|
||||
float weight = 1e-6;
|
||||
|
||||
vec4 sum = base_color * weight;
|
||||
|
||||
float nai_weight = 1e-6;
|
||||
|
||||
vec4 nai_sum = base_color * nai_weight;
|
||||
|
||||
for(int i = 0; i < params.sample_count; i++)
|
||||
{
|
||||
float t = mix(-1.0, 1.0, (i + j * params.maximum_jitter_value + 1.0) / (params.sample_count + 1.0));
|
||||
|
||||
bool use_vn = ((i % 2) == 0);
|
||||
|
||||
vec2 d = use_vn ? vn : vx;
|
||||
|
||||
float dz = use_vn ? vnzw.z : vxzw.z;
|
||||
|
||||
vec2 wd = use_vn ? wn : wx;
|
||||
|
||||
float T = abs(t * vn_length);
|
||||
|
||||
vec2 y = x + t * d / render_size;
|
||||
|
||||
float wa = abs(dot(wx, wd));
|
||||
|
||||
vec4 vyzw = textureLod(velocity_sampler, y, 0.0) * vec4(render_size / 2, 1, 1) * params.motion_blur_intensity;
|
||||
|
||||
vec2 vy = vyzw.xy - dz * t;
|
||||
|
||||
float vy_length = max(0.5, length(vy));
|
||||
|
||||
float zy = vyzw.w;
|
||||
|
||||
float f = z_compare(-zy, -zx, 20000);
|
||||
float b = z_compare(-zx, -zy, 20000);
|
||||
|
||||
float wb = abs(dot(vy / vy_length, wd));
|
||||
|
||||
if(use_vn)
|
||||
{
|
||||
float ay = f * step(T, vy_length * wb);
|
||||
|
||||
weight += ay;
|
||||
|
||||
sum += textureLod(color_sampler, y, 0.0) * ay;
|
||||
}
|
||||
|
||||
float nai_ay = b * step(T, vx_length * wa) * 2;
|
||||
|
||||
nai_weight += nai_ay;
|
||||
|
||||
nai_sum += textureLod(color_sampler, y, 0.0) * nai_ay;
|
||||
}
|
||||
|
||||
sum /= weight;
|
||||
|
||||
weight /= params.sample_count / 2;
|
||||
|
||||
nai_sum /= nai_weight;
|
||||
|
||||
sum = mix(nai_sum, sum, weight);
|
||||
|
||||
imageStore(output_color, uvi, sum);
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, base_color);
|
||||
imageStore(debug_2_image, uvi, vec4(vn / render_size * 2, 0, 1));
|
||||
imageStore(debug_3_image, uvi, vec4(vx / render_size * 2, 0, 1));
|
||||
imageStore(debug_4_image, uvi, vxzw);
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://br71y0l0rxt8h"
|
||||
path="res://.godot/imported/guertin_experimental_blur.glsl-196a1037ea9a4eb1095033202fe161a7.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_experimental_blur.glsl"
|
||||
dest_files=["res://.godot/imported/guertin_experimental_blur.glsl-196a1037ea9a4eb1095033202fe161a7.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D neighbor_max;
|
||||
layout(set = 0, binding = 3) uniform sampler2D tile_variance;
|
||||
layout(rgba16f, set = 0, binding = 4) uniform writeonly image2D output_color;
|
||||
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float minimum_user_threshold;
|
||||
float importance_bias;
|
||||
float maximum_jitter_value;
|
||||
float motion_blur_intensity;
|
||||
int tile_size;
|
||||
int sample_count;
|
||||
int frame;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - T / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, T);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float sze)
|
||||
{
|
||||
return clamp(1. - sze * (a - b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv){
|
||||
uv += float(params.frame) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://github.com/bradparks/KinoMotion__unity_motion_blur/tree/master
|
||||
// ----------------------------------------------------------
|
||||
vec2 safenorm(vec2 v)
|
||||
{
|
||||
float l = max(length(v), 1e-6);
|
||||
return v / l * int(l >= 0.5);
|
||||
}
|
||||
|
||||
vec2 jitter_tile(vec2 uvi)
|
||||
{
|
||||
float rx, ry;
|
||||
float angle = interleaved_gradient_noise(uvi + vec2(2, 0)) * M_PI * 2;
|
||||
rx = cos(angle);
|
||||
ry = sin(angle);
|
||||
return vec2(rx, ry) / textureSize(neighbor_max, 0) / 4;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 tile_render_size = ivec2(textureSize(neighbor_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
float j = interleaved_gradient_noise(uvi) * 2. - 1.;
|
||||
|
||||
vec4 vnzw = textureLod(neighbor_max, x + vec2(params.tile_size / 2) / vec2(render_size) + jitter_tile(uvi), 0.0) * vec4(render_size / 2., 1, 1) * params.motion_blur_intensity;
|
||||
|
||||
vec2 vn = vnzw.xy;
|
||||
|
||||
float vn_length = length(vn);
|
||||
|
||||
vec4 base_color = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
if(vn_length < 0.5)
|
||||
{
|
||||
imageStore(output_color, uvi, base_color);
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, base_color);
|
||||
imageStore(debug_2_image, uvi, vec4(vn / render_size * 2, 0, 1));
|
||||
imageStore(debug_3_image, uvi, vec4(0));
|
||||
imageStore(debug_4_image, uvi, vec4(0));
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 wn = safenorm(vn);
|
||||
|
||||
vec4 vxzw = textureLod(velocity_sampler, x, 0.0) * vec4(render_size / 2., 1, 1) * params.motion_blur_intensity;
|
||||
|
||||
vec2 vx = vxzw.xy;
|
||||
|
||||
float vx_length = max(0.5, length(vx));
|
||||
|
||||
vec2 wx = safenorm(vx);
|
||||
|
||||
vec2 wp = vec2(-wn.y, wn.x);
|
||||
|
||||
if(dot(wp, vx) < 0)
|
||||
{
|
||||
wp = -wp;
|
||||
}
|
||||
|
||||
vec2 wc = safenorm(mix(wp, wx, clamp((vx_length - 0.5) / params.minimum_user_threshold, 0, 1)));
|
||||
|
||||
float zx = vxzw.w;
|
||||
|
||||
float total_weight = params.sample_count / (params.importance_bias * vx_length);
|
||||
|
||||
vec4 sum = base_color * total_weight;
|
||||
|
||||
for(int i = 0; i < params.sample_count; i++)
|
||||
{
|
||||
float t = mix(-1.0, 1.0, (i + j * params.maximum_jitter_value + 1.0) / (params.sample_count + 1.0));
|
||||
|
||||
vec2 d = ((i % 2) > 0) ? vx : vn;
|
||||
|
||||
float dz = ((i % 2) > 0) ? vxzw.z : vnzw.z;
|
||||
|
||||
vec2 wd = safenorm(d);
|
||||
|
||||
float T = abs(t * vn_length);
|
||||
|
||||
vec2 y = x + t * d / render_size;
|
||||
|
||||
float wa = dot(wc, wd);
|
||||
|
||||
vec4 vyzw = textureLod(velocity_sampler, y, 0.0) * vec4(render_size / 2, 1, 1) * params.motion_blur_intensity;
|
||||
|
||||
vec2 vy = vyzw.xy - dz * t;
|
||||
|
||||
float vy_length = max(0.5, length(vy));
|
||||
|
||||
float zy = vyzw.w;
|
||||
|
||||
float f = z_compare(-zy, -zx, 20000);
|
||||
float b = z_compare(-zx, -zy, 20000);
|
||||
|
||||
float wb = abs(dot(vy / vy_length, wd));
|
||||
|
||||
float weight = 0.0;
|
||||
weight += f * cone(T, vy_length) * wb;
|
||||
weight += b * cone(T, vx_length) * wa;
|
||||
weight += cylinder(T, min(vy_length, vx_length)) * 2. * max(wa, wb);
|
||||
|
||||
total_weight += weight;
|
||||
|
||||
sum += weight * textureLod(color_sampler, y, 0.0);
|
||||
}
|
||||
|
||||
sum /= total_weight;
|
||||
|
||||
imageStore(output_color, uvi, sum);
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, sum);
|
||||
imageStore(debug_2_image, uvi, vec4(vn / render_size * 2, 0, 1));
|
||||
imageStore(debug_3_image, uvi, vnzw);
|
||||
imageStore(debug_4_image, uvi, vxzw);
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://m6rlgfu6i0b3"
|
||||
path="res://.godot/imported/guertin_kino_blur.glsl-71e9932045a7522115793d60f179d67e.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_kino_blur.glsl"
|
||||
dest_files=["res://.godot/imported/guertin_kino_blur.glsl-71e9932045a7522115793d60f179d67e.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D neighbor_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 max_neighbor_velocity = vec2(0);
|
||||
|
||||
float max_neighbor_velocity_length = 0;
|
||||
|
||||
for(int i = -1; i < 2; i++)
|
||||
{
|
||||
for(int j = -1; j < 2; j++)
|
||||
{
|
||||
vec2 current_offset = vec2(1) / vec2(render_size) * vec2(i, j);
|
||||
vec2 current_uv = uvn + current_offset;
|
||||
if(current_uv.x < 0 || current_uv.x > 1 || current_uv.y < 0 || current_uv.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_diagonal = (abs(i) + abs(j) == 2);
|
||||
|
||||
vec2 current_neighbor_velocity = textureLod(tile_max, current_uv, 0.0).xy;
|
||||
|
||||
bool facing_center = dot(current_neighbor_velocity, current_offset) > 0;
|
||||
|
||||
if(is_diagonal && !facing_center)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float current_neighbor_velocity_length = dot(current_neighbor_velocity, current_neighbor_velocity);
|
||||
if(current_neighbor_velocity_length > max_neighbor_velocity_length)
|
||||
{
|
||||
max_neighbor_velocity_length = current_neighbor_velocity_length;
|
||||
max_neighbor_velocity = current_neighbor_velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imageStore(neighbor_max, uvi, vec4(max_neighbor_velocity, 0, 1));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://bn88jkvr17x4j"
|
||||
path="res://.godot/imported/guertin_neighbor_max.glsl-91e836516679e0c51b67df5b480ef0af.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_neighbor_max.glsl"
|
||||
dest_files=["res://.godot/imported/guertin_neighbor_max.glsl-91e836516679e0c51b67df5b480ef0af.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D blur_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform image2D color_image;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(blur_sampler, 0));
|
||||
ivec2 output_size = imageSize(color_image);
|
||||
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uv.x >= output_size.x) || (uv.y >= output_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
imageStore(color_image, uv, textureLod(blur_sampler, (vec2(uv) + 0.5) / output_size, 0.0));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://i6rnwhmss334"
|
||||
path="res://.godot/imported/guertin_overlay.glsl-506c18362b63cb0a2477b4a4fbfea046.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_overlay.glsl"
|
||||
dest_files=["res://.godot/imported/guertin_overlay.glsl-506c18362b63cb0a2477b4a4fbfea046.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D depth_sampler;
|
||||
layout(rgba16f, set = 0, binding = 2) uniform writeonly image2D tile_max_x;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(velocity_sampler, 0));
|
||||
ivec2 output_size = imageSize(tile_max_x);
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
ivec2 global_uvi = uvi * ivec2(params.tile_size, 1);
|
||||
if ((uvi.x >= output_size.x) || (uvi.y >= output_size.y) || (global_uvi.x >= render_size.x) || (global_uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(global_uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec4 max_velocity = vec4(0);
|
||||
|
||||
float max_velocity_length = -1;
|
||||
|
||||
for(int i = 0; i < params.tile_size; i++)
|
||||
{
|
||||
vec2 current_uv = uvn + vec2(float(i) / render_size.x, 0);
|
||||
vec3 velocity_sample = textureLod(velocity_sampler, current_uv, 0.0).xyz;
|
||||
float current_velocity_length = dot(velocity_sample.xy, velocity_sample.xy);
|
||||
if(current_velocity_length > max_velocity_length)
|
||||
{
|
||||
max_velocity_length = current_velocity_length;
|
||||
max_velocity = vec4(velocity_sample, textureLod(depth_sampler, current_uv, 0.0).x);
|
||||
}
|
||||
}
|
||||
imageStore(tile_max_x, uvi, max_velocity);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://d0s5upcgm7r6l"
|
||||
path="res://.godot/imported/guertin_tile_max_x.glsl-7ca561425618287b0f2821fd8c232f09.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_tile_max_x.glsl"
|
||||
dest_files=["res://.godot/imported/guertin_tile_max_x.glsl-7ca561425618287b0f2821fd8c232f09.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max_x;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D tile_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max_x, 0));
|
||||
ivec2 output_size = imageSize(tile_max);
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
ivec2 global_uvi = uvi * ivec2(1, params.tile_size);
|
||||
if ((uvi.x >= output_size.x) || (uvi.y >= output_size.y) || (global_uvi.x >= render_size.x) || (global_uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(global_uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec4 max_velocity = vec4(0);
|
||||
|
||||
float max_velocity_length = -1;
|
||||
|
||||
for(int i = 0; i < params.tile_size; i++)
|
||||
{
|
||||
vec2 current_uv = uvn + vec2(0, float(i) / render_size.y);
|
||||
vec4 velocity_sample = textureLod(tile_max_x, current_uv, 0.0);
|
||||
float current_velocity_length = dot(velocity_sample.xy, velocity_sample.xy);
|
||||
if(current_velocity_length > max_velocity_length)
|
||||
{
|
||||
max_velocity_length = current_velocity_length;
|
||||
max_velocity = velocity_sample;
|
||||
}
|
||||
}
|
||||
imageStore(tile_max, uvi, max_velocity);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://ceetvitdbio4l"
|
||||
path="res://.godot/imported/guertin_tile_max_y.glsl-60f045725ff6917c4bd911cf3710a444.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_tile_max_y.glsl"
|
||||
dest_files=["res://.godot/imported/guertin_tile_max_y.glsl-60f045725ff6917c4bd911cf3710a444.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D tile_variance;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
float variance = 0;
|
||||
|
||||
vec2 current_velocity = abs(normalize(textureLod(tile_max, uvn, 0.0).xy));
|
||||
|
||||
float tile_count = 0;
|
||||
|
||||
for(int i = -1; i < 2; i++)
|
||||
{
|
||||
for(int j = -1; j < 2; j++)
|
||||
{
|
||||
vec2 current_offset = vec2(1) / vec2(render_size) * vec2(i, j);
|
||||
vec2 current_uv = uvn + current_offset;
|
||||
if(current_uv.x < 0 || current_uv.x > 1 || current_uv.y < 0 || current_uv.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(i == j && i == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
tile_count += 1;
|
||||
|
||||
vec2 current_neighbor_velocity = abs(normalize(textureLod(tile_max, current_uv, 0.0).xy));
|
||||
|
||||
variance += dot(current_velocity, current_neighbor_velocity);
|
||||
}
|
||||
}
|
||||
|
||||
variance /= tile_count;
|
||||
|
||||
imageStore(tile_variance, uvi, vec4(1 - variance));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://by6mslkv0palh"
|
||||
path="res://.godot/imported/guertin_tile_variance.glsl-2fb44423dc25efae19822b8cfbe32a55.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_tile_variance.glsl"
|
||||
dest_files=["res://.godot/imported/guertin_tile_variance.glsl-2fb44423dc25efae19822b8cfbe32a55.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/BaseClasses/mb_compositor_effect.gd"
|
||||
|
||||
@export_group("Shader Parameters")
|
||||
@export var tile_size : int = 40
|
||||
|
||||
@export var linear_falloff_slope : float = 1
|
||||
|
||||
@export var importance_bias : float = 40
|
||||
|
||||
@export var maximum_jitter_value : float = 0.95
|
||||
|
||||
@export var minimum_user_threshold : float = 1.5
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://dre56ajymywpr"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_loemu"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://m6rlgfu6i0b3" path="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_kino_blur.glsl" id="2_uo41r"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_loemu")
|
||||
shader_file = ExtResource("2_uo41r")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://ca45noqewsyvp"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_kvtxq"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://br71y0l0rxt8h" path="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_experimental_blur.glsl" id="2_ykr12"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_kvtxq")
|
||||
shader_file = ExtResource("2_ykr12")
|
||||
|
|
@ -1,245 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/Guertin/base_guertin_motion_blur.gd"
|
||||
class_name OldGuertinMotionBlur
|
||||
|
||||
@export_group("Shader Stages")
|
||||
@export var blur_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_blur_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(blur_stage)
|
||||
blur_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var overlay_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_overlay_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(overlay_stage)
|
||||
overlay_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var tile_max_x_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_tile_max_x_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_x_stage)
|
||||
tile_max_x_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var tile_max_y_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_tile_max_y_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_y_stage)
|
||||
tile_max_y_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var neighbor_max_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_neighbor_max_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(neighbor_max_stage)
|
||||
neighbor_max_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var tile_variance_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_tile_variance_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_variance_stage)
|
||||
tile_variance_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
var output_color: StringName = "output_color"
|
||||
|
||||
var tile_max_x : StringName = "tile_max_x"
|
||||
|
||||
var tile_max : StringName = "tile_max"
|
||||
|
||||
var neighbor_max : StringName = "neighbor_max"
|
||||
|
||||
var tile_variance : StringName = "tile_variance"
|
||||
|
||||
var custom_velocity : StringName = "custom_velocity"
|
||||
|
||||
var freeze : bool = false
|
||||
|
||||
var temp_intensity : float
|
||||
|
||||
var previous_time : float = 0
|
||||
|
||||
func _render_callback_2(render_size : Vector2i, render_scene_buffers : RenderSceneBuffersRD, render_scene_data : RenderSceneDataRD):
|
||||
var time : float = float(Time.get_ticks_msec()) / 1000
|
||||
|
||||
var delta_time : float = time - previous_time
|
||||
|
||||
previous_time = time
|
||||
|
||||
temp_intensity = intensity
|
||||
|
||||
if framerate_independent:
|
||||
var capped_frame_time : float = 1 / target_constant_framerate
|
||||
|
||||
if !uncapped_independence:
|
||||
capped_frame_time = min(capped_frame_time, delta_time)
|
||||
|
||||
temp_intensity = intensity * capped_frame_time / delta_time
|
||||
|
||||
ensure_texture(tile_max_x, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / tile_size, 1.))
|
||||
ensure_texture(tile_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / tile_size, 1. / tile_size))
|
||||
ensure_texture(neighbor_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / tile_size, 1. / tile_size))
|
||||
ensure_texture(tile_variance, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / tile_size, 1. / tile_size))
|
||||
ensure_texture(custom_velocity, render_scene_buffers)
|
||||
ensure_texture(output_color, render_scene_buffers)
|
||||
|
||||
rd.draw_command_begin_label("Motion Blur", Color(1.0, 1.0, 1.0, 1.0))
|
||||
|
||||
var tile_max_x_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_x_push_constants : PackedInt32Array = [
|
||||
tile_size,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_x_push_constants_byte_array = tile_max_x_push_constants.to_byte_array()
|
||||
tile_max_x_push_constants_byte_array.append_array(int_tile_max_x_push_constants.to_byte_array())
|
||||
|
||||
var tile_max_y_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_y_push_constants : PackedInt32Array = [
|
||||
tile_size,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_y_push_constants_byte_array = tile_max_y_push_constants.to_byte_array()
|
||||
tile_max_y_push_constants_byte_array.append_array(int_tile_max_y_push_constants.to_byte_array())
|
||||
|
||||
var neighbor_max_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_neighbor_max_push_constants : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var neighbor_max_push_constants_byte_array = neighbor_max_push_constants.to_byte_array()
|
||||
neighbor_max_push_constants_byte_array.append_array(int_neighbor_max_push_constants.to_byte_array())
|
||||
|
||||
var tile_variance_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_variance_push_constants : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_variance_push_constants_byte_array = tile_variance_push_constants.to_byte_array()
|
||||
tile_variance_push_constants_byte_array.append_array(int_tile_variance_push_constants.to_byte_array())
|
||||
|
||||
var blur_push_constants: PackedFloat32Array = [
|
||||
minimum_user_threshold,
|
||||
importance_bias,
|
||||
maximum_jitter_value,
|
||||
temp_intensity,
|
||||
]
|
||||
var int_blur_push_constants : PackedInt32Array = [
|
||||
tile_size,
|
||||
samples,
|
||||
Engine.get_frames_drawn() % 8,
|
||||
0
|
||||
]
|
||||
var blur_push_constants_byte_array = blur_push_constants.to_byte_array()
|
||||
blur_push_constants_byte_array.append_array(int_blur_push_constants.to_byte_array())
|
||||
|
||||
var view_count = render_scene_buffers.get_view_count()
|
||||
|
||||
for view in range(view_count):
|
||||
var color_image := render_scene_buffers.get_color_layer(view)
|
||||
var depth_image := render_scene_buffers.get_depth_layer(view)
|
||||
var output_color_image := render_scene_buffers.get_texture_slice(context, output_color, view, 0, 1, 1)
|
||||
var tile_max_x_image := render_scene_buffers.get_texture_slice(context, tile_max_x, view, 0, 1, 1)
|
||||
var tile_max_image := render_scene_buffers.get_texture_slice(context, tile_max, view, 0, 1, 1)
|
||||
var neighbor_max_image := render_scene_buffers.get_texture_slice(context, neighbor_max, view, 0, 1, 1)
|
||||
var tile_variance_image := render_scene_buffers.get_texture_slice(context, tile_variance, view, 0, 1, 1)
|
||||
var custom_velocity_image := render_scene_buffers.get_texture_slice(context, custom_velocity, view, 0, 1, 1)
|
||||
|
||||
var x_groups := floori((render_size.x / tile_size - 1) / 16 + 1)
|
||||
var y_groups := floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_x_stage,
|
||||
[
|
||||
get_sampler_uniform(custom_velocity_image, 0, false),
|
||||
get_sampler_uniform(depth_image, 1, false),
|
||||
get_image_uniform(tile_max_x_image, 2)
|
||||
],
|
||||
tile_max_x_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxX",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x / tile_size - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y / tile_size - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_y_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_x_image, 0, false),
|
||||
get_image_uniform(tile_max_image, 1)
|
||||
],
|
||||
tile_max_y_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxY",
|
||||
view)
|
||||
|
||||
dispatch_stage(neighbor_max_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_image_uniform(neighbor_max_image, 1)
|
||||
],
|
||||
neighbor_max_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"NeighborMax",
|
||||
view)
|
||||
|
||||
dispatch_stage(tile_variance_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_image_uniform(tile_variance_image, 1)
|
||||
],
|
||||
tile_variance_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileVariance",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(blur_stage,
|
||||
[
|
||||
get_sampler_uniform(color_image, 0, false),
|
||||
get_sampler_uniform(custom_velocity_image, 1, false),
|
||||
get_sampler_uniform(neighbor_max_image, 2, false),
|
||||
get_sampler_uniform(tile_variance_image, 3, true),
|
||||
get_image_uniform(output_color_image, 4),
|
||||
],
|
||||
blur_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Blur",
|
||||
view)
|
||||
|
||||
dispatch_stage(overlay_stage,
|
||||
[
|
||||
get_sampler_uniform(output_color_image, 0, false),
|
||||
get_image_uniform(color_image, 1)
|
||||
],
|
||||
[],
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Overlay result",
|
||||
view)
|
||||
|
||||
rd.draw_command_end_label()
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://cvb65hfs2lrxo"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_i1bu0"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://bn88jkvr17x4j" path="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_neighbor_max.glsl" id="2_jp4do"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_i1bu0")
|
||||
shader_file = ExtResource("2_jp4do")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://bidsfymvdyhek"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_2uett"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://i6rnwhmss334" path="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_overlay.glsl" id="2_evkw4"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_2uett")
|
||||
shader_file = ExtResource("2_evkw4")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://dipvwksvqb3dm"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_bxcqf"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://d0s5upcgm7r6l" path="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_tile_max_x.glsl" id="2_q6kae"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_bxcqf")
|
||||
shader_file = ExtResource("2_q6kae")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://bxfg45ubc2pv7"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_gy5dj"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://ceetvitdbio4l" path="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_tile_max_y.glsl" id="2_grpec"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_gy5dj")
|
||||
shader_file = ExtResource("2_grpec")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://bqehecsdgt70s"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_kkpwt"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://by6mslkv0palh" path="res://addons/SphynxMotionBlurToolkit/Guertin/ShaderFiles/guertin_tile_variance.glsl" id="2_r5u5d"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_kkpwt")
|
||||
shader_file = ExtResource("2_r5u5d")
|
||||
|
|
@ -1,245 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/Guertin/base_guertin_motion_blur.gd"
|
||||
class_name GuertinMotionBlur
|
||||
|
||||
@export_group("Shader Stages")
|
||||
@export var blur_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_experimental_blur_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(blur_stage)
|
||||
blur_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var overlay_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_overlay_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(overlay_stage)
|
||||
overlay_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var tile_max_x_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_tile_max_x_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_x_stage)
|
||||
tile_max_x_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var tile_max_y_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_tile_max_y_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_y_stage)
|
||||
tile_max_y_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var neighbor_max_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_neighbor_max_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(neighbor_max_stage)
|
||||
neighbor_max_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var tile_variance_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/Guertin/guertin_tile_variance_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_variance_stage)
|
||||
tile_variance_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
var output_color: StringName = "output_color"
|
||||
|
||||
var tile_max_x : StringName = "tile_max_x"
|
||||
|
||||
var tile_max : StringName = "tile_max"
|
||||
|
||||
var neighbor_max : StringName = "neighbor_max"
|
||||
|
||||
var tile_variance : StringName = "tile_variance"
|
||||
|
||||
var custom_velocity : StringName = "custom_velocity"
|
||||
|
||||
var freeze : bool = false
|
||||
|
||||
var temp_intensity : float
|
||||
|
||||
var previous_time : float = 0
|
||||
|
||||
func _render_callback_2(render_size : Vector2i, render_scene_buffers : RenderSceneBuffersRD, render_scene_data : RenderSceneDataRD):
|
||||
var time : float = float(Time.get_ticks_msec()) / 1000
|
||||
|
||||
var delta_time : float = time - previous_time
|
||||
|
||||
previous_time = time
|
||||
|
||||
temp_intensity = intensity
|
||||
|
||||
if framerate_independent:
|
||||
var capped_frame_time : float = 1 / target_constant_framerate
|
||||
|
||||
if !uncapped_independence:
|
||||
capped_frame_time = min(capped_frame_time, delta_time)
|
||||
|
||||
temp_intensity = intensity * capped_frame_time / delta_time
|
||||
|
||||
ensure_texture(tile_max_x, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / tile_size, 1.))
|
||||
ensure_texture(tile_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / tile_size, 1. / tile_size))
|
||||
ensure_texture(neighbor_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / tile_size, 1. / tile_size))
|
||||
ensure_texture(tile_variance, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / tile_size, 1. / tile_size))
|
||||
ensure_texture(custom_velocity, render_scene_buffers)
|
||||
ensure_texture(output_color, render_scene_buffers)
|
||||
|
||||
rd.draw_command_begin_label("Motion Blur", Color(1.0, 1.0, 1.0, 1.0))
|
||||
|
||||
var tile_max_x_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_x_push_constants : PackedInt32Array = [
|
||||
tile_size,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_x_push_constants_byte_array = tile_max_x_push_constants.to_byte_array()
|
||||
tile_max_x_push_constants_byte_array.append_array(int_tile_max_x_push_constants.to_byte_array())
|
||||
|
||||
var tile_max_y_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_y_push_constants : PackedInt32Array = [
|
||||
tile_size,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_y_push_constants_byte_array = tile_max_y_push_constants.to_byte_array()
|
||||
tile_max_y_push_constants_byte_array.append_array(int_tile_max_y_push_constants.to_byte_array())
|
||||
|
||||
var neighbor_max_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_neighbor_max_push_constants : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var neighbor_max_push_constants_byte_array = neighbor_max_push_constants.to_byte_array()
|
||||
neighbor_max_push_constants_byte_array.append_array(int_neighbor_max_push_constants.to_byte_array())
|
||||
|
||||
var tile_variance_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_variance_push_constants : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_variance_push_constants_byte_array = tile_variance_push_constants.to_byte_array()
|
||||
tile_variance_push_constants_byte_array.append_array(int_tile_variance_push_constants.to_byte_array())
|
||||
|
||||
var blur_push_constants: PackedFloat32Array = [
|
||||
minimum_user_threshold,
|
||||
importance_bias,
|
||||
maximum_jitter_value,
|
||||
temp_intensity,
|
||||
]
|
||||
var int_blur_push_constants : PackedInt32Array = [
|
||||
tile_size,
|
||||
samples,
|
||||
Engine.get_frames_drawn() % 8,
|
||||
0
|
||||
]
|
||||
var blur_push_constants_byte_array = blur_push_constants.to_byte_array()
|
||||
blur_push_constants_byte_array.append_array(int_blur_push_constants.to_byte_array())
|
||||
|
||||
var view_count = render_scene_buffers.get_view_count()
|
||||
|
||||
for view in range(view_count):
|
||||
var color_image := render_scene_buffers.get_color_layer(view)
|
||||
var depth_image := render_scene_buffers.get_depth_layer(view)
|
||||
var output_color_image := render_scene_buffers.get_texture_slice(context, output_color, view, 0, 1, 1)
|
||||
var tile_max_x_image := render_scene_buffers.get_texture_slice(context, tile_max_x, view, 0, 1, 1)
|
||||
var tile_max_image := render_scene_buffers.get_texture_slice(context, tile_max, view, 0, 1, 1)
|
||||
var neighbor_max_image := render_scene_buffers.get_texture_slice(context, neighbor_max, view, 0, 1, 1)
|
||||
var tile_variance_image := render_scene_buffers.get_texture_slice(context, tile_variance, view, 0, 1, 1)
|
||||
var custom_velocity_image := render_scene_buffers.get_texture_slice(context, custom_velocity, view, 0, 1, 1)
|
||||
|
||||
var x_groups := floori((render_size.x / tile_size - 1) / 16 + 1)
|
||||
var y_groups := floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_x_stage,
|
||||
[
|
||||
get_sampler_uniform(custom_velocity_image, 0, false),
|
||||
get_sampler_uniform(depth_image, 1, false),
|
||||
get_image_uniform(tile_max_x_image, 2)
|
||||
],
|
||||
tile_max_x_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxX",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x / tile_size - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y / tile_size - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_y_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_x_image, 0, false),
|
||||
get_image_uniform(tile_max_image, 1)
|
||||
],
|
||||
tile_max_y_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxY",
|
||||
view)
|
||||
|
||||
dispatch_stage(neighbor_max_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_image_uniform(neighbor_max_image, 1)
|
||||
],
|
||||
neighbor_max_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"NeighborMax",
|
||||
view)
|
||||
|
||||
dispatch_stage(tile_variance_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_image_uniform(tile_variance_image, 1)
|
||||
],
|
||||
tile_variance_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileVariance",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(blur_stage,
|
||||
[
|
||||
get_sampler_uniform(color_image, 0, false),
|
||||
get_sampler_uniform(custom_velocity_image, 1, false),
|
||||
get_sampler_uniform(neighbor_max_image, 2, false),
|
||||
get_sampler_uniform(tile_variance_image, 3, true),
|
||||
get_image_uniform(output_color_image, 4),
|
||||
],
|
||||
blur_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Blur",
|
||||
view)
|
||||
|
||||
dispatch_stage(overlay_stage,
|
||||
[
|
||||
get_sampler_uniform(output_color_image, 0, false),
|
||||
get_image_uniform(color_image, 1)
|
||||
],
|
||||
[],
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Overlay result",
|
||||
view)
|
||||
|
||||
rd.draw_command_end_label()
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max;
|
||||
layout(set = 0, binding = 1) uniform sampler2D tile_max_map;
|
||||
layout(rgba16f, set = 0, binding = 2) uniform writeonly image2D neighbor_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 max_neighbor_velocity = vec2(0);
|
||||
|
||||
float max_neighbor_depth = -1;
|
||||
|
||||
for(int i = -1; i < 2; i++)
|
||||
{
|
||||
for(int j = -1; j < 2; j++)
|
||||
{
|
||||
vec2 current_offset = vec2(1) / vec2(render_size) * vec2(i, j);
|
||||
vec2 current_uv = uvn + current_offset;
|
||||
if(current_uv.x < 0 || current_uv.x > 1 || current_uv.y < 0 || current_uv.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vec3 current_neighbor_sample = textureLod(tile_max_map, current_uv, 0.0).xyz;
|
||||
|
||||
if(current_neighbor_sample.z > max_neighbor_depth)
|
||||
{
|
||||
max_neighbor_depth = current_neighbor_sample.z;
|
||||
max_neighbor_velocity = current_neighbor_sample.xy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imageStore(neighbor_max, uvi, vec4(max_neighbor_velocity, 0, 1));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://bcivntgn7ipwo"
|
||||
path="res://.godot/imported/jf_neighbor_depth_max.glsl-d20bc4da7a00b27ca7e046fc2a191610.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/Archive/jf_neighbor_depth_max.glsl"
|
||||
dest_files=["res://.godot/imported/jf_neighbor_depth_max.glsl-d20bc4da7a00b27ca7e046fc2a191610.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,201 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D buffer_a;
|
||||
layout(rgba16f, set = 0, binding = 2) uniform writeonly image2D buffer_b;
|
||||
layout(set = 0, binding = 3) uniform sampler2D buffer_a_sampler;
|
||||
layout(set = 0, binding = 4) uniform sampler2D buffer_b_sampler;
|
||||
|
||||
layout(set = 0, binding = 5, std430) restrict buffer MyDataBuffer {
|
||||
int iteration_index;
|
||||
}
|
||||
iteration_data;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
int nan0;//iteration_index;
|
||||
int last_iteration_index;
|
||||
int nan1;
|
||||
int nan2;
|
||||
float perpen_error_thresh;
|
||||
float sample_step_multiplier;
|
||||
float motion_blur_intensity;
|
||||
float nan_fl_5;
|
||||
float nan_fl_4;
|
||||
float nan_fl_3;
|
||||
float nan_fl_6;
|
||||
float step_exponent_modifier;
|
||||
float nan_fl_0;//step_size;
|
||||
float max_dilation_radius;
|
||||
float nan_fl_1;
|
||||
float nan_fl_2;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
const int kernel_size = 8;
|
||||
|
||||
const vec2 check_step_kernel[kernel_size] = {
|
||||
vec2(-1, 0),
|
||||
vec2(1, 0),
|
||||
vec2(0, -1),
|
||||
vec2(0, 1),
|
||||
vec2(-1, 1),
|
||||
vec2(1, -1),
|
||||
vec2(1, 1),
|
||||
vec2(-1, -1),
|
||||
};
|
||||
|
||||
vec2 get_value(bool a, vec2 uv)
|
||||
{
|
||||
if(a)
|
||||
{
|
||||
return textureLod(buffer_a_sampler, uv, 0.0).xy;
|
||||
}
|
||||
else
|
||||
{
|
||||
return textureLod(buffer_b_sampler, uv, 0.0).xy;
|
||||
}
|
||||
}
|
||||
|
||||
void set_value(bool a, ivec2 uvi, vec4 value)
|
||||
{
|
||||
if(a)
|
||||
{
|
||||
imageStore(buffer_a, uvi, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageStore(buffer_b, uvi, value);
|
||||
}
|
||||
}
|
||||
|
||||
void sample_fitness(vec2 uv_offset, vec4 uv_sample, vec2 render_size, inout vec4 current_sample_fitness)
|
||||
{
|
||||
vec2 sample_velocity = -uv_sample.xy;
|
||||
|
||||
// if (dot(sample_velocity, sample_velocity) <= FLT_MIN || uv_sample.w == 0)
|
||||
// {
|
||||
// current_sample_fitness = vec4(10, 10, 0, 0);
|
||||
// return;
|
||||
// }
|
||||
|
||||
float velocity_space_distance = dot(sample_velocity, uv_offset) / dot(sample_velocity, sample_velocity);
|
||||
|
||||
float mid_point = params.motion_blur_intensity / 2 + 1e-5;
|
||||
|
||||
float absolute_velocity_space_distance = abs(velocity_space_distance - mid_point);
|
||||
|
||||
float within_velocity_range = step(absolute_velocity_space_distance, mid_point);
|
||||
|
||||
float side_offset = abs(dot(vec2(uv_offset.y, -uv_offset.x), sample_velocity)) / dot(sample_velocity, sample_velocity);
|
||||
|
||||
float within_perpen_error_range = step(side_offset, params.perpen_error_thresh * params.motion_blur_intensity);
|
||||
|
||||
current_sample_fitness = vec4(/*max(absolute_velocity_space_distance, side_offset)*/absolute_velocity_space_distance, velocity_space_distance, uv_sample.w + uv_sample.z * velocity_space_distance, within_velocity_range * within_perpen_error_range);
|
||||
}
|
||||
|
||||
//float is_sample_better(vec4 a, vec4 b)
|
||||
//{
|
||||
// return 1. - step(b.x * a.w, a.x * b.w);//mix(1. - step(b.x * a.w, a.x * b.w), step(b.z, a.z), step(0.5, b.w) * step(0.5, a.w));
|
||||
//}
|
||||
|
||||
//vec4 backtrack_sample(vec2 chosen_uv, vec4 best_sample_fitness)
|
||||
//{
|
||||
// vec4 velocity = textureLod(tile_max_sampler, chosen_uv, 0.0);
|
||||
//
|
||||
// vec2 uv_candidate = chosen_uv + velocity.xy;
|
||||
//
|
||||
// vec4 velocity_candidate = textureLod(tile_max_sampler, uv_candidate, 0.0);
|
||||
//
|
||||
// if((dot(velocity, velocity_candidate) / dot(velocity, velocity)) > 0.5 && velocity_candidate.w > 0)
|
||||
// {
|
||||
// return vec4(uv_candidate, 0, 0);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return vec4(chosen_uv, 0, 0);
|
||||
// }
|
||||
//}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 step_size = vec2(round(pow(2 + params.step_exponent_modifier, params.last_iteration_index - iteration_data.iteration_index)));
|
||||
|
||||
vec2 uv_step = vec2(round(step_size)) / render_size;
|
||||
|
||||
vec4 best_sample_fitness = vec4(10, 10, 0, 0);
|
||||
|
||||
vec2 chosen_uv = uvn;
|
||||
|
||||
bool set_a = !bool(step(0.5, float(iteration_data.iteration_index % 2)));
|
||||
|
||||
iteration_data.iteration_index += 1;
|
||||
|
||||
vec2 step_offset;
|
||||
|
||||
vec2 check_uv;
|
||||
|
||||
vec4 uv_sample;
|
||||
|
||||
vec4 current_sample_fitness;
|
||||
|
||||
for(int i = 0; i < kernel_size; i++)
|
||||
{
|
||||
step_offset = check_step_kernel[i] * uv_step;
|
||||
check_uv = uvn + step_offset;
|
||||
|
||||
if(any(notEqual(check_uv, clamp(check_uv, vec2(0.0), vec2(1.0)))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// if(iteration_data.iteration_index > 0)
|
||||
// {
|
||||
check_uv = get_value(!set_a, check_uv).xy;
|
||||
|
||||
step_offset = check_uv - uvn;
|
||||
// }
|
||||
|
||||
uv_sample = textureLod(tile_max_sampler, check_uv, 0.0);
|
||||
|
||||
sample_fitness(step_offset, uv_sample, render_size, current_sample_fitness);
|
||||
|
||||
float sample_better = 1. - step(current_sample_fitness.z * current_sample_fitness.w, best_sample_fitness.z * best_sample_fitness.w);
|
||||
best_sample_fitness = mix(best_sample_fitness, current_sample_fitness, sample_better);
|
||||
chosen_uv = mix(chosen_uv, check_uv, sample_better);
|
||||
}
|
||||
|
||||
// if(params.iteration_index < params.last_iteration_index)
|
||||
// {
|
||||
// set_value(set_a, uvi, vec4(chosen_uv, 0, 0));
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// float depth = textureLod(tile_max_sampler, uvn, 0.0).w;
|
||||
//
|
||||
// if(params.iteration_index == params.last_iteration_index && (best_sample_fitness.w < 0.5 || depth > best_sample_fitness.z))
|
||||
// {
|
||||
// set_value(set_a, uvi, vec4(uvn, 0, 0));
|
||||
// return;
|
||||
// }
|
||||
|
||||
set_value(set_a, uvi, vec4(chosen_uv, 0, 0));
|
||||
|
||||
// vec4 backtracked_sample = backtrack_sample(chosen_uv, best_sample_fitness);
|
||||
//
|
||||
// set_value(set_a, uvi, backtracked_sample);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://brlr85tfh5tv2"
|
||||
path="res://.godot/imported/jf_simple_archive_17_8_24.glsl-e91ee2bf9d7e74579e89e443fc0e02d3.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/Archive/jf_simple_archive_17_8_24.glsl"
|
||||
dest_files=["res://.godot/imported/jf_simple_archive_17_8_24.glsl-e91ee2bf9d7e74579e89e443fc0e02d3.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D buffer_a;
|
||||
layout(rgba16f, set = 0, binding = 2) uniform writeonly image2D buffer_b;
|
||||
layout(set = 0, binding = 3) uniform sampler2D buffer_a_sampler;
|
||||
layout(set = 0, binding = 4) uniform sampler2D buffer_b_sampler;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
int iteration_index;
|
||||
int last_iteration_index;
|
||||
int nan1;
|
||||
int nan2;
|
||||
float perpen_error_thresh;
|
||||
float sample_step_multiplier;
|
||||
float motion_blur_intensity;
|
||||
float nan_fl_5;
|
||||
float nan_fl_4;
|
||||
float nan_fl_3;
|
||||
float nan_fl_6;
|
||||
float step_exponent_modifier;
|
||||
float step_size;
|
||||
float max_dilation_radius;
|
||||
float nan_fl_1;
|
||||
float nan_fl_2;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
const int kernel_size = 8;
|
||||
|
||||
const vec2 check_step_kernel[kernel_size] = {
|
||||
vec2(-1, 0),
|
||||
vec2(1, 0),
|
||||
vec2(0, -1),
|
||||
vec2(0, 1),
|
||||
vec2(-1, 1),
|
||||
vec2(1, -1),
|
||||
vec2(1, 1),
|
||||
vec2(-1, -1),
|
||||
};
|
||||
|
||||
vec2 get_value(bool a, vec2 uv)
|
||||
{
|
||||
if(a)
|
||||
{
|
||||
return textureLod(buffer_a_sampler, uv, 0.0).xy;
|
||||
}
|
||||
else
|
||||
{
|
||||
return textureLod(buffer_b_sampler, uv, 0.0).xy;
|
||||
}
|
||||
}
|
||||
|
||||
void set_value(bool a, ivec2 uvi, vec4 value)
|
||||
{
|
||||
if(a)
|
||||
{
|
||||
imageStore(buffer_a, uvi, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageStore(buffer_b, uvi, value);
|
||||
}
|
||||
}
|
||||
|
||||
void sample_fitness(vec2 uv_offset, vec4 uv_sample, vec2 render_size, inout vec4 current_sample_fitness)
|
||||
{
|
||||
vec2 sample_velocity = -uv_sample.xy;
|
||||
|
||||
// if (dot(sample_velocity, sample_velocity) <= FLT_MIN || uv_sample.w == 0)
|
||||
// {
|
||||
// current_sample_fitness = vec4(10, 10, 0, 0);
|
||||
// return;
|
||||
// }
|
||||
|
||||
float velocity_space_distance = dot(sample_velocity, uv_offset) / dot(sample_velocity, sample_velocity);
|
||||
|
||||
float mid_point = params.motion_blur_intensity / 2 + 1e-5;
|
||||
|
||||
float absolute_velocity_space_distance = abs(velocity_space_distance - mid_point);
|
||||
|
||||
float within_velocity_range = step(absolute_velocity_space_distance, mid_point);
|
||||
|
||||
float side_offset = abs(dot(vec2(uv_offset.y, -uv_offset.x), sample_velocity)) / dot(sample_velocity, sample_velocity);
|
||||
|
||||
float within_perpen_error_range = step(side_offset, params.perpen_error_thresh * params.motion_blur_intensity);
|
||||
|
||||
current_sample_fitness = vec4(/*max(absolute_velocity_space_distance, side_offset)*/absolute_velocity_space_distance, velocity_space_distance, uv_sample.w + uv_sample.z * velocity_space_distance, within_velocity_range * within_perpen_error_range);
|
||||
}
|
||||
|
||||
//float is_sample_better(vec4 a, vec4 b)
|
||||
//{
|
||||
// return 1. - step(b.x * a.w, a.x * b.w);//mix(1. - step(b.x * a.w, a.x * b.w), step(b.z, a.z), step(0.5, b.w) * step(0.5, a.w));
|
||||
//}
|
||||
|
||||
//vec4 backtrack_sample(vec2 chosen_uv, vec4 best_sample_fitness)
|
||||
//{
|
||||
// vec4 velocity = textureLod(tile_max_sampler, chosen_uv, 0.0);
|
||||
//
|
||||
// vec2 uv_candidate = chosen_uv + velocity.xy;
|
||||
//
|
||||
// vec4 velocity_candidate = textureLod(tile_max_sampler, uv_candidate, 0.0);
|
||||
//
|
||||
// if((dot(velocity, velocity_candidate) / dot(velocity, velocity)) > 0.5 && velocity_candidate.w > 0)
|
||||
// {
|
||||
// return vec4(uv_candidate, 0, 0);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return vec4(chosen_uv, 0, 0);
|
||||
// }
|
||||
//}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 uv_step = vec2(round(params.step_size)) / render_size;
|
||||
|
||||
vec4 best_sample_fitness = vec4(10, 10, 0, 0);
|
||||
|
||||
vec2 chosen_uv = uvn;
|
||||
|
||||
bool set_a = !bool(step(0.5, float(params.iteration_index % 2)));
|
||||
|
||||
vec2 step_offset;
|
||||
|
||||
vec2 check_uv;
|
||||
|
||||
vec4 uv_sample;
|
||||
|
||||
vec4 current_sample_fitness;
|
||||
|
||||
for(int i = 0; i < kernel_size; i++)
|
||||
{
|
||||
step_offset = check_step_kernel[i] * uv_step;
|
||||
check_uv = uvn + step_offset;
|
||||
|
||||
if(any(notEqual(check_uv, clamp(check_uv, vec2(0.0), vec2(1.0)))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(params.iteration_index > 0)
|
||||
{
|
||||
check_uv = get_value(!set_a, check_uv).xy;
|
||||
|
||||
step_offset = check_uv - uvn;
|
||||
}
|
||||
|
||||
uv_sample = textureLod(tile_max_sampler, check_uv, 0.0);
|
||||
|
||||
sample_fitness(step_offset, uv_sample, render_size, current_sample_fitness);
|
||||
|
||||
float sample_better = 1. - step(current_sample_fitness.z * current_sample_fitness.w, best_sample_fitness.z * best_sample_fitness.w);
|
||||
best_sample_fitness = mix(best_sample_fitness, current_sample_fitness, sample_better);
|
||||
chosen_uv = mix(chosen_uv, check_uv, sample_better);
|
||||
}
|
||||
|
||||
// if(params.iteration_index < params.last_iteration_index)
|
||||
// {
|
||||
// set_value(set_a, uvi, vec4(chosen_uv, 0, 0));
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// float depth = textureLod(tile_max_sampler, uvn, 0.0).w;
|
||||
//
|
||||
// if(params.iteration_index == params.last_iteration_index && (best_sample_fitness.w < 0.5 || depth > best_sample_fitness.z))
|
||||
// {
|
||||
// set_value(set_a, uvi, vec4(uvn, 0, 0));
|
||||
// return;
|
||||
// }
|
||||
|
||||
set_value(set_a, uvi, vec4(chosen_uv, 0, 0));
|
||||
|
||||
// vec4 backtracked_sample = backtrack_sample(chosen_uv, best_sample_fitness);
|
||||
//
|
||||
// set_value(set_a, uvi, backtracked_sample);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://c7q41dxu78i8o"
|
||||
path="res://.godot/imported/jfp_simple_push_based_archive.glsl-a99001e07de7540b5869f83d2e3643a4.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/Archive/jfp_simple_push_based_archive.glsl"
|
||||
dest_files=["res://.godot/imported/jfp_simple_push_based_archive.glsl-a99001e07de7540b5869f83d2e3643a4.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,235 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D depth_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D vector_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D velocity_map;
|
||||
layout(rgba16f, set = 0, binding = 4) uniform writeonly image2D output_image;
|
||||
layout(rgba16f, set = 0, binding = 5) uniform writeonly image2D debug_1_image;
|
||||
layout(rgba16f, set = 0, binding = 6) uniform writeonly image2D debug_2_image;
|
||||
layout(rgba16f, set = 0, binding = 7) uniform writeonly image2D debug_3_image;
|
||||
layout(rgba16f, set = 0, binding = 8) uniform writeonly image2D debug_4_image;
|
||||
layout(rgba16f, set = 0, binding = 9) uniform writeonly image2D debug_5_image;
|
||||
layout(rgba16f, set = 0, binding = 10) uniform writeonly image2D debug_6_image;
|
||||
layout(rgba16f, set = 0, binding = 11) uniform writeonly image2D debug_7_image;
|
||||
layout(rgba16f, set = 0, binding = 12) uniform writeonly image2D debug_8_image;
|
||||
layout(set = 0, binding = 13) uniform sampler2D tile_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float motion_blur_samples;
|
||||
float motion_blur_intensity;
|
||||
float motion_blur_center_fade;
|
||||
float frame;
|
||||
float last_iteration_index;
|
||||
float sample_step_multiplier;
|
||||
float step_exponent_modifier;
|
||||
float max_dilation_radius;
|
||||
int nan0;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - T / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, T);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float sze)
|
||||
{
|
||||
return clamp(1. - sze * (a - b) / min(a, b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv){
|
||||
uv += float(params.frame) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://github.com/bradparks/KinoMotion__unity_motion_blur/tree/master
|
||||
// ----------------------------------------------------------
|
||||
vec2 safenorm(vec2 v)
|
||||
{
|
||||
float l = max(length(v), 1e-6);
|
||||
return v / l * int(1 >= 0.5);
|
||||
}
|
||||
|
||||
vec2 jitter_tile(vec2 uvi)
|
||||
{
|
||||
float rx, ry;
|
||||
float angle = interleaved_gradient_noise(uvi + vec2(2, 0)) * M_PI * 2;
|
||||
rx = cos(angle);
|
||||
ry = sin(angle);
|
||||
return vec2(rx, ry) / textureSize(tile_max, 0) / 4;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
float get_motion_difference(vec2 V, vec2 V2, float power)
|
||||
{
|
||||
vec2 VO = V - V2;
|
||||
float difference = dot(VO, V) / max(FLT_MIN, dot(V, V));
|
||||
return pow(clamp(difference, 0, 1), power);
|
||||
}
|
||||
|
||||
vec2 sample_random_offset(vec2 uv, float j)
|
||||
{
|
||||
return vec2(0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
vec2 velocity_map_sample = textureLod(velocity_map, x + jitter_tile(uvi), 0.0).xy;
|
||||
|
||||
vec3 vnz = textureLod(tile_max, velocity_map_sample, 0.0).xyz * vec3(render_size, 1);// * 2;
|
||||
|
||||
vec2 vn = vnz.xy;
|
||||
|
||||
float vn_length = max(0.5, length(vn));
|
||||
|
||||
vec2 wn = safenorm(vn);
|
||||
|
||||
vec4 col_x = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
vec3 vxz = textureLod(vector_sampler, x, 0.0).xyz * vec3(render_size, 1);// * 2;
|
||||
|
||||
vec2 vx = vxz.xy;
|
||||
|
||||
if(vn_length <= 0.5)
|
||||
{
|
||||
imageStore(output_image, uvi, col_x);
|
||||
imageStore(debug_1_image, uvi, col_x);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, 10 * abs(textureLod(tile_max, x, 0.0)));
|
||||
imageStore(debug_6_image, uvi, 10 * abs(textureLod(tile_max, textureLod(velocity_map, x, 0.0).xy, 0.0)));
|
||||
imageStore(debug_7_image, uvi, 10 * abs(textureLod(velocity_map, x, 0.0)));
|
||||
imageStore(debug_8_image, uvi, abs(textureLod(velocity_map, x, 0.0) / 10));
|
||||
return;
|
||||
}
|
||||
|
||||
float zx = -0.05 / max(FLT_MIN, textureLod(depth_sampler, x, 0.0).x);
|
||||
|
||||
float vx_length = max(0.5, length(vx));
|
||||
|
||||
vec2 wx = safenorm(vx);
|
||||
|
||||
vec2 wp = vec2(-wn.y, wn.x);
|
||||
|
||||
if(dot(wp, vx) < 0)
|
||||
{
|
||||
wp = -wp;
|
||||
}
|
||||
|
||||
vec2 wc = safenorm(mix(wp, wx, clamp((vx_length - 0.5) / 1.5, 0, 1)));
|
||||
|
||||
float weight = 1;//params.motion_blur_samples / (100 * vx_length);
|
||||
|
||||
vec4 sum = col_x * weight;
|
||||
|
||||
float j = interleaved_gradient_noise(uvi) - 0.5;
|
||||
|
||||
int vnvx = 2;//int(vn_length / (10 + vx_length)) + 2;
|
||||
|
||||
for(int i = 0; i < params.motion_blur_samples; i++)
|
||||
{
|
||||
if(i == (params.motion_blur_samples - 1) / 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float t = mix(-1., 0.0, (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
float T = abs(t * vn_length);
|
||||
|
||||
float Tx = abs((t + 0.5) * vn_length);
|
||||
|
||||
bool sample_main_v = !(((i - 1) % vnvx) == 0);
|
||||
|
||||
vec2 d = vn;//sample_main_v ? vn : vx;
|
||||
|
||||
float dz = vnz.z;//sample_main_v ? vnz.z : vxz.z;
|
||||
|
||||
vec2 wd = safenorm(d);
|
||||
|
||||
vec2 y = x + (d / render_size) * t;
|
||||
|
||||
vec2 vy = textureLod(vector_sampler, y, 0.0).xy * render_size;// * 2;
|
||||
|
||||
float vy_length = max(0.5, length(vy));
|
||||
|
||||
float zy = -0.05 / max(FLT_MIN, textureLod(depth_sampler, y, 0.0).x - dz * t);
|
||||
|
||||
float f = z_compare(zy, zx, 15);
|
||||
float b = z_compare(zx, zy, 15);
|
||||
|
||||
float wa = abs(max(0, dot(vy / vy_length, wd)));
|
||||
|
||||
float wb = abs((dot(wc, wd)));
|
||||
|
||||
float cone_x = cone(T, vx_length); // how much of the velocity reaches the current position
|
||||
|
||||
float cone_y = cone(T, vy_length); // how much of the velocity reaches the current position
|
||||
|
||||
float ay = clamp(max(step(FLT_MIN, f * wa * cone_y), step(FLT_MIN, b * wb * cone_x)), 0, 1);// * wb;// + cylinder(T, vy_length) * cylinder(T, vx_length) * 2;//cylinder(T, min(vy_length, vx_length)) * 2. * max(wa, wb);//
|
||||
|
||||
vec4 col_y = textureLod(color_sampler, y, 0.0);
|
||||
|
||||
vec4 final_color = mix(col_x, col_y, ay);
|
||||
|
||||
float final_weight = mix(1, 1, ay);
|
||||
|
||||
weight += final_weight;//ay;
|
||||
sum += final_color * final_weight;// * ay;
|
||||
}
|
||||
|
||||
sum /= weight;
|
||||
|
||||
imageStore(output_image, uvi, sum);
|
||||
|
||||
imageStore(debug_1_image, uvi, sum);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, 10 * abs(textureLod(tile_max, x, 0.0)));
|
||||
imageStore(debug_6_image, uvi, 10 * abs(textureLod(tile_max, textureLod(velocity_map, x, 0.0).xy, 0.0)));
|
||||
imageStore(debug_7_image, uvi, 10 * abs(textureLod(velocity_map, x, 0.0)));
|
||||
imageStore(debug_8_image, uvi, abs(textureLod(velocity_map, x, 0.0) / 10));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://dc6r26wwdjceq"
|
||||
path="res://.godot/imported/jump_flood_mcguire_blur.glsl-db182d03471f2a14ff66b8fcdafe8dc6.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/Archive/jump_flood_mcguire_blur.glsl"
|
||||
dest_files=["res://.godot/imported/jump_flood_mcguire_blur.glsl-db182d03471f2a14ff66b8fcdafe8dc6.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,452 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D depth_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D velocity_map;
|
||||
layout(rgba16f, set = 0, binding = 4) uniform writeonly image2D output_image;
|
||||
layout(set = 0, binding = 5) uniform sampler2D tile_max;
|
||||
layout(set = 0, binding = 6) uniform sampler2D past_color_sampler;
|
||||
layout(set = 0, binding = 7) uniform sampler2D past_velocity_sampler;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float motion_blur_samples;
|
||||
float motion_blur_intensity;
|
||||
float motion_blur_center_fade;
|
||||
float frame;
|
||||
float last_iteration_index;
|
||||
float sample_step_multiplier;
|
||||
float step_exponent_modifier;
|
||||
float max_dilation_radius;
|
||||
int nan0;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - T / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, T);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float sze)
|
||||
{
|
||||
return clamp(1. - sze * (a - b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv){
|
||||
uv += float(params.frame) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://github.com/bradparks/KinoMotion__unity_motion_blur/tree/master
|
||||
// ----------------------------------------------------------
|
||||
vec2 safenorm(vec2 v)
|
||||
{
|
||||
float l = max(length(v), 1e-6);
|
||||
return v / l * int(l >= 0.5);
|
||||
}
|
||||
|
||||
vec2 jitter_tile(vec2 uvi)
|
||||
{
|
||||
float rx, ry;
|
||||
float angle = interleaved_gradient_noise(uvi + vec2(2, 0)) * M_PI * 2;
|
||||
rx = cos(angle);
|
||||
ry = sin(angle);
|
||||
return vec2(rx, ry) / textureSize(tile_max, 0) / 4;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
vec2 velocity_map_sample = textureLod(velocity_map, x + jitter_tile(uvi), 0.0).xy;
|
||||
|
||||
vec3 vnz = textureLod(tile_max, velocity_map_sample, 0.0).xyz * vec3(render_size, 1);
|
||||
|
||||
float vn_length = max(0.5, length(vnz.xy));
|
||||
|
||||
float multiplier = clamp(vn_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vn_length);
|
||||
|
||||
vnz.xyz *= multiplier;
|
||||
|
||||
vn_length *= multiplier;
|
||||
|
||||
vec2 vn = vnz.xy;
|
||||
|
||||
vec4 col_x = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
vec2 wn = safenorm(vn);
|
||||
|
||||
vec4 vxz = textureLod(velocity_sampler, x, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float vx_length = max(0.5, length(vxz.xy));
|
||||
|
||||
multiplier = clamp(vx_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vx_length);
|
||||
|
||||
vxz.xyz *= multiplier;
|
||||
|
||||
vx_length *= multiplier;
|
||||
|
||||
vec2 vx = vxz.xy;
|
||||
|
||||
if(vn_length <= 0.5)
|
||||
{
|
||||
imageStore(output_image, uvi, col_x);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, col_x);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
float velocity_match = pow(clamp(dot(vx, vn) / dot(vn, vn), 0, 1), 0.25);
|
||||
|
||||
vn = mix(vn, vx, velocity_match);
|
||||
|
||||
vnz = mix(vnz, vxz.xyz, velocity_match);
|
||||
|
||||
float zx = vxz.w;
|
||||
|
||||
vec2 wx = safenorm(vx);
|
||||
|
||||
float weight = 0;
|
||||
|
||||
vec4 sum = col_x * weight;
|
||||
|
||||
float total_back_weight = 1e-10;
|
||||
|
||||
vec4 back_sum = col_x * total_back_weight;
|
||||
|
||||
float j = interleaved_gradient_noise(uvi) - 0.5;
|
||||
|
||||
vec4 past_vxz = textureLod(past_velocity_sampler, x, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
vec2 past_vx = past_vxz.xy;
|
||||
|
||||
vec4 past_col_x = textureLod(past_color_sampler, x, 0.0);
|
||||
|
||||
for(int i = 0; i < params.motion_blur_samples; i++)
|
||||
{
|
||||
float nai_t = mix(0., -1., (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
float nai_T = abs(nai_t * vx_length);
|
||||
|
||||
vec2 nai_y = x + (vx / render_size) * nai_t;
|
||||
|
||||
if(nai_y.x < 0 || nai_y.x > 1 || nai_y.y < 0 || nai_y.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vec4 nai_vy = textureLod(velocity_sampler, nai_y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float nai_zy = nai_vy.w - vxz.z * nai_t;
|
||||
|
||||
float nai_b = z_compare(-zx, -nai_zy, 20000);
|
||||
|
||||
float nai_f = z_compare(-nai_zy, -zx, 20000);
|
||||
|
||||
float nai_ay = nai_b + (1 - nai_f);
|
||||
|
||||
float past_t = mix(0., -1., (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
vec2 past_y = x + (past_vx / render_size) * past_t;
|
||||
|
||||
float alpha = z_compare(-past_vxz.w, -vxz.w, 20000); // may need to be a step
|
||||
|
||||
vec4 past_vy = mix(textureLod(past_velocity_sampler, past_y, 0.0) * vec4(render_size, 1, 1), textureLod(velocity_sampler, past_y, 0.0) * vec4(render_size, 1, 1), alpha);
|
||||
|
||||
float past_zy = past_vy.w - past_vxz.z * past_t;
|
||||
|
||||
float past_b = z_compare(-past_vxz.w, -past_zy, 20000);
|
||||
|
||||
vec4 nai_col_y = mix(textureLod(color_sampler, nai_y, 0.0), mix(textureLod(past_color_sampler, x, 0.0), mix(textureLod(past_color_sampler, past_y, 0.0), textureLod(color_sampler, past_y, 0.0), alpha), past_b), (1 - nai_f));
|
||||
|
||||
total_back_weight += nai_ay;
|
||||
|
||||
back_sum += nai_col_y * nai_ay;
|
||||
|
||||
float t = mix(0., -1., (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
float T = abs(t * vn_length);
|
||||
|
||||
vec2 y = x + (vn / render_size) * t;
|
||||
|
||||
if(y.x < 0 || y.x > 1 || y.y < 0 || y.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vec4 vy = textureLod(velocity_sampler, y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float vy_length = max(0.5, length(vy.xy));
|
||||
|
||||
float zy = vy.w - vnz.z * t;
|
||||
|
||||
float f = z_compare(-zy, -zx, 20000);
|
||||
|
||||
float wa = abs(max(0, dot(vy.xy / vy_length, wn)));
|
||||
|
||||
float ay_trail = f * step(T, vy_length * wa);
|
||||
|
||||
vec4 col_y = textureLod(color_sampler, y, 0.0);
|
||||
|
||||
weight += ay_trail;
|
||||
|
||||
sum += col_y * ay_trail;
|
||||
}
|
||||
|
||||
back_sum *= (params.motion_blur_samples - weight) / total_back_weight;
|
||||
|
||||
sum /= params.motion_blur_samples;
|
||||
|
||||
back_sum /= params.motion_blur_samples;
|
||||
|
||||
imageStore(output_image, uvi, sum + back_sum);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, sum + back_sum);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
imageStore(debug_6_image, uvi, past_col_x);
|
||||
imageStore(debug_7_image, uvi, past_col_x);
|
||||
imageStore(debug_8_image, uvi, back_sum);
|
||||
#endif
|
||||
}
|
||||
|
||||
//void main()
|
||||
//{
|
||||
// ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
// ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
// if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
//
|
||||
// vec2 velocity_map_sample = textureLod(velocity_map, x + jitter_tile(uvi), 0.0).xy;
|
||||
//
|
||||
// vec3 vnz = textureLod(tile_max, velocity_map_sample, 0.0).xyz * vec3(render_size, 1);// * 2;
|
||||
//
|
||||
// vec2 vn = vnz.xy;
|
||||
//
|
||||
// float vn_length = max(0.5, length(vn));
|
||||
//
|
||||
// vec2 wn = safenorm(vn);
|
||||
//
|
||||
// vec4 col_x = textureLod(color_sampler, x, 0.0);
|
||||
//
|
||||
// vec3 vxz = textureLod(vector_sampler, x, 0.0).xyz * vec3(render_size, 1);// * 2;
|
||||
//
|
||||
// vec2 vx = vxz.xy;
|
||||
//
|
||||
// vec3 past_vxz = textureLod(past_velocity_sampler, x, 0.0).xyz * vec3(render_size, 1);
|
||||
//
|
||||
// vec2 past_vx = past_vxz.xy;
|
||||
//
|
||||
// vec4 past_col_x = textureLod(past_color_sampler, x, 0.0);
|
||||
//
|
||||
// float velocity_match = pow(clamp(dot(vx, vn) / dot(vn, vn), 0, 1), 0.5);
|
||||
//
|
||||
// vn = mix(vn, vx, velocity_match);
|
||||
//
|
||||
// vnz = mix(vnz, vxz, velocity_match);
|
||||
//
|
||||
// if(vn_length <= 0.5)
|
||||
// {
|
||||
// imageStore(output_image, uvi, col_x);
|
||||
//
|
||||
//#ifdef DEBUG
|
||||
// imageStore(debug_1_image, uvi, col_x);
|
||||
// imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
// imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
// imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
// imageStore(debug_5_image, uvi, col_x);
|
||||
// imageStore(debug_6_image, uvi, past_col_x);
|
||||
// imageStore(debug_7_image, uvi, past_col_x);
|
||||
// imageStore(debug_8_image, uvi, abs(vec4(past_vx / render_size * 10, past_vxz.z * 100, 1)));
|
||||
//#endif
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// float zx = -0.05 / max(FLT_MIN, textureLod(depth_sampler, x, 0.0).x);
|
||||
//
|
||||
// float vx_length = max(0.5, length(vx));
|
||||
//
|
||||
// vec2 wx = safenorm(vx);
|
||||
//
|
||||
// vec2 wp = vec2(-wn.y, wn.x);
|
||||
//
|
||||
// if(dot(wp, vx) < 0)
|
||||
// {
|
||||
// wp = -wp;
|
||||
// }
|
||||
//
|
||||
// vec2 wc = safenorm(mix(wp, wx, clamp((vx_length - 0.5) / 1.5, 0, 1)));
|
||||
//
|
||||
// float weight = 0;// params.motion_blur_samples / (40 * vx_length);
|
||||
//
|
||||
// vec4 sum = col_x * weight;
|
||||
//
|
||||
// float j = interleaved_gradient_noise(uvi) - 0.5;
|
||||
//
|
||||
// int vnvx = 2;//int(vn_length / (10 + vx_length)) + 2;
|
||||
//
|
||||
// float total_back_weight = 1e-10;
|
||||
//
|
||||
// vec4 back_sum = col_x * total_back_weight;
|
||||
//
|
||||
// for(int i = 0; i < params.motion_blur_samples; i++)
|
||||
// {
|
||||
// float t = mix(-1., 0.0, (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
//
|
||||
// float T = abs(t * vn_length);
|
||||
//
|
||||
// float Tx = abs((t + 0.5) * vn_length);
|
||||
//
|
||||
// bool sample_main_v = !(((i - 1) % vnvx) == 0);
|
||||
//
|
||||
// vec2 d = vn;//sample_main_v ? vn : vx;
|
||||
//
|
||||
// vec2 nai_d = vx;
|
||||
//
|
||||
// vec2 nai_wd = safenorm(nai_d);
|
||||
//
|
||||
// float nai_dz = vxz.z;
|
||||
//
|
||||
// vec2 past_nai_d = past_vx;
|
||||
//
|
||||
// float dz = vnz.z;//sample_main_v ? vnz.z : vxz.z;
|
||||
//
|
||||
// vec2 wd = safenorm(d);
|
||||
//
|
||||
// vec2 y = x + (d / render_size) * t;
|
||||
//
|
||||
// vec2 nai_y = x + (nai_d / render_size) * t;
|
||||
//
|
||||
// vec2 past_nai_y = x + (past_nai_d / render_size) * t;
|
||||
//
|
||||
// float nai_y_length = max(0.5, length(nai_y));
|
||||
//
|
||||
// vec2 vy = textureLod(vector_sampler, y, 0.0).xy * render_size;// * 2;
|
||||
//
|
||||
// float vy_length = max(0.5, length(vy));
|
||||
//
|
||||
// vec2 nai_vy = textureLod(vector_sampler, nai_y, 0.0).xy * render_size;
|
||||
//
|
||||
// float nai_vy_length = max(0.5, length(nai_vy));
|
||||
//
|
||||
// float zy = -0.05 / max(FLT_MIN, textureLod(depth_sampler, y, 0.0).x - dz * t);
|
||||
//
|
||||
// float nai_zy = -0.05 / max(FLT_MIN, textureLod(depth_sampler, nai_y, 0.0).x - nai_dz * t);
|
||||
//
|
||||
// float f = z_compare(zy, zx, 15);
|
||||
// float b = z_compare(zx, zy, 15);
|
||||
//
|
||||
// float wa = abs(max(0, dot(vy / vy_length, wd)));
|
||||
//
|
||||
// float wb = abs((dot(wc, wd)));
|
||||
//
|
||||
// float cone_x = cone(T, vx_length);
|
||||
//
|
||||
// float cone_y = cone(T, vy_length);
|
||||
//
|
||||
// float nai_f = z_compare(nai_zy, zx, 15);
|
||||
//
|
||||
// float nai_b = z_compare(zx, nai_zy, 15);
|
||||
//
|
||||
// float nai_wa = abs(max(0, dot(nai_vy / nai_vy_length, nai_wd)));
|
||||
//
|
||||
// float nai_wb = abs((dot(wc, nai_wd)));
|
||||
//
|
||||
// float nai_cone_y = cone(T, nai_vy_length);
|
||||
//
|
||||
// float ay_trail = f * wa * step(FLT_MIN, cone_y);
|
||||
//
|
||||
// float ay_lead = (1 - f) * wb * step(FLT_MIN, cone_x);
|
||||
//
|
||||
// float nai_ay = nai_b;//max(nai_b, nai_f * nai_wa * step(FLT_MIN, nai_cone_y));
|
||||
//
|
||||
// vec4 col_y = textureLod(color_sampler, y, 0.0);
|
||||
//
|
||||
// vec4 past_col_y = textureLod(past_color_sampler, past_nai_y, 0.0);
|
||||
//
|
||||
// vec4 nai_col_y = textureLod(color_sampler, nai_y, 0.0);
|
||||
//
|
||||
// vec4 col_back = nai_col_y;
|
||||
//
|
||||
// total_back_weight += nai_ay;
|
||||
//
|
||||
// back_sum += col_back * nai_ay;
|
||||
//
|
||||
// weight += ay_trail + ay_lead;
|
||||
//
|
||||
// sum += col_y * ay_trail + past_col_y * ay_lead;
|
||||
// }
|
||||
//
|
||||
// back_sum *= (params.motion_blur_samples - weight) / total_back_weight;
|
||||
//
|
||||
// sum /= params.motion_blur_samples;
|
||||
//
|
||||
// back_sum /= params.motion_blur_samples;
|
||||
//
|
||||
// imageStore(output_image, uvi, sum + back_sum);
|
||||
//
|
||||
//#ifdef DEBUG
|
||||
// imageStore(debug_1_image, uvi, sum + back_sum);
|
||||
// imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
// imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
// imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
// imageStore(debug_5_image, uvi, col_x);//sum + back_sum);
|
||||
// imageStore(debug_6_image, uvi, past_col_x);
|
||||
// imageStore(debug_7_image, uvi, past_col_x);
|
||||
// imageStore(debug_8_image, uvi, abs(vec4(past_vx / render_size * 10, past_vxz.z * 100, 1)));
|
||||
//#endif
|
||||
//}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://4vnw7nqk2lmb"
|
||||
path="res://.godot/imported/jump_flood_past_experimental_blur.glsl-75b0138dd1cf1e624e753e1e20d4e672.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/Archive/jump_flood_past_experimental_blur.glsl"
|
||||
dest_files=["res://.godot/imported/jump_flood_past_experimental_blur.glsl-75b0138dd1cf1e624e753e1e20d4e672.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D velocity_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D tile_max_x;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(velocity_sampler, 0));
|
||||
ivec2 output_size = imageSize(tile_max_x);
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
int tile_size = render_size.x / output_size.x;
|
||||
ivec2 global_uvi = uvi * ivec2(tile_size, 1);
|
||||
if ((uvi.x >= output_size.x) || (uvi.y >= output_size.y) || (global_uvi.x >= render_size.x) || (global_uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(global_uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec4 max_velocity = vec4(0);
|
||||
|
||||
float max_velocity_length = -1;
|
||||
|
||||
//bool foreground = false;
|
||||
|
||||
for(int i = 0; i < tile_size; i++)
|
||||
{
|
||||
vec2 current_uv = uvn + vec2(float(i) / render_size.x, 0);
|
||||
vec4 velocity_sample = textureLod(velocity_sampler, current_uv, 0.0);
|
||||
float current_velocity_length = dot(velocity_sample.xy, velocity_sample.xy);
|
||||
if(current_velocity_length > max_velocity_length)// || (velocity_sample.w > 0 && !foreground))
|
||||
{
|
||||
max_velocity_length = current_velocity_length;
|
||||
max_velocity = vec4(velocity_sample);
|
||||
// if(velocity_sample.w > 0)
|
||||
// {
|
||||
// foreground = true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
imageStore(tile_max_x, uvi, max_velocity);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://djp3da364fk2l"
|
||||
path="res://.godot/imported/jf_guertin_tile_max_x.glsl-acb187dfb7304d498ecdfb75a54c725d.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jf_guertin_tile_max_x.glsl"
|
||||
dest_files=["res://.godot/imported/jf_guertin_tile_max_x.glsl-acb187dfb7304d498ecdfb75a54c725d.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max_x;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D tile_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max_x, 0));
|
||||
ivec2 output_size = imageSize(tile_max);
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
int tile_size = render_size.y / output_size.y;
|
||||
ivec2 global_uvi = uvi * ivec2(1, tile_size);
|
||||
if ((uvi.x >= output_size.x) || (uvi.y >= output_size.y) || (global_uvi.x >= render_size.x) || (global_uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(global_uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec4 max_velocity = vec4(0);
|
||||
|
||||
float max_velocity_length = -1;
|
||||
|
||||
//bool foreground = false;
|
||||
|
||||
for(int i = 0; i < tile_size; i++)
|
||||
{
|
||||
vec2 current_uv = uvn + vec2(0, float(i) / render_size.y);
|
||||
vec4 velocity_sample = textureLod(tile_max_x, current_uv, 0.0);
|
||||
float current_velocity_length = dot(velocity_sample.xy, velocity_sample.xy);
|
||||
if(current_velocity_length > max_velocity_length)// || (velocity_sample.w > 0 && !foreground))
|
||||
{
|
||||
max_velocity_length = current_velocity_length;
|
||||
max_velocity = vec4(velocity_sample);
|
||||
// if(velocity_sample.w > 0)
|
||||
// {
|
||||
// foreground = true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
imageStore(tile_max, uvi, max_velocity);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://cqlltc8f21wre"
|
||||
path="res://.godot/imported/jf_guertin_tile_max_y.glsl-8b893536de27f9161f4a8be7b8c5058f.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jf_guertin_tile_max_y.glsl"
|
||||
dest_files=["res://.godot/imported/jf_guertin_tile_max_y.glsl-8b893536de27f9161f4a8be7b8c5058f.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max;
|
||||
layout(set = 0, binding = 1) uniform sampler2D tile_max_map;
|
||||
layout(rgba16f, set = 0, binding = 2) uniform writeonly image2D neighbor_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 best_sample_uv = vec2(uvn);
|
||||
|
||||
float max_neighbor_velocity_length = -1;
|
||||
|
||||
for(int i = -1; i < 2; i++)
|
||||
{
|
||||
for(int j = -1; j < 2; j++)
|
||||
{
|
||||
vec2 current_offset = vec2(1) / vec2(render_size) * vec2(i, j);
|
||||
vec2 current_uv = uvn + current_offset;
|
||||
if(current_uv.x < 0 || current_uv.x > 1 || current_uv.y < 0 || current_uv.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vec2 velocity_map_sample = textureLod(tile_max_map, current_uv, 0.0).xy;
|
||||
|
||||
vec4 velocity_sample = textureLod(tile_max, velocity_map_sample, 0.0);
|
||||
|
||||
float current_velocity_length = dot(velocity_sample.xy, velocity_sample.xy);
|
||||
|
||||
if(current_velocity_length > max_neighbor_velocity_length)
|
||||
{
|
||||
max_neighbor_velocity_length = current_velocity_length;
|
||||
best_sample_uv = velocity_map_sample;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imageStore(neighbor_max, uvi, vec4(best_sample_uv, 0, 1));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://cfk5chwlcyay4"
|
||||
path="res://.godot/imported/jf_neighbor_max.glsl-d9e677fd383d0688a8ad642473870160.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jf_neighbor_max.glsl"
|
||||
dest_files=["res://.godot/imported/jf_neighbor_max.glsl-d9e677fd383d0688a8ad642473870160.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,283 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D depth_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D velocity_sampler;
|
||||
layout(rgba16f, set = 0, binding = 2) uniform writeonly image2D buffer_a;
|
||||
layout(rgba16f, set = 0, binding = 3) uniform writeonly image2D buffer_b;
|
||||
layout(set = 0, binding = 4) uniform sampler2D buffer_a_sampler;
|
||||
layout(set = 0, binding = 5) uniform sampler2D buffer_b_sampler;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
int iteration_index;
|
||||
int last_iteration_index;
|
||||
int backtracking_sample_count;
|
||||
int nan2;
|
||||
float perpen_error_thresh;
|
||||
float sample_step_multiplier;
|
||||
float motion_blur_intensity;
|
||||
float velocity_match_threshold;
|
||||
float parallel_sensitivity;
|
||||
float perpendicular_sensitivity;
|
||||
float depth_match_threshold;
|
||||
float step_exponent_modifier;
|
||||
float step_size;
|
||||
float max_dilation_radius;
|
||||
float nan_fl_1;
|
||||
float nan_fl_2;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
const int kernel_size = 8;
|
||||
|
||||
const vec2 check_step_kernel[kernel_size] = {
|
||||
vec2(-1, 0),
|
||||
vec2(1, 0),
|
||||
vec2(0, -1),
|
||||
vec2(0, 1),
|
||||
vec2(-1, 1),
|
||||
vec2(1, -1),
|
||||
vec2(1, 1),
|
||||
vec2(-1, -1),
|
||||
};
|
||||
|
||||
void get_value(bool a,inout vec2 uv)
|
||||
{
|
||||
if(a)
|
||||
{
|
||||
uv = textureLod(buffer_a_sampler, uv, 0.0).xy;
|
||||
}
|
||||
else
|
||||
{
|
||||
uv = textureLod(buffer_b_sampler, uv, 0.0).xy;
|
||||
}
|
||||
}
|
||||
|
||||
void set_value(bool a, ivec2 uvi, vec4 value)
|
||||
{
|
||||
if(a)
|
||||
{
|
||||
imageStore(buffer_a, uvi, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageStore(buffer_b, uvi, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Motion similarity
|
||||
// ----------------------------------------------------------
|
||||
float get_motion_difference(vec2 V, vec2 V2)
|
||||
{
|
||||
return clamp(dot(V - V2, V) / dot(V, V), 0, 1);
|
||||
// vec2 VO = V - V2;
|
||||
// float parallel = dot(VO, V) / dot(V, V);
|
||||
// return clamp(parallel, 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
void sample_fitness(vec2 uv_offset, vec4 uv_sample, vec2 render_size, inout vec4 curren_sample_fitness)
|
||||
{
|
||||
vec2 sample_velocity = -uv_sample.xy;
|
||||
|
||||
// if velocity is 0, we never reach it (steps never smaller than 1)
|
||||
if (dot(sample_velocity, sample_velocity) <= FLT_MIN || uv_sample.w == 0)
|
||||
{
|
||||
curren_sample_fitness = vec4(FLT_MAX, FLT_MAX, FLT_MAX, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// velocity space distance (projected pixel offset onto velocity vector)
|
||||
float velocity_space_distance = dot(sample_velocity, uv_offset) / dot(sample_velocity, sample_velocity);
|
||||
// the velcity space distance to gravitate the JFA to (found more relieable than doing a 0 - 1 range)
|
||||
float mid_point = params.motion_blur_intensity / 2;
|
||||
// centralize the velocity space distance around that mid point
|
||||
float absolute_velocity_space_distance = abs(velocity_space_distance - mid_point);
|
||||
// if that distance is half the original, its within range (we centered around a mid point)
|
||||
float within_velocity_range = step(absolute_velocity_space_distance, mid_point);
|
||||
// perpendicular offset
|
||||
float side_offset = abs(dot(vec2(uv_offset.y, -uv_offset.x), sample_velocity)) / dot(sample_velocity, sample_velocity);
|
||||
// arbitrary perpendicular limit (lower means tighter dilation, but less reliable)
|
||||
float within_perpen_error_range = step(side_offset, params.perpen_error_thresh * params.motion_blur_intensity);
|
||||
// store relevant data for use in conditions
|
||||
curren_sample_fitness = vec4(absolute_velocity_space_distance, velocity_space_distance, uv_sample.w + uv_sample.z * velocity_space_distance, within_velocity_range * within_perpen_error_range);
|
||||
}
|
||||
|
||||
float is_sample_better(vec4 a, vec4 b)
|
||||
{
|
||||
// see explanation at end of code
|
||||
return mix(1. - step(b.x * a.w, a.x * b.w), step(b.z, a.z), step(0.5, b.w) * step(0.5, a.w));
|
||||
}
|
||||
|
||||
// dilation validation and better sample selection
|
||||
vec4 get_backtracked_sample(vec2 uvn, vec2 chosen_uv, vec3 chosen_velocity, vec4 best_sample_fitness, vec2 render_size)
|
||||
{
|
||||
//return vec4(chosen_uv, best_sample_fitness.z, best_sample_fitness.w);// comment this to enable backtracking
|
||||
|
||||
float smallest_step = 1 / max(render_size.x, render_size.y);
|
||||
// choose maximum range to check along (matches with implementation in blur stage)
|
||||
float general_velocity_multiplier = min(best_sample_fitness.y, params.max_dilation_radius * smallest_step / (length(chosen_velocity) * params.motion_blur_intensity));
|
||||
|
||||
vec2 best_uv = chosen_uv;
|
||||
|
||||
float best_multiplier = best_sample_fitness.y;
|
||||
|
||||
float best_depth = best_sample_fitness.z;
|
||||
|
||||
// set temp variable to keet track of better matches
|
||||
float smallest_velocity_difference = 0.99;//params.velocity_match_threshold;
|
||||
// minimum amount of valid velocities to compare before decision
|
||||
int initial_steps_to_compare = 2;
|
||||
|
||||
int steps_to_compare = initial_steps_to_compare;
|
||||
|
||||
float velocity_multiplier;
|
||||
|
||||
vec2 check_uv;
|
||||
|
||||
vec3 velocity_test;
|
||||
|
||||
float depth_test;
|
||||
|
||||
float velocity_difference;
|
||||
|
||||
float current_depth;
|
||||
|
||||
for(int i = -params.backtracking_sample_count; i < params.backtracking_sample_count + 1; i++)
|
||||
{
|
||||
velocity_multiplier = general_velocity_multiplier * (1 + float(i) / float(params.backtracking_sample_count));
|
||||
|
||||
if(velocity_multiplier > params.motion_blur_intensity || velocity_multiplier < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
check_uv = uvn - chosen_velocity.xy * velocity_multiplier;
|
||||
|
||||
if(any(notEqual(check_uv, clamp(check_uv, vec2(0.0), vec2(1.0)))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// get potential velocity and depth matches
|
||||
velocity_test = textureLod(velocity_sampler, check_uv, 0.0).xyz;
|
||||
|
||||
depth_test = textureLod(depth_sampler, check_uv, 0.0).x;
|
||||
|
||||
velocity_difference = get_motion_difference(chosen_velocity.xy, velocity_test.xy);
|
||||
|
||||
current_depth = depth_test + chosen_velocity.z * velocity_multiplier;
|
||||
|
||||
// if checked sample matches depth and velocity, it is valid for backtracking
|
||||
if((abs(current_depth - best_sample_fitness.z) < 0.002) && (velocity_difference <= smallest_velocity_difference))
|
||||
{
|
||||
best_uv = check_uv;
|
||||
best_multiplier = velocity_multiplier;
|
||||
best_depth = current_depth;
|
||||
if(steps_to_compare == 0)
|
||||
{
|
||||
return vec4(best_uv, best_depth, 0);
|
||||
}
|
||||
steps_to_compare--;
|
||||
}
|
||||
// if a sample was found and we lost footing after, go with that found sample right away
|
||||
else if(initial_steps_to_compare > steps_to_compare)
|
||||
{
|
||||
return vec4(best_uv, best_depth, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return vec4(uvn, best_sample_fitness.z, 1);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(velocity_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// must be on pixel center for whole values
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 uv_step = vec2(round(params.step_size)) / render_size;
|
||||
|
||||
vec4 best_sample_fitness = vec4(FLT_MAX, FLT_MAX, FLT_MAX, 0.);
|
||||
|
||||
vec2 chosen_uv = uvn;
|
||||
|
||||
vec3 chosen_velocity = vec3(0.);
|
||||
|
||||
bool set_a = !bool(step(0.5, float(params.iteration_index % 2)));
|
||||
|
||||
vec2 step_offset;
|
||||
|
||||
vec2 check_uv;
|
||||
|
||||
vec4 uv_sample;
|
||||
|
||||
vec4 current_sample_fitness;
|
||||
|
||||
for(int i = 0; i < kernel_size; i++)
|
||||
{
|
||||
step_offset = check_step_kernel[i] * uv_step;
|
||||
check_uv = uvn + step_offset;
|
||||
|
||||
if(any(notEqual(check_uv, clamp(check_uv, vec2(0.0), vec2(1.0)))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(params.iteration_index > 0.)
|
||||
{
|
||||
get_value(!set_a, check_uv);
|
||||
|
||||
step_offset = check_uv - uvn;
|
||||
}
|
||||
|
||||
uv_sample = vec4(textureLod(velocity_sampler, check_uv, 0.0).xyz, textureLod(depth_sampler, check_uv, 0.0).x);
|
||||
|
||||
sample_fitness(step_offset, uv_sample, render_size, current_sample_fitness);
|
||||
|
||||
if (mix(1. - step(best_sample_fitness.x * current_sample_fitness.w, current_sample_fitness.x * best_sample_fitness.w), step(best_sample_fitness.z, current_sample_fitness.z), step(0.5, best_sample_fitness.w) * step(0.5, current_sample_fitness.w)) > 0.5)//is_sample_better(current_sample_fitness, best_sample_fitness) > 0.5)
|
||||
{
|
||||
best_sample_fitness = current_sample_fitness;
|
||||
chosen_uv = check_uv;
|
||||
chosen_velocity = uv_sample.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
if(params.iteration_index < params.last_iteration_index)
|
||||
{
|
||||
set_value(set_a, uvi, vec4(chosen_uv, 0, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
float depth = textureLod(depth_sampler, uvn, 0.0).x;
|
||||
|
||||
// best_sample_fitness.z contains the depth of the texture + offset of velocity z
|
||||
vec4 backtracked_sample = get_backtracked_sample(uvn, chosen_uv, chosen_velocity, best_sample_fitness, render_size);
|
||||
|
||||
if(best_sample_fitness.w == 0 || depth > backtracked_sample.z)
|
||||
{
|
||||
set_value(set_a, uvi, vec4(uvn, 0, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
set_value(set_a, uvi, backtracked_sample);
|
||||
|
||||
return;
|
||||
}
|
||||
//
|
||||
// if((a.w == b.w) && (a.w == 1))
|
||||
// {
|
||||
// return a.z < b.z ? 0. : 1.;
|
||||
// }
|
||||
//
|
||||
// return a.x * b.w < b.x * a.w ? 1. : 0.;
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://rkkajixdjosk"
|
||||
path="res://.godot/imported/jfp_backtracking_experimental.glsl-a7a47621c3999d6edb8c655271f824d5.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jfp_backtracking_experimental.glsl"
|
||||
dest_files=["res://.godot/imported/jfp_backtracking_experimental.glsl-a7a47621c3999d6edb8c655271f824d5.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D buffer_a;
|
||||
layout(rgba16f, set = 0, binding = 2) uniform writeonly image2D buffer_b;
|
||||
layout(set = 0, binding = 3) uniform sampler2D buffer_a_sampler;
|
||||
layout(set = 0, binding = 4) uniform sampler2D buffer_b_sampler;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
int iteration_index;
|
||||
int last_iteration_index;
|
||||
int nan1;
|
||||
int nan2;
|
||||
float perpen_error_thresh;
|
||||
float sample_step_multiplier;
|
||||
float motion_blur_intensity;
|
||||
float nan_fl_5;
|
||||
float nan_fl_4;
|
||||
float nan_fl_3;
|
||||
float nan_fl_6;
|
||||
float step_exponent_modifier;
|
||||
float nan_fl_0;
|
||||
float max_dilation_radius;
|
||||
float nan_fl_1;
|
||||
float nan_fl_2;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
const int kernel_size = 8;
|
||||
|
||||
const vec2 check_step_kernel[kernel_size] = {
|
||||
vec2(-1, 0),
|
||||
vec2(1, 0),
|
||||
vec2(0, -1),
|
||||
vec2(0, 1),
|
||||
vec2(-1, 1),
|
||||
vec2(1, -1),
|
||||
vec2(1, 1),
|
||||
vec2(-1, -1),
|
||||
};
|
||||
|
||||
vec2 get_value(bool a, vec2 uv)
|
||||
{
|
||||
if(a)
|
||||
{
|
||||
return textureLod(buffer_a_sampler, uv, 0.0).xy;
|
||||
}
|
||||
else
|
||||
{
|
||||
return textureLod(buffer_b_sampler, uv, 0.0).xy;
|
||||
}
|
||||
}
|
||||
|
||||
void set_value(bool a, ivec2 uvi, vec4 value)
|
||||
{
|
||||
if(a)
|
||||
{
|
||||
imageStore(buffer_a, uvi, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageStore(buffer_b, uvi, value);
|
||||
}
|
||||
}
|
||||
|
||||
void sample_fitness(vec2 uv_offset, vec4 uv_sample, vec2 render_size, inout vec4 current_sample_fitness)
|
||||
{
|
||||
vec2 sample_velocity = -uv_sample.xy;
|
||||
|
||||
if (dot(sample_velocity, sample_velocity) <= FLT_MIN || uv_sample.w == 0)
|
||||
{
|
||||
current_sample_fitness = vec4(10, 10, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
float velocity_space_distance = dot(sample_velocity, uv_offset) / dot(sample_velocity, sample_velocity);
|
||||
|
||||
float mid_point = params.motion_blur_intensity / 2;
|
||||
|
||||
float absolute_velocity_space_distance = abs(velocity_space_distance - mid_point);
|
||||
|
||||
float within_velocity_range = step(absolute_velocity_space_distance, mid_point);
|
||||
|
||||
float side_offset = abs(dot(vec2(uv_offset.y, -uv_offset.x), sample_velocity)) / dot(sample_velocity, sample_velocity);
|
||||
|
||||
float within_perpen_error_range = step(side_offset, params.perpen_error_thresh * params.motion_blur_intensity);
|
||||
|
||||
current_sample_fitness = vec4(absolute_velocity_space_distance, velocity_space_distance, uv_sample.w + uv_sample.z * velocity_space_distance, within_velocity_range * within_perpen_error_range);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 step_size = vec2(round(pow(2 + params.step_exponent_modifier, params.last_iteration_index - params.iteration_index)));
|
||||
|
||||
vec2 uv_step = vec2(round(step_size)) / render_size;
|
||||
|
||||
vec4 best_sample_fitness = vec4(10, 10, 0, 0);
|
||||
|
||||
vec2 chosen_uv = uvn;
|
||||
|
||||
bool set_a = !bool(step(0.5, float(params.iteration_index % 2)));
|
||||
|
||||
vec2 step_offset;
|
||||
|
||||
vec2 check_uv;
|
||||
|
||||
vec4 uv_sample;
|
||||
|
||||
vec4 current_sample_fitness;
|
||||
|
||||
for(int i = 0; i < kernel_size; i++)
|
||||
{
|
||||
step_offset = check_step_kernel[i] * uv_step;
|
||||
check_uv = uvn + step_offset;
|
||||
|
||||
if(any(notEqual(check_uv, clamp(check_uv, vec2(0.0), vec2(1.0)))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
check_uv = get_value(!set_a, check_uv).xy;
|
||||
|
||||
step_offset = check_uv - uvn;
|
||||
|
||||
uv_sample = textureLod(tile_max_sampler, check_uv, 0.0);
|
||||
|
||||
sample_fitness(step_offset, uv_sample, render_size, current_sample_fitness);
|
||||
|
||||
float sample_better = 1. - step(current_sample_fitness.z * current_sample_fitness.w, best_sample_fitness.z * best_sample_fitness.w);
|
||||
best_sample_fitness = mix(best_sample_fitness, current_sample_fitness, sample_better);
|
||||
chosen_uv = mix(chosen_uv, check_uv, sample_better);
|
||||
}
|
||||
|
||||
set_value(set_a, uvi, vec4(chosen_uv, 0, 0));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://c4dywnp7k8rph"
|
||||
path="res://.godot/imported/jfp_simple.glsl-96987ba8c42947c7e648d28f42a73f7a.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jfp_simple.glsl"
|
||||
dest_files=["res://.godot/imported/jfp_simple.glsl-96987ba8c42947c7e648d28f42a73f7a.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define DBL_MAX 1.7976931348623158e+308
|
||||
#define DBL_MIN 2.2250738585072014e-308
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D depth_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D vector_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D velocity_map;
|
||||
layout(rgba16f, set = 0, binding = 4) uniform writeonly image2D output_image;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float motion_blur_samples;
|
||||
float motion_blur_intensity;
|
||||
float motion_blur_center_fade;
|
||||
float frame;
|
||||
float last_iteration_index;
|
||||
float sample_step_multiplier;
|
||||
float step_exponent_modifier;
|
||||
float max_dilation_radius;
|
||||
int nan0;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// near plane distance
|
||||
float npd = 0.05;
|
||||
|
||||
// SOFT_Z_EXTENT
|
||||
float sze = 0.1;
|
||||
|
||||
// Helper functions
|
||||
// --------------------------------------------
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
float interleaved_gradient_noise(vec2 uv, int FrameId){
|
||||
uv += float(FrameId) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
float get_motion_difference(vec2 V, vec2 V2, float power)
|
||||
{
|
||||
vec2 VO = V - V2;
|
||||
float difference = dot(VO, V) / max(FLT_MIN, dot(V, V));
|
||||
return pow(clamp(difference, 0, 1), power);
|
||||
}
|
||||
// McGuire's function https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
float soft_depth_compare(float depth_X, float depth_Y)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
// -------------------------------------------------------
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// must be on pixel center for whole values (tested)
|
||||
vec2 uvn = vec2(uvi + vec2(0.5)) / render_size;
|
||||
|
||||
vec4 base_color = textureLod(color_sampler, uvn, 0.0);
|
||||
// get dominant velocity data
|
||||
vec4 velocity_map_sample = textureLod(velocity_map, uvn, 0.0);
|
||||
|
||||
vec3 dominant_velocity = -textureLod(vector_sampler, velocity_map_sample.xy, 0.0).xyz;
|
||||
|
||||
vec3 naive_velocity = -textureLod(vector_sampler, uvn, 0.0).xyz;
|
||||
// if velocity is 0 and we dont show debug, return right away.
|
||||
if ((dot(dominant_velocity, dominant_velocity) == 0 || params.motion_blur_intensity == 0))
|
||||
{
|
||||
imageStore(output_image, uvi, base_color);
|
||||
return;
|
||||
}
|
||||
// offset along velocity to blend between sample steps
|
||||
float noise_offset = interleaved_gradient_noise(uvi, int(params.frame)) - 1;
|
||||
// scale of step
|
||||
float velocity_step_coef = min(params.motion_blur_intensity, params.max_dilation_radius / max(render_size.x, render_size.y) / (length(dominant_velocity) * params.motion_blur_intensity)) / max(1.0, params.motion_blur_samples - 1.0);
|
||||
|
||||
vec3 step_sample = dominant_velocity * velocity_step_coef;
|
||||
|
||||
vec3 naive_step_sample = naive_velocity * velocity_step_coef;
|
||||
|
||||
vec4 velocity_map_step_sample = vec4(0);
|
||||
|
||||
//float d = 1.0 - min(1.0, 2.0 * distance(uvn, vec2(0.5)));
|
||||
//sample_step *= 1.0 - d * params.fade_padding.x;
|
||||
|
||||
float total_weight = 1;
|
||||
|
||||
vec3 dominant_offset = step_sample * noise_offset;
|
||||
|
||||
vec3 naive_offset = naive_step_sample * noise_offset;
|
||||
|
||||
vec3 dominant_back_offset = -step_sample * (1. - noise_offset);
|
||||
|
||||
vec4 col = base_color * total_weight;
|
||||
|
||||
float naive_depth = textureLod(depth_sampler, uvn, 0.0).x;
|
||||
|
||||
float backstepping_coef = clamp(length(dominant_velocity) / 0.05, 0, 1);
|
||||
|
||||
vec2 dominant_uvo;
|
||||
|
||||
vec2 naive_uvo;
|
||||
|
||||
vec3 current_dominant_offset;
|
||||
|
||||
float current_naive_depth;
|
||||
|
||||
float foreground;
|
||||
|
||||
vec3 current_dominant_velocity;
|
||||
|
||||
float motion_difference;
|
||||
|
||||
float sample_weight;
|
||||
|
||||
float dominant_naive_mix;
|
||||
|
||||
vec2 sample_uv;
|
||||
|
||||
for (int i = 1; i < params.motion_blur_samples; i++)
|
||||
{
|
||||
dominant_offset += step_sample;
|
||||
|
||||
naive_offset += naive_step_sample;
|
||||
|
||||
dominant_uvo = uvn + dominant_offset.xy;
|
||||
|
||||
naive_uvo = uvn + naive_offset.xy;
|
||||
|
||||
current_dominant_offset = dominant_offset;
|
||||
|
||||
current_naive_depth = textureLod(depth_sampler, dominant_uvo, 0.0).x;
|
||||
// is current depth closer than origin of dilation (stepped into a foreground object)
|
||||
foreground = step(naive_depth + current_dominant_offset.z, current_naive_depth - 0.0001);
|
||||
|
||||
velocity_map_step_sample = textureLod(velocity_map, dominant_uvo, 0.0);
|
||||
|
||||
current_dominant_velocity = -textureLod(vector_sampler, velocity_map_step_sample.xy, 0.0).xyz;
|
||||
|
||||
motion_difference = get_motion_difference(dominant_velocity.xy, current_dominant_velocity.xy, 0.1);
|
||||
|
||||
sample_weight = 1;
|
||||
|
||||
if (any(notEqual(dominant_uvo, clamp(dominant_uvo, vec2(0.0), vec2(1.0)))) || foreground * motion_difference > 0.5)
|
||||
{
|
||||
dominant_uvo = uvn + dominant_back_offset.xy;
|
||||
current_dominant_offset = dominant_back_offset;
|
||||
dominant_back_offset -= step_sample;
|
||||
sample_weight = 0.5;//backstepping_coef;
|
||||
}
|
||||
|
||||
velocity_map_step_sample = textureLod(velocity_map, dominant_uvo, 0.0);
|
||||
|
||||
current_dominant_velocity = -textureLod(vector_sampler, velocity_map_step_sample.xy, 0.0).xyz;
|
||||
// is current velocity different than dilated velocity
|
||||
|
||||
current_naive_depth = textureLod(depth_sampler, dominant_uvo, 0.0).x;
|
||||
// is current depth closer than origin of dilation (stepped into a foreground object)
|
||||
foreground = step(naive_depth + current_dominant_offset.z, current_naive_depth - 0.002);
|
||||
|
||||
motion_difference = get_motion_difference(dominant_velocity.xy, current_dominant_velocity.xy, 0.1);
|
||||
// if we are sampling a foreground object and its velocity is different, discard this sample (prevent ghosting)
|
||||
sample_weight *= 1 - (foreground * motion_difference);
|
||||
|
||||
dominant_naive_mix = 1. - step(0.9, motion_difference);
|
||||
|
||||
sample_uv = mix(naive_uvo, dominant_uvo, dominant_naive_mix);
|
||||
|
||||
total_weight += sample_weight;
|
||||
|
||||
col += textureLod(color_sampler, sample_uv, 0.0) * sample_weight;
|
||||
}
|
||||
|
||||
col /= total_weight;
|
||||
|
||||
imageStore(output_image, uvi, col);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://c57nhlyxb4m1t"
|
||||
path="res://.godot/imported/jump_flood_blur.glsl-11f088c8cddfb4c62f32dfa84c694ded.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_blur.glsl"
|
||||
dest_files=["res://.godot/imported/jump_flood_blur.glsl-11f088c8cddfb4c62f32dfa84c694ded.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D color_sampler;
|
||||
layout(rgba16f, set = 0, binding = 2) uniform image2D past_velocity;
|
||||
layout(rgba16f, set = 0, binding = 3) uniform image2D past_color;
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float sze)
|
||||
{
|
||||
return clamp(1. - sze * (a - b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(velocity_sampler, 0));
|
||||
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uv.x >= render_size.x) || (uv.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uv) + 0.5) / render_size;
|
||||
|
||||
vec4 past_vx = textureLod(velocity_sampler, x, 0.0);
|
||||
|
||||
vec4 past_vx_vx = textureLod(velocity_sampler, x + past_vx.xy, 0.0);
|
||||
|
||||
vec4 past_col_vx = textureLod(color_sampler, x + past_vx.xy, 0.0);
|
||||
|
||||
vec4 past_col_x = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
float alpha = 1 - z_compare(-past_vx.w, -past_vx_vx.w, 20000);
|
||||
|
||||
vec4 final_past_col = mix(past_col_vx, past_col_x, alpha);
|
||||
|
||||
vec4 final_past_vx = mix(vec4(past_vx_vx.xyz, past_vx.w), past_vx, alpha);
|
||||
|
||||
imageStore(past_color, uv, final_past_col);
|
||||
imageStore(past_velocity, uv, final_past_vx);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://quuyr2q5w5kx"
|
||||
path="res://.godot/imported/jump_flood_cache.glsl-f4eae7ab471d126e0587a3e727d847f6.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_cache.glsl"
|
||||
dest_files=["res://.godot/imported/jump_flood_cache.glsl-f4eae7ab471d126e0587a3e727d847f6.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,316 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D velocity_map;
|
||||
layout(rgba16f, set = 0, binding = 4) uniform writeonly image2D output_image;
|
||||
layout(set = 0, binding = 5) uniform sampler2D tile_max;
|
||||
layout(set = 0, binding = 6) uniform sampler2D past_color_sampler;
|
||||
layout(set = 0, binding = 7) uniform sampler2D past_velocity_sampler;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float motion_blur_samples;
|
||||
float motion_blur_intensity;
|
||||
float motion_blur_center_fade;
|
||||
float frame;
|
||||
float last_iteration_index;
|
||||
float sample_step_multiplier;
|
||||
float step_exponent_modifier;
|
||||
float max_dilation_radius;
|
||||
int nan0;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - T / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, T);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float sze)
|
||||
{
|
||||
return clamp(1. - sze * (a - b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv){
|
||||
uv += float(params.frame) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://github.com/bradparks/KinoMotion__unity_motion_blur/tree/master
|
||||
// ----------------------------------------------------------
|
||||
vec2 safenorm(vec2 v)
|
||||
{
|
||||
float l = max(length(v), 1e-6);
|
||||
return v / l * int(l >= 0.5);
|
||||
}
|
||||
|
||||
vec2 jitter_tile(vec2 uvi)
|
||||
{
|
||||
float rx, ry;
|
||||
float angle = interleaved_gradient_noise(uvi + vec2(2, 0)) * M_PI * 2;
|
||||
rx = cos(angle);
|
||||
ry = sin(angle);
|
||||
return vec2(rx, ry) / textureSize(tile_max, 0) / 4;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
vec2 velocity_map_sample = textureLod(velocity_map, x + jitter_tile(uvi), 0.0).xy;
|
||||
|
||||
vec3 vnz = textureLod(tile_max, velocity_map_sample, 0.0).xyz * vec3(render_size, 1);
|
||||
|
||||
float vn_length = max(0.5, length(vnz.xy));
|
||||
|
||||
float multiplier = clamp(vn_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vn_length);
|
||||
|
||||
vnz.xyz *= multiplier;
|
||||
|
||||
vn_length *= multiplier;
|
||||
|
||||
vec2 vn = vnz.xy;
|
||||
|
||||
vec4 col_x = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
vec4 vxz = textureLod(velocity_sampler, x, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float vx_length = max(0.5, length(vxz.xy));
|
||||
|
||||
//multiplier = clamp(vx_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vx_length);
|
||||
|
||||
vxz.xyz *= multiplier;
|
||||
|
||||
vx_length *= multiplier;
|
||||
|
||||
vec2 vx = vxz.xy;
|
||||
|
||||
vec2 wx = safenorm(vx);
|
||||
|
||||
if(vn_length <= 0.5)
|
||||
{
|
||||
imageStore(output_image, uvi, col_x);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, col_x);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
vec3 wvnz = normalize(vnz.xyz);
|
||||
|
||||
float velocity_match = pow(clamp(dot(vx, vn) / dot(vn, vn), 0, 1), 1 / (10000 * pow(abs(vnz.z), 2)));
|
||||
|
||||
vn = mix(vn, vx, velocity_match);
|
||||
|
||||
vnz = mix(vnz, vxz.xyz, velocity_match);
|
||||
|
||||
vec2 wn = safenorm(vn);
|
||||
|
||||
float zx = vxz.w;
|
||||
|
||||
float j = interleaved_gradient_noise(uvi) - 0.5;
|
||||
|
||||
vec4 past_vxz = textureLod(past_velocity_sampler, x, 0.0) * vec4(render_size * multiplier, 1 * multiplier, 1);
|
||||
|
||||
vec2 past_vx = past_vxz.xy;
|
||||
|
||||
vec4 past_col_x = textureLod(past_color_sampler, x, 0.0);
|
||||
|
||||
float t;
|
||||
float back_t;
|
||||
float T;
|
||||
vec2 y;
|
||||
float y_inside;
|
||||
vec4 nai_vy;
|
||||
vec2 nai_y;
|
||||
vec2 nai_back_y;
|
||||
float nai_zy;
|
||||
float nai_b;
|
||||
float nai_ay;
|
||||
float nai_y_inside;
|
||||
vec4 vy;
|
||||
float vy_length;
|
||||
float zy;
|
||||
float f;
|
||||
float wa;
|
||||
float ay_trail;
|
||||
float past_t;
|
||||
vec2 past_y;
|
||||
vec2 past_back_y;
|
||||
float past_ay;
|
||||
float alpha;
|
||||
vec4 past_vy;
|
||||
float past_zy;
|
||||
float past_b;
|
||||
float past_y_inside;
|
||||
float nai_T;
|
||||
float nai_vy_length;
|
||||
float nai_wa;
|
||||
|
||||
float weight = 1e-5;
|
||||
|
||||
vec4 sum = col_x * weight;
|
||||
|
||||
float nai_weight = 1e-5;
|
||||
|
||||
float nai_sub_weight = 1e-5;
|
||||
|
||||
vec4 nai_sum = col_x * nai_sub_weight;
|
||||
|
||||
float past_weight = 1e-5;
|
||||
|
||||
float past_sub_weight = 1e-5;
|
||||
|
||||
vec4 past_sum = past_col_x * past_sub_weight;
|
||||
|
||||
float final_sample_count = params.motion_blur_samples + 1e-5;
|
||||
|
||||
for(int i = 0; i < params.motion_blur_samples; i++)
|
||||
{
|
||||
t = mix(0., -1., (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
back_t = mix(1, 0, (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
T = abs(t * vn_length);
|
||||
|
||||
y = x + (vn / render_size) * t;
|
||||
|
||||
nai_T = abs(t * vx_length);
|
||||
|
||||
nai_y = x + (vx / render_size) * t;
|
||||
|
||||
nai_back_y = x + (vx / render_size) * back_t;
|
||||
|
||||
nai_vy = textureLod(velocity_sampler, nai_y, 0.0) * vec4(render_size * multiplier, 1 * multiplier, 1);
|
||||
|
||||
nai_vy_length = max(0.5, length(nai_vy.xy));
|
||||
|
||||
nai_zy = nai_vy.w - vxz.z * t;
|
||||
|
||||
nai_b = z_compare(-zx, -nai_zy, 20000);
|
||||
|
||||
float nai_f = z_compare(-nai_zy, -zx, 20000);
|
||||
|
||||
nai_wa = abs(max(0, dot(nai_vy.xy / vy_length, wx)));
|
||||
|
||||
nai_ay = max(nai_b, 0);//step(nai_T, nai_vy_length * nai_wa));
|
||||
|
||||
nai_weight += 1;
|
||||
|
||||
nai_sub_weight += 1;
|
||||
|
||||
nai_y_inside = step(0, nai_y.x) * step(nai_y.x, 1) * step(0, nai_y.y) * step(nai_y.y, 1);
|
||||
|
||||
nai_sum += mix(textureLod(color_sampler, nai_back_y, 0.0), textureLod(color_sampler, nai_y, 0.0), nai_ay * nai_y_inside);
|
||||
|
||||
past_y = x + (past_vx / render_size) * t;
|
||||
|
||||
past_back_y = x + (past_vx / render_size) * back_t;
|
||||
|
||||
alpha = z_compare(-past_vxz.w, -vxz.w, 20000);
|
||||
|
||||
past_vy = textureLod(past_velocity_sampler, past_y, 0.0) * vec4(render_size * multiplier, 1 * multiplier, 1);
|
||||
|
||||
past_zy = past_vy.w - past_vxz.z * t;
|
||||
|
||||
past_b = z_compare(-past_vxz.w, -past_zy, 20000);
|
||||
|
||||
past_ay = (1 - step(nai_T, nai_vy_length * nai_wa)) * (1 - alpha);
|
||||
|
||||
past_weight += past_ay;
|
||||
|
||||
past_sub_weight += 1;
|
||||
|
||||
past_y_inside = step(0, past_y.x) * step(past_y.x, 1) * step(0, past_y.y) * step(past_y.y, 1);
|
||||
|
||||
past_sum += mix(textureLod(past_color_sampler, past_back_y, 0.0), textureLod(past_color_sampler, past_y, 0.0), past_b * past_y_inside);
|
||||
|
||||
vy = textureLod(velocity_sampler, y, 0.0) * vec4(render_size * multiplier, 1 * multiplier, 1);
|
||||
|
||||
vy_length = max(0.5, length(vy.xy));
|
||||
|
||||
zy = vy.w - vnz.z * t;
|
||||
|
||||
f = z_compare(-zy, -zx, 20000);
|
||||
|
||||
wa = abs(max(0, dot(vy.xy / vy_length, wn)));
|
||||
|
||||
ay_trail = f * step(T, vy_length * wa);
|
||||
|
||||
y_inside = step(0, y.x) * step(y.x, 1) * step(0, y.y) * step(y.y, 1);
|
||||
|
||||
weight += ay_trail * y_inside;
|
||||
|
||||
sum += textureLod(color_sampler, y, 0.0) * ay_trail * y_inside;
|
||||
}
|
||||
|
||||
sum /= weight;
|
||||
|
||||
weight /= final_sample_count;
|
||||
|
||||
nai_sum /= nai_sub_weight;
|
||||
|
||||
nai_weight /= final_sample_count;
|
||||
|
||||
past_sum /= past_sub_weight;
|
||||
|
||||
past_weight /= final_sample_count;
|
||||
|
||||
sum = mix(mix(nai_sum, past_sum, past_weight), sum, weight);
|
||||
|
||||
imageStore(output_image, uvi, sum);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, sum);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://bud4a7eh5sqr8"
|
||||
path="res://.godot/imported/jump_flood_experimental_blur.glsl-27880bed814a937f2189c48828ca161e.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_experimental_blur.glsl"
|
||||
dest_files=["res://.godot/imported/jump_flood_experimental_blur.glsl-27880bed814a937f2189c48828ca161e.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D blur_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform image2D color_image;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(blur_sampler, 0));
|
||||
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uv.x >= render_size.x) || (uv.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
imageStore(color_image, uv, textureLod(blur_sampler, (vec2(uv) + 0.5) / render_size, 0.0));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://dig08kpnfakuf"
|
||||
path="res://.godot/imported/jump_flood_overlay.glsl-fc28b3ae9a688e5da04536a5cdb7b76e.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_overlay.glsl"
|
||||
dest_files=["res://.godot/imported/jump_flood_overlay.glsl-fc28b3ae9a688e5da04536a5cdb7b76e.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,292 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D depth_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D velocity_map;
|
||||
layout(rgba16f, set = 0, binding = 4) uniform writeonly image2D output_image;
|
||||
layout(set = 0, binding = 5) uniform sampler2D tile_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float motion_blur_samples;
|
||||
float motion_blur_intensity;
|
||||
float motion_blur_center_fade;
|
||||
float frame;
|
||||
float last_iteration_index;
|
||||
float sample_step_multiplier;
|
||||
float step_exponent_modifier;
|
||||
float max_dilation_radius;
|
||||
int nan0;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - T / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, T);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float sze)
|
||||
{
|
||||
return clamp(1. - sze * (a - b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv){
|
||||
uv += float(params.frame) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://github.com/bradparks/KinoMotion__unity_motion_blur/tree/master
|
||||
// ----------------------------------------------------------
|
||||
vec2 safenorm(vec2 v)
|
||||
{
|
||||
float l = max(length(v), 1e-6);
|
||||
return v / l * int(l >= 0.5);
|
||||
}
|
||||
|
||||
vec2 jitter_tile(vec2 uvi)
|
||||
{
|
||||
float rx, ry;
|
||||
float angle = interleaved_gradient_noise(uvi + vec2(2, 0)) * M_PI * 2;
|
||||
rx = cos(angle);
|
||||
ry = sin(angle);
|
||||
return vec2(rx, ry) / textureSize(tile_max, 0) / 4;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
vec2 velocity_map_sample = textureLod(velocity_map, x + jitter_tile(uvi), 0.0).xy;
|
||||
|
||||
vec3 vnz = textureLod(tile_max, velocity_map_sample, 0.0).xyz * vec3(render_size, 1);
|
||||
|
||||
float vn_length = max(0.5, length(vnz.xy));
|
||||
|
||||
float multiplier = clamp(vn_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vn_length);
|
||||
|
||||
vnz.xyz *= multiplier;
|
||||
|
||||
vn_length *= multiplier;
|
||||
|
||||
vec2 vn = vnz.xy;
|
||||
|
||||
vec4 col_x = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
vec2 wn = safenorm(vn);
|
||||
|
||||
vec4 vxz = textureLod(velocity_sampler, x, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float vx_length = max(0.5, length(vxz.xy));
|
||||
|
||||
multiplier = clamp(vx_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vx_length);
|
||||
|
||||
vxz.xyz *= multiplier;
|
||||
|
||||
vx_length *= multiplier;
|
||||
|
||||
vec2 vx = vxz.xy;
|
||||
|
||||
if(vn_length <= 0.5)
|
||||
{
|
||||
imageStore(output_image, uvi, col_x);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, col_x);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
float velocity_match = pow(clamp(dot(vx, vn) / dot(vn, vn), 0, 1), 0.5);
|
||||
|
||||
vn = mix(vn, vx, velocity_match);
|
||||
|
||||
vnz = mix(vnz, vxz.xyz, velocity_match);
|
||||
|
||||
float zx = vxz.w;
|
||||
|
||||
vec2 wx = safenorm(vx);
|
||||
|
||||
float weight = 0;
|
||||
|
||||
vec4 sum = col_x * weight;
|
||||
|
||||
float total_back_weight = 1e-10;
|
||||
|
||||
vec4 back_sum = col_x * total_back_weight;
|
||||
|
||||
float j = interleaved_gradient_noise(uvi) - 0.5;
|
||||
|
||||
int back_amount = 0;
|
||||
|
||||
int nai_back_i = 1;
|
||||
|
||||
for(int i = 0; i < params.motion_blur_samples; i++)
|
||||
{
|
||||
float nai_t = mix(0., -1., (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
float nai_T = abs(nai_t * vx_length);
|
||||
|
||||
vec2 nai_y = x + (vx / render_size) * nai_t;
|
||||
|
||||
float nai_zy = textureLod(depth_sampler, nai_y, 0.0).x - vxz.z * nai_t;
|
||||
|
||||
float nai_b = z_compare(-zx, -nai_zy, 20000);
|
||||
|
||||
float nai_f = z_compare(-nai_zy, -zx, 20000);
|
||||
|
||||
vec4 nai_vy = textureLod(velocity_sampler, nai_y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float nai_vy_length = max(0.5, length(nai_vy.xy));
|
||||
|
||||
float nai_ay = nai_b;
|
||||
|
||||
float nai_wb = abs(max(0, dot(nai_vy.xy / nai_vy_length, wx)));
|
||||
|
||||
float nai_ay_f = nai_f * step(nai_T, nai_vy_length * nai_wb);
|
||||
|
||||
if(nai_y.x < 0 || nai_y.x > 1 || nai_y.y < 0 || nai_y.y > 1 || nai_ay + nai_ay_f <= 1e-5)
|
||||
{
|
||||
nai_t = mix(0., 1., (nai_back_i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
nai_T = abs(nai_t * vx_length);
|
||||
|
||||
nai_y = x + (vx / render_size) * nai_t;
|
||||
|
||||
nai_zy = textureLod(depth_sampler, nai_y, 0.0).x - vxz.z * nai_t;
|
||||
|
||||
nai_b = z_compare(-zx, -nai_zy, 20000);
|
||||
|
||||
nai_f = z_compare(-nai_zy, -zx, 20000);
|
||||
|
||||
nai_vy = textureLod(velocity_sampler, nai_y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
nai_vy_length = max(0.5, length(nai_vy.xy));
|
||||
|
||||
nai_ay = nai_b;
|
||||
|
||||
nai_wb = abs(max(0, dot(nai_vy.xy / nai_vy_length, wx)));
|
||||
|
||||
nai_ay_f = nai_f * step(nai_T, nai_vy_length * nai_wb);
|
||||
|
||||
nai_back_i++;
|
||||
}
|
||||
|
||||
vec4 nai_col_y = textureLod(color_sampler, nai_y, 0.0);
|
||||
|
||||
total_back_weight += nai_ay;
|
||||
|
||||
back_sum += nai_col_y * nai_ay;
|
||||
|
||||
float t = mix(0., -1., (i - back_amount + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
float T = abs(t * vn_length);
|
||||
|
||||
vec2 y = x + (vn / render_size) * t;
|
||||
|
||||
if(y.x < 0 || y.x > 1 || y.y < 0 || y.y > 1)
|
||||
{
|
||||
continue;
|
||||
// vn = -vn;
|
||||
// vnz = -vnz;
|
||||
// wn = -wn;
|
||||
// back_amount = i;
|
||||
}
|
||||
|
||||
vec4 vy = textureLod(velocity_sampler, y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float vy_length = max(0.5, length(vy.xy));
|
||||
|
||||
float zy = vy.w - vnz.z * t;
|
||||
|
||||
float f = z_compare(-zy, -zx, 20000);
|
||||
|
||||
float wa = abs(max(0, dot(vy.xy / vy_length, wn)));
|
||||
|
||||
float ay_trail = f * step(T, vy_length * wa);
|
||||
|
||||
vec4 col_y = textureLod(color_sampler, y, 0.0);
|
||||
|
||||
vec2 back_y = x + (vn / render_size) * -t;
|
||||
|
||||
vec4 back_vy = textureLod(velocity_sampler, back_y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float back_vy_length = max(0.5, length(back_vy.xy));
|
||||
|
||||
float back_zy = back_vy.w - vnz.z * -t;
|
||||
|
||||
float back_wa = abs(max(0, dot(back_vy.xy / back_vy_length, -wn)));
|
||||
|
||||
float back_f = z_compare(-back_zy, -zx, 20000);
|
||||
|
||||
float back_ay_trail = back_f * step(T, back_vy_length * back_wa);
|
||||
|
||||
vec4 back_col_y = textureLod(color_sampler, back_y, 0.0);
|
||||
|
||||
weight += back_ay_trail + (back_ay_trail > 0 ? 0 : ay_trail);
|
||||
|
||||
sum += back_col_y * back_ay_trail + (back_ay_trail > 0 ? vec4(0) : col_y * ay_trail);
|
||||
|
||||
|
||||
}
|
||||
|
||||
back_sum *= (params.motion_blur_samples - weight) / total_back_weight;
|
||||
|
||||
sum /= params.motion_blur_samples;
|
||||
|
||||
back_sum /= params.motion_blur_samples;
|
||||
|
||||
imageStore(output_image, uvi, sum + back_sum);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, sum + back_sum);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://b1fr5qhhrbpst"
|
||||
path="res://.godot/imported/jump_flood_realistic_blur.glsl-c7d6d91d942d788c7b2fc3bc2c1c8e38.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_realistic_blur.glsl"
|
||||
dest_files=["res://.godot/imported/jump_flood_realistic_blur.glsl-c7d6d91d942d788c7b2fc3bc2c1c8e38.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,245 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D velocity_map;
|
||||
layout(rgba16f, set = 0, binding = 4) uniform writeonly image2D output_image;
|
||||
layout(set = 0, binding = 5) uniform sampler2D tile_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float motion_blur_samples;
|
||||
float motion_blur_intensity;
|
||||
float motion_blur_center_fade;
|
||||
float frame;
|
||||
float last_iteration_index;
|
||||
float sample_step_multiplier;
|
||||
float step_exponent_modifier;
|
||||
float max_dilation_radius;
|
||||
int nan0;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - T / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, T);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float sze)
|
||||
{
|
||||
return clamp(1. - sze * (a - b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv){
|
||||
uv += float(params.frame) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://github.com/bradparks/KinoMotion__unity_motion_blur/tree/master
|
||||
// ----------------------------------------------------------
|
||||
vec2 safenorm(vec2 v)
|
||||
{
|
||||
float l = max(length(v), 1e-6);
|
||||
return v / l * int(l >= 0.5);
|
||||
}
|
||||
|
||||
vec2 jitter_tile(vec2 uvi)
|
||||
{
|
||||
float rx, ry;
|
||||
float angle = interleaved_gradient_noise(uvi + vec2(2, 0)) * M_PI * 2;
|
||||
rx = cos(angle);
|
||||
ry = sin(angle);
|
||||
return vec2(rx, ry) / textureSize(tile_max, 0) / 4;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
vec2 velocity_map_sample = textureLod(velocity_map, x + jitter_tile(uvi), 0.0).xy;
|
||||
|
||||
vec3 vnz = textureLod(tile_max, velocity_map_sample, 0.0).xyz * vec3(render_size, 1);
|
||||
|
||||
float vn_length = max(0.5, length(vnz.xy));
|
||||
|
||||
float multiplier = clamp(vn_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vn_length);
|
||||
|
||||
vnz.xyz *= multiplier;
|
||||
|
||||
vn_length *= multiplier;
|
||||
|
||||
vec2 vn = vnz.xy;
|
||||
|
||||
vec4 col_x = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
vec2 wn = safenorm(vn);
|
||||
|
||||
vec4 vxz = textureLod(velocity_sampler, x, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float vx_length = max(0.5, length(vxz.xy));
|
||||
|
||||
multiplier = clamp(vx_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vx_length);
|
||||
|
||||
vxz.xyz *= multiplier;
|
||||
|
||||
vx_length *= multiplier;
|
||||
|
||||
vec2 vx = vxz.xy;
|
||||
|
||||
if(vn_length <= 0.5)
|
||||
{
|
||||
imageStore(output_image, uvi, col_x);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, col_x);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
float velocity_match = pow(clamp(dot(vx, vn) / dot(vn, vn), 0, 1), 0.5);
|
||||
|
||||
vn = mix(vn, vx, velocity_match);
|
||||
|
||||
vnz = mix(vnz, vxz.xyz, velocity_match);
|
||||
|
||||
float zx = vxz.w;
|
||||
|
||||
vec2 wx = safenorm(vx);
|
||||
|
||||
float weight = 0;
|
||||
|
||||
vec4 sum = col_x * weight;
|
||||
|
||||
float total_back_weight = 1e-10;
|
||||
|
||||
vec4 back_sum = col_x * total_back_weight;
|
||||
|
||||
float j = interleaved_gradient_noise(uvi) - 0.5;
|
||||
|
||||
float nai_t;
|
||||
float nai_T;
|
||||
vec2 nai_y;
|
||||
float t;
|
||||
float T;
|
||||
vec2 y;
|
||||
vec4 nai_vy;
|
||||
float nai_zy;
|
||||
float nai_b;
|
||||
float nai_ay;
|
||||
vec4 nai_col_y;
|
||||
vec4 vy;
|
||||
float vy_length;
|
||||
float zy;
|
||||
float f;
|
||||
float wa;
|
||||
float ay_trail;
|
||||
vec4 col_y;
|
||||
|
||||
for(int i = 0; i < params.motion_blur_samples; i++)
|
||||
{
|
||||
t = mix(0., -1., (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
nai_y = x + (vx / render_size) * t;
|
||||
|
||||
T = abs(t * vn_length);
|
||||
|
||||
y = x + (vn / render_size) * t;
|
||||
|
||||
if(nai_y.x < 0 || nai_y.x > 1 || nai_y.y < 0 || nai_y.y > 1 || y.x < 0 || y.x > 1 || y.y < 0 || y.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
nai_vy = textureLod(velocity_sampler, nai_y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
nai_zy = nai_vy.w - vxz.z * t;
|
||||
|
||||
nai_b = z_compare(-zx, -nai_zy, 20000);
|
||||
|
||||
nai_ay = nai_b;
|
||||
|
||||
nai_col_y = textureLod(color_sampler, nai_y, 0.0);
|
||||
|
||||
total_back_weight += nai_ay;
|
||||
|
||||
back_sum += nai_col_y * nai_ay;
|
||||
|
||||
vy = textureLod(velocity_sampler, y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
vy_length = max(0.5, length(vy.xy));
|
||||
|
||||
zy = vy.w - vnz.z * t;
|
||||
|
||||
f = z_compare(-zy, -zx, 20000);
|
||||
|
||||
wa = abs(max(0, dot(vy.xy / vy_length, wn)));
|
||||
|
||||
ay_trail = f * step(T, vy_length * wa);
|
||||
|
||||
col_y = textureLod(color_sampler, y, 0.0);
|
||||
|
||||
weight += ay_trail;
|
||||
|
||||
sum += col_y * ay_trail;
|
||||
}
|
||||
|
||||
back_sum *= (params.motion_blur_samples - weight) / total_back_weight;
|
||||
|
||||
sum /= params.motion_blur_samples;
|
||||
|
||||
back_sum /= params.motion_blur_samples;
|
||||
|
||||
imageStore(output_image, uvi, sum + back_sum);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, sum + back_sum);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://bdm5t4l1y3ts7"
|
||||
path="res://.godot/imported/jump_flood_simple_blur.glsl-cf442320d0e724df4bd151fec5d94fae.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_simple_blur.glsl"
|
||||
dest_files=["res://.godot/imported/jump_flood_simple_blur.glsl-cf442320d0e724df4bd151fec5d94fae.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,239 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D velocity_map;
|
||||
layout(rgba16f, set = 0, binding = 4) uniform writeonly image2D output_image;
|
||||
layout(set = 0, binding = 5) uniform sampler2D tile_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float motion_blur_samples;
|
||||
float motion_blur_intensity;
|
||||
float motion_blur_center_fade;
|
||||
float frame;
|
||||
float last_iteration_index;
|
||||
float sample_step_multiplier;
|
||||
float step_exponent_modifier;
|
||||
float max_dilation_radius;
|
||||
int nan0;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - T / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, T);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float sze)
|
||||
{
|
||||
return clamp(1. - sze * (a - b), 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv){
|
||||
uv += float(params.frame) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://github.com/bradparks/KinoMotion__unity_motion_blur/tree/master
|
||||
// ----------------------------------------------------------
|
||||
vec2 safenorm(vec2 v)
|
||||
{
|
||||
float l = max(length(v), 1e-6);
|
||||
return v / l * int(l >= 0.5);
|
||||
}
|
||||
|
||||
vec2 jitter_tile(vec2 uvi)
|
||||
{
|
||||
float rx, ry;
|
||||
float angle = interleaved_gradient_noise(uvi + vec2(2, 0)) * M_PI * 2;
|
||||
rx = cos(angle);
|
||||
ry = sin(angle);
|
||||
return vec2(rx, ry) / textureSize(tile_max, 0) / 4;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
vec2 velocity_map_sample = textureLod(velocity_map, x + jitter_tile(uvi), 0.0).xy;
|
||||
|
||||
vec3 vnz = textureLod(tile_max, velocity_map_sample, 0.0).xyz * vec3(render_size, 1);
|
||||
|
||||
float vn_length = max(0.5, length(vnz.xy));
|
||||
|
||||
float multiplier = clamp(vn_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vn_length);
|
||||
|
||||
vnz.xyz *= multiplier;
|
||||
|
||||
vn_length *= multiplier;
|
||||
|
||||
vec2 vn = vnz.xy;
|
||||
|
||||
vec4 col_x = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
vec2 wn = safenorm(vn);
|
||||
|
||||
vec4 vxz = textureLod(velocity_sampler, x, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
float vx_length = max(0.5, length(vxz.xy));
|
||||
|
||||
multiplier = clamp(vx_length, 0, min(params.max_dilation_radius, vn_length * params.motion_blur_intensity)) / max(FLT_MIN, vx_length);
|
||||
|
||||
vxz.xyz *= multiplier;
|
||||
|
||||
vx_length *= multiplier;
|
||||
|
||||
vec2 vx = vxz.xy;
|
||||
|
||||
if(vn_length <= 0.5)
|
||||
{
|
||||
imageStore(output_image, uvi, col_x);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, col_x);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
float velocity_match = pow(clamp(dot(vx, vn) / dot(vn, vn), 0, 1), 1 / (1000 * abs(vnz.z)));
|
||||
|
||||
vn = mix(vn, vx, velocity_match);
|
||||
|
||||
vnz = mix(vnz, vxz.xyz, velocity_match);
|
||||
|
||||
float zx = vxz.w;
|
||||
|
||||
float j = interleaved_gradient_noise(uvi) - 0.5;
|
||||
|
||||
vec2 nai_y;
|
||||
float t;
|
||||
float T;
|
||||
vec2 y;
|
||||
vec4 nai_vy;
|
||||
float nai_zy;
|
||||
float nai_b;
|
||||
float nai_ay;
|
||||
vec4 vy;
|
||||
float vy_length;
|
||||
float zy;
|
||||
float f;
|
||||
float wa;
|
||||
float ay_trail;
|
||||
float y_inside;
|
||||
|
||||
float weight = 1e-5;
|
||||
|
||||
vec4 sum = col_x * weight;
|
||||
|
||||
float nai_weight = 1e-5;
|
||||
|
||||
vec4 nai_sum = col_x * weight;
|
||||
|
||||
float final_sample_count = params.motion_blur_samples;
|
||||
|
||||
for(int i = 0; i < params.motion_blur_samples; i++)
|
||||
{
|
||||
t = mix(0., -1., (i + j + 1.0) / (params.motion_blur_samples + 1.0));
|
||||
|
||||
nai_y = x + (vx / render_size) * t;
|
||||
|
||||
T = abs(t * vn_length);
|
||||
|
||||
y = x + (vn / render_size) * t;
|
||||
|
||||
nai_vy = textureLod(velocity_sampler, nai_y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
nai_zy = nai_vy.w - vxz.z * t;
|
||||
|
||||
nai_b = z_compare(-zx, -nai_zy, 20000);
|
||||
|
||||
nai_ay = nai_b;
|
||||
|
||||
nai_weight += 1;
|
||||
|
||||
nai_sum += mix(col_x, textureLod(color_sampler, nai_y, 0.0), nai_ay);
|
||||
|
||||
vy = textureLod(velocity_sampler, y, 0.0) * vec4(render_size, 1, 1);
|
||||
|
||||
vy_length = max(0.5, length(vy.xy));
|
||||
|
||||
zy = vy.w - vnz.z * t;
|
||||
|
||||
f = z_compare(-zy, -zx, 20000);
|
||||
|
||||
wa = abs(max(0, dot(vy.xy / vy_length, wn)));
|
||||
|
||||
ay_trail = f * step(T, vy_length * wa);
|
||||
|
||||
y_inside = step(0, y.x) * step(y.x, 1) * step(0, y.y) * step(y.y, 1);
|
||||
|
||||
weight += ay_trail * y_inside;
|
||||
|
||||
sum += textureLod(color_sampler, y, 0.0) * ay_trail * y_inside;
|
||||
}
|
||||
|
||||
sum /= weight;
|
||||
|
||||
weight /= final_sample_count;
|
||||
|
||||
nai_sum /= nai_weight;
|
||||
|
||||
nai_weight /= final_sample_count;
|
||||
|
||||
sum = mix(nai_sum, sum, weight);
|
||||
|
||||
imageStore(output_image, uvi, sum);
|
||||
|
||||
#ifdef DEBUG
|
||||
imageStore(debug_1_image, uvi, sum);
|
||||
imageStore(debug_2_image, uvi, abs(vec4(vn / render_size * 10, vnz.z * 100, 1)));
|
||||
imageStore(debug_3_image, uvi, abs(vec4(velocity_map_sample - x, 0, 1)));
|
||||
imageStore(debug_4_image, uvi, abs(vec4(vx / render_size * 10, vxz.z * 100, 1)));
|
||||
imageStore(debug_5_image, uvi, col_x);
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://c1vndulne5a5r"
|
||||
path="res://.godot/imported/jump_flood_simple_new_blur.glsl-eae32754cec4350c64665a4ed0291739.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_simple_new_blur.glsl"
|
||||
dest_files=["res://.godot/imported/jump_flood_simple_new_blur.glsl-eae32754cec4350c64665a4ed0291739.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/BaseClasses/mb_compositor_effect.gd"
|
||||
|
||||
@export_group("Shader Parameters")
|
||||
## the portion of speed that is allowed for side bleed of velocities
|
||||
## during the jfa dilation passes and before backtracking. Getting this a higher value
|
||||
## would make it so that meshes at movement blur more reliably, but also bleed
|
||||
## further perpendicularly to their velocity, thus wash elemets behind them out.
|
||||
@export var perpen_error_threshold : float = 0.5
|
||||
|
||||
## an initial step size that can increase the dilation radius proportionally, at the
|
||||
## sacrifice of some quality in the final resolution of the dilation.[br][br]
|
||||
## the formula for the maximum radius of the dilation (in pixels) is: pow(2 + step_exponent_modifier, JFA_pass_count) * sample_step_multiplier
|
||||
@export var sample_step_multiplier : int = 16
|
||||
|
||||
## by default, the jump flood makes samples along distances that start
|
||||
## at 2 to the power of the pass count you want to perform, which is also
|
||||
## the dilation radius you desire. You can change it to values higher than
|
||||
## 2 with this variable, and reach higher dilation radius at the sacrifice of
|
||||
## some accuracy in the dilation.
|
||||
## the formula for the maximum radius of the dilation (in pixels) is: pow(2 + step_exponent_modifier, JFA_pass_count) * sample_step_multiplier
|
||||
@export var step_exponent_modifier : float = 1
|
||||
|
||||
## the number of passes performed by the jump flood algorithm based dilation,
|
||||
## each pass added doubles the maximum radius of dilation available.[br][br]
|
||||
## the formula for the maximum radius of the dilation (in pixels) is: pow(2 + step_exponent_modifier, JFA_pass_count) * sample_step_multiplier
|
||||
@export var JFA_pass_count : int = 3
|
||||
|
|
@ -1,294 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/JumpFlood/base_jump_flood_motion_blur.gd"
|
||||
class_name ExperimentalJumpFloodMotionBlur
|
||||
|
||||
@export_group("Shader Stages")
|
||||
@export var tile_max_x_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_tile_max_x_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_x_stage)
|
||||
tile_max_x_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var tile_max_y_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_tile_max_y_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_y_stage)
|
||||
tile_max_y_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var construct_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jf_simple_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(construct_stage)
|
||||
construct_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var neighbor_max_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_neighbor_max_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(neighbor_max_stage)
|
||||
neighbor_max_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var blur_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/experimental_jump_flood_blur_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(blur_stage)
|
||||
blur_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var cache_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_cache_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(cache_stage)
|
||||
cache_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var overlay_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_overlay_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(overlay_stage)
|
||||
overlay_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
var tile_max_x : StringName = "tile_max_x"
|
||||
|
||||
var tile_max : StringName = "tile_max"
|
||||
|
||||
var neighbor_max : StringName = "neighbor_max"
|
||||
|
||||
var output_color : StringName = "output_color"
|
||||
|
||||
var past_color : StringName = "past_color_cache"
|
||||
|
||||
var past_velocity : StringName = "past_velocity_cache"
|
||||
|
||||
var buffer_a : StringName = "buffer_a"
|
||||
var buffer_b : StringName = "buffer_b"
|
||||
|
||||
var custom_velocity : StringName = "custom_velocity"
|
||||
|
||||
var temp_intensity : float
|
||||
|
||||
var previous_time : float = 0
|
||||
|
||||
func _render_callback_2(render_size : Vector2i, render_scene_buffers : RenderSceneBuffersRD, render_scene_data : RenderSceneDataRD):
|
||||
var time : float = float(Time.get_ticks_msec()) / 1000
|
||||
|
||||
var delta_time : float = time - previous_time
|
||||
|
||||
previous_time = time
|
||||
|
||||
temp_intensity = intensity
|
||||
|
||||
if framerate_independent:
|
||||
var capped_frame_time : float = 1 / target_constant_framerate
|
||||
|
||||
if !uncapped_independence:
|
||||
capped_frame_time = min(capped_frame_time, delta_time)
|
||||
|
||||
temp_intensity = intensity * capped_frame_time / delta_time
|
||||
|
||||
ensure_texture(custom_velocity, render_scene_buffers)
|
||||
ensure_texture(tile_max_x, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1.))
|
||||
ensure_texture(tile_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(buffer_a, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(buffer_b, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(neighbor_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(output_color, render_scene_buffers)
|
||||
ensure_texture(past_color, render_scene_buffers)
|
||||
ensure_texture(past_velocity, render_scene_buffers)
|
||||
|
||||
rd.draw_command_begin_label("Motion Blur", Color(1.0, 1.0, 1.0, 1.0))
|
||||
|
||||
var last_iteration_index : int = JFA_pass_count - 1;
|
||||
|
||||
var max_dilation_radius : float = pow(2 + step_exponent_modifier, last_iteration_index) * sample_step_multiplier / intensity;
|
||||
|
||||
var tile_max_x_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_x_push_constants : PackedInt32Array = [
|
||||
sample_step_multiplier,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_x_push_constants_byte_array = tile_max_x_push_constants.to_byte_array()
|
||||
tile_max_x_push_constants_byte_array.append_array(int_tile_max_x_push_constants.to_byte_array())
|
||||
|
||||
var tile_max_y_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_y_push_constants : PackedInt32Array = [
|
||||
sample_step_multiplier,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_y_push_constants_byte_array = tile_max_y_push_constants.to_byte_array()
|
||||
tile_max_y_push_constants_byte_array.append_array(int_tile_max_y_push_constants.to_byte_array())
|
||||
var neighbor_max_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_neighbor_max_push_constants : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var neighbor_max_push_constants_byte_array = neighbor_max_push_constants.to_byte_array()
|
||||
neighbor_max_push_constants_byte_array.append_array(int_neighbor_max_push_constants.to_byte_array())
|
||||
|
||||
var push_constant: PackedFloat32Array = [
|
||||
samples,
|
||||
temp_intensity,
|
||||
center_fade,
|
||||
Engine.get_frames_drawn() % 8,
|
||||
last_iteration_index,
|
||||
sample_step_multiplier,
|
||||
step_exponent_modifier,
|
||||
max_dilation_radius,
|
||||
]
|
||||
var int_push_constant : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var byte_array = push_constant.to_byte_array()
|
||||
byte_array.append_array(int_push_constant.to_byte_array())
|
||||
|
||||
var view_count = render_scene_buffers.get_view_count()
|
||||
for view in range(view_count):
|
||||
var color_image := render_scene_buffers.get_color_layer(view)
|
||||
var depth_image := render_scene_buffers.get_depth_layer(view)
|
||||
var output_color_image := render_scene_buffers.get_texture_slice(context, output_color, view, 0, 1, 1)
|
||||
var past_color_image := render_scene_buffers.get_texture_slice(context, past_color, view, 0, 1, 1)
|
||||
var past_velocity_image := render_scene_buffers.get_texture_slice(context, past_velocity, view, 0, 1, 1)
|
||||
var buffer_a_image := render_scene_buffers.get_texture_slice(context, buffer_a, view, 0, 1, 1)
|
||||
var buffer_b_image := render_scene_buffers.get_texture_slice(context, buffer_b, view, 0, 1, 1)
|
||||
var custom_velocity_image := render_scene_buffers.get_texture_slice(context, custom_velocity, view, 0, 1, 1)
|
||||
var tile_max_x_image := render_scene_buffers.get_texture_slice(context, tile_max_x, view, 0, 1, 1)
|
||||
var tile_max_image := render_scene_buffers.get_texture_slice(context, tile_max, view, 0, 1, 1)
|
||||
var neighbor_max_image := render_scene_buffers.get_texture_slice(context, neighbor_max, view, 0, 1, 1)
|
||||
|
||||
var x_groups := floori((render_size.x / sample_step_multiplier - 1) / 16 + 1)
|
||||
var y_groups := floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_x_stage,
|
||||
[
|
||||
get_sampler_uniform(custom_velocity_image, 0, false),
|
||||
get_image_uniform(tile_max_x_image, 1)
|
||||
],
|
||||
tile_max_x_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxX",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x / sample_step_multiplier - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y / sample_step_multiplier - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_y_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_x_image, 0, false),
|
||||
get_image_uniform(tile_max_image, 1)
|
||||
],
|
||||
tile_max_y_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxY",
|
||||
view)
|
||||
|
||||
for i in JFA_pass_count:
|
||||
var jf_push_constants : PackedInt32Array = [
|
||||
i,
|
||||
last_iteration_index,
|
||||
0,
|
||||
16
|
||||
]
|
||||
|
||||
var jf_float_push_constants_test : PackedFloat32Array = [
|
||||
perpen_error_threshold,
|
||||
sample_step_multiplier,
|
||||
temp_intensity,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
step_exponent_modifier,
|
||||
0,
|
||||
max_dilation_radius,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var jf_byte_array = jf_push_constants.to_byte_array()
|
||||
jf_byte_array.append_array(jf_float_push_constants_test.to_byte_array())
|
||||
|
||||
dispatch_stage(construct_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_image_uniform(buffer_a_image, 1),
|
||||
get_image_uniform(buffer_b_image, 2),
|
||||
get_sampler_uniform(buffer_a_image, 3, false),
|
||||
get_sampler_uniform(buffer_b_image, 4, false),
|
||||
],
|
||||
jf_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Construct Blur",
|
||||
view)
|
||||
|
||||
dispatch_stage(neighbor_max_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_sampler_uniform(buffer_b_image if last_iteration_index % 2 else buffer_a_image, 1, false),
|
||||
get_image_uniform(neighbor_max_image, 2)
|
||||
],
|
||||
neighbor_max_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"NeighborMax",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(blur_stage,
|
||||
[
|
||||
get_sampler_uniform(color_image, 0, false),
|
||||
get_sampler_uniform(depth_image, 1, false),
|
||||
get_sampler_uniform(custom_velocity_image, 2, false),
|
||||
get_sampler_uniform(neighbor_max_image, 3, false),
|
||||
get_image_uniform(output_color_image, 4),
|
||||
get_sampler_uniform(tile_max_image, 5, false),
|
||||
get_sampler_uniform(past_color_image, 6, false),
|
||||
get_sampler_uniform(past_velocity_image, 7, false)
|
||||
],
|
||||
byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Compute Blur",
|
||||
view)
|
||||
|
||||
dispatch_stage(cache_stage,
|
||||
[
|
||||
get_sampler_uniform(custom_velocity_image, 0),
|
||||
get_sampler_uniform(color_image, 1),
|
||||
get_image_uniform(past_velocity_image, 2),
|
||||
get_image_uniform(past_color_image, 3),
|
||||
],
|
||||
[],
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Past Color Copy",
|
||||
view)
|
||||
|
||||
dispatch_stage(overlay_stage,
|
||||
[
|
||||
get_sampler_uniform(output_color_image, 0),
|
||||
get_image_uniform(color_image, 1),
|
||||
],
|
||||
[],
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Overlay Result",
|
||||
view)
|
||||
|
||||
rd.draw_command_end_label()
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://cvavvqqstnm1j"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_3q423"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://bud4a7eh5sqr8" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_experimental_blur.glsl" id="2_8flx6"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_3q423")
|
||||
shader_file = ExtResource("2_8flx6")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://bj3exhmsfcx4w"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_v4e3u"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://c4dywnp7k8rph" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jfp_simple.glsl" id="2_msxel"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_v4e3u")
|
||||
shader_file = ExtResource("2_msxel")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://nhb123qs0ja8"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_fyqxe"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://c57nhlyxb4m1t" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_blur.glsl" id="2_c1vs2"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_fyqxe")
|
||||
shader_file = ExtResource("2_c1vs2")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://bq18dhoelcexm"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_3clo0"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://quuyr2q5w5kx" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_cache.glsl" id="2_val47"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_3clo0")
|
||||
shader_file = ExtResource("2_val47")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://clwi2fnp1nm3r"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_eeyf1"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://rkkajixdjosk" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jfp_backtracking_experimental.glsl" id="2_o6bvw"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_eeyf1")
|
||||
shader_file = ExtResource("2_o6bvw")
|
||||
|
|
@ -1,190 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/JumpFlood/base_jump_flood_motion_blur.gd"
|
||||
class_name SphynxOldJumpFloodMotionBlur
|
||||
|
||||
@export_group("Shader Stages")
|
||||
@export var blur_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_blur_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(blur_stage)
|
||||
blur_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var overlay_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_overlay_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(overlay_stage)
|
||||
overlay_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var construct_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_construction_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(construct_stage)
|
||||
construct_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
## how many steps along a range of 2 velocities from the
|
||||
## dilation target velocity space do we go along to find a better fitting velocity sample
|
||||
## higher samples meaning higher detail getting captured and blurred
|
||||
@export var backtracking_sample_count : int = 8
|
||||
|
||||
## how sensitive the backtracking for velocities be
|
||||
@export var backtracking_velocity_match_threshold : float = 0.9
|
||||
|
||||
## how sensitively the backtracking should treat velocities that are a different
|
||||
## length along that velocity
|
||||
@export var backtracking_velocity_match_parallel_sensitivity : float = 1
|
||||
|
||||
## how sensitively the backtracking should treat velcoities that have perpendicular
|
||||
## offset to that velocity
|
||||
@export var backtracking_velcoity_match_perpendicular_sensitivity : float = 0.05
|
||||
|
||||
## how closely does the depth of the backtracked sample has to match the original sample to be
|
||||
## considered (in NDC space)
|
||||
@export var backtracbing_depth_match_threshold : float = 0.001
|
||||
|
||||
var texture: StringName = "texture"
|
||||
|
||||
var buffer_a : StringName = "buffer_a"
|
||||
var buffer_b : StringName = "buffer_b"
|
||||
|
||||
var custom_velocity : StringName = "custom_velocity"
|
||||
|
||||
var temp_intensity : float
|
||||
|
||||
var previous_time : float = 0
|
||||
|
||||
func _render_callback_2(render_size : Vector2i, render_scene_buffers : RenderSceneBuffersRD, render_scene_data : RenderSceneDataRD):
|
||||
var time : float = float(Time.get_ticks_msec()) / 1000
|
||||
|
||||
var delta_time : float = time - previous_time
|
||||
|
||||
previous_time = time
|
||||
|
||||
temp_intensity = intensity
|
||||
|
||||
if framerate_independent:
|
||||
var capped_frame_time : float = 1 / target_constant_framerate
|
||||
|
||||
if !uncapped_independence:
|
||||
capped_frame_time = min(capped_frame_time, delta_time)
|
||||
|
||||
temp_intensity = intensity * capped_frame_time / delta_time
|
||||
|
||||
|
||||
ensure_texture(texture, render_scene_buffers)
|
||||
ensure_texture(buffer_a, render_scene_buffers)#, RenderingDevice.DATA_FORMAT_R16G16_SFLOAT)
|
||||
ensure_texture(buffer_b, render_scene_buffers)#, RenderingDevice.DATA_FORMAT_R16G16_SFLOAT)
|
||||
ensure_texture(custom_velocity, render_scene_buffers)
|
||||
|
||||
rd.draw_command_begin_label("Motion Blur", Color(1.0, 1.0, 1.0, 1.0))
|
||||
|
||||
var last_iteration_index : int = JFA_pass_count - 1;
|
||||
|
||||
var max_dilation_radius : float = pow(2 + step_exponent_modifier, last_iteration_index) * sample_step_multiplier / intensity;
|
||||
|
||||
var push_constant: PackedFloat32Array = [
|
||||
samples,
|
||||
temp_intensity,
|
||||
center_fade,
|
||||
Engine.get_frames_drawn() % 8,
|
||||
last_iteration_index,
|
||||
sample_step_multiplier,
|
||||
step_exponent_modifier,
|
||||
max_dilation_radius,
|
||||
]
|
||||
var int_push_constant : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var byte_array = push_constant.to_byte_array()
|
||||
byte_array.append_array(int_push_constant.to_byte_array())
|
||||
|
||||
var view_count = render_scene_buffers.get_view_count()
|
||||
for view in range(view_count):
|
||||
var color_image := render_scene_buffers.get_color_layer(view)
|
||||
var depth_image := render_scene_buffers.get_depth_layer(view)
|
||||
var texture_image := render_scene_buffers.get_texture_slice(context, texture, view, 0, 1, 1)
|
||||
var buffer_a_image := render_scene_buffers.get_texture_slice(context, buffer_a, view, 0, 1, 1)
|
||||
var buffer_b_image := render_scene_buffers.get_texture_slice(context, buffer_b, view, 0, 1, 1)
|
||||
var custom_velocity_image := render_scene_buffers.get_texture_slice(context, custom_velocity, view, 0, 1, 1)
|
||||
|
||||
rd.draw_command_begin_label("Construct blur " + str(view), Color(1.0, 1.0, 1.0, 1.0))
|
||||
|
||||
var tex_uniform_set
|
||||
var compute_list
|
||||
|
||||
var x_groups := floori((render_size.x - 1) / 16 + 1)
|
||||
var y_groups := floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
tex_uniform_set = UniformSetCacheRD.get_cache(construct_stage.shader, 0, [
|
||||
get_sampler_uniform(depth_image, 0, false),
|
||||
get_sampler_uniform(custom_velocity_image, 1, false),
|
||||
get_image_uniform(buffer_a_image, 2),
|
||||
get_image_uniform(buffer_b_image, 3),
|
||||
get_sampler_uniform(buffer_a_image, 4, false),
|
||||
get_sampler_uniform(buffer_b_image, 5, false)
|
||||
])
|
||||
|
||||
compute_list = rd.compute_list_begin()
|
||||
rd.compute_list_bind_compute_pipeline(compute_list, construct_stage.pipeline)
|
||||
rd.compute_list_bind_uniform_set(compute_list, tex_uniform_set, 0)
|
||||
|
||||
for i in JFA_pass_count:
|
||||
var jf_push_constants : PackedInt32Array = [
|
||||
i,
|
||||
last_iteration_index,
|
||||
backtracking_sample_count,
|
||||
16
|
||||
]
|
||||
|
||||
var step_size : float = round(pow(2 + step_exponent_modifier, last_iteration_index - i)) * sample_step_multiplier;
|
||||
|
||||
var jf_float_push_constants_test : PackedFloat32Array = [
|
||||
perpen_error_threshold,
|
||||
sample_step_multiplier,
|
||||
temp_intensity,
|
||||
backtracking_velocity_match_threshold,
|
||||
backtracking_velocity_match_parallel_sensitivity,
|
||||
backtracking_velcoity_match_perpendicular_sensitivity,
|
||||
backtracbing_depth_match_threshold,
|
||||
step_exponent_modifier,
|
||||
step_size,
|
||||
max_dilation_radius,
|
||||
0,
|
||||
0
|
||||
]
|
||||
|
||||
var jf_byte_array = jf_push_constants.to_byte_array()
|
||||
jf_byte_array.append_array(jf_float_push_constants_test.to_byte_array())
|
||||
|
||||
rd.compute_list_set_push_constant(compute_list, jf_byte_array, jf_byte_array.size())
|
||||
rd.compute_list_dispatch(compute_list, x_groups, y_groups, 1)
|
||||
|
||||
rd.compute_list_end()
|
||||
|
||||
rd.draw_command_end_label()
|
||||
|
||||
dispatch_stage(blur_stage,
|
||||
[
|
||||
get_sampler_uniform(color_image, 0, false),
|
||||
get_sampler_uniform(depth_image, 1, false),
|
||||
get_sampler_uniform(custom_velocity_image, 2, false),
|
||||
get_sampler_uniform(buffer_b_image if last_iteration_index % 2 else buffer_a_image, 3, false),
|
||||
get_image_uniform(texture_image, 4),
|
||||
],
|
||||
byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Compute Blur",
|
||||
view)
|
||||
|
||||
dispatch_stage(overlay_stage,
|
||||
[
|
||||
get_sampler_uniform(texture_image, 0),
|
||||
get_image_uniform(color_image, 1)
|
||||
],
|
||||
[],
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Overlay Result",
|
||||
view)
|
||||
|
||||
rd.draw_command_end_label()
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://co5k7plgmxepi"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_8et3l"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://cfk5chwlcyay4" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jf_neighbor_max.glsl" id="2_fub7x"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_8et3l")
|
||||
shader_file = ExtResource("2_fub7x")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://dc5fr84ue3dn5"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_6wgo2"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://dig08kpnfakuf" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_overlay.glsl" id="2_ljukb"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_6wgo2")
|
||||
shader_file = ExtResource("2_ljukb")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://c10aboaly701b"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_5367c"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://djp3da364fk2l" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jf_guertin_tile_max_x.glsl" id="2_1b71e"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_5367c")
|
||||
shader_file = ExtResource("2_1b71e")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://cymk87e4nyxva"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_5vg08"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://cqlltc8f21wre" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jf_guertin_tile_max_y.glsl" id="2_iusae"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_5vg08")
|
||||
shader_file = ExtResource("2_iusae")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://ceav72kvj4qbw"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_qdmen"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://b1fr5qhhrbpst" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_realistic_blur.glsl" id="2_bdp68"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_qdmen")
|
||||
shader_file = ExtResource("2_bdp68")
|
||||
|
|
@ -1,268 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/JumpFlood/base_jump_flood_motion_blur.gd"
|
||||
class_name SphynxRealisticJumpFloodMotionBlur
|
||||
|
||||
@export_group("Shader Stages")
|
||||
@export var tile_max_x_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_tile_max_x_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_x_stage)
|
||||
tile_max_x_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var tile_max_y_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_tile_max_y_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_y_stage)
|
||||
tile_max_y_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var construct_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jf_simple_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(construct_stage)
|
||||
construct_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var neighbor_max_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_neighbor_max_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(neighbor_max_stage)
|
||||
neighbor_max_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var blur_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/realistic_jf_blur_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(blur_stage)
|
||||
blur_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var overlay_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_overlay_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(overlay_stage)
|
||||
overlay_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
var tile_max_x : StringName = "tile_max_x"
|
||||
|
||||
var tile_max : StringName = "tile_max"
|
||||
|
||||
var neighbor_max : StringName = "neighbor_max"
|
||||
|
||||
var output_color : StringName = "output_color"
|
||||
|
||||
var buffer_a : StringName = "buffer_a"
|
||||
var buffer_b : StringName = "buffer_b"
|
||||
|
||||
var custom_velocity : StringName = "custom_velocity"
|
||||
var temp_intensity : float
|
||||
|
||||
var previous_time : float = 0
|
||||
|
||||
func _render_callback_2(render_size : Vector2i, render_scene_buffers : RenderSceneBuffersRD, render_scene_data : RenderSceneDataRD):
|
||||
var time : float = float(Time.get_ticks_msec()) / 1000
|
||||
|
||||
var delta_time : float = time - previous_time
|
||||
|
||||
previous_time = time
|
||||
|
||||
temp_intensity = intensity
|
||||
|
||||
if framerate_independent:
|
||||
var capped_frame_time : float = 1 / target_constant_framerate
|
||||
|
||||
if !uncapped_independence:
|
||||
capped_frame_time = min(capped_frame_time, delta_time)
|
||||
|
||||
temp_intensity = intensity * capped_frame_time / delta_time
|
||||
|
||||
ensure_texture(custom_velocity, render_scene_buffers)
|
||||
ensure_texture(tile_max_x, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1.))
|
||||
ensure_texture(tile_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(buffer_a, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(buffer_b, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(neighbor_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(output_color, render_scene_buffers)
|
||||
|
||||
rd.draw_command_begin_label("Motion Blur", Color(1.0, 1.0, 1.0, 1.0))
|
||||
|
||||
var last_iteration_index : int = JFA_pass_count - 1;
|
||||
|
||||
var max_dilation_radius : float = pow(2 + step_exponent_modifier, last_iteration_index) * sample_step_multiplier;
|
||||
|
||||
var tile_max_x_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_x_push_constants : PackedInt32Array = [
|
||||
sample_step_multiplier,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_x_push_constants_byte_array = tile_max_x_push_constants.to_byte_array()
|
||||
tile_max_x_push_constants_byte_array.append_array(int_tile_max_x_push_constants.to_byte_array())
|
||||
|
||||
var tile_max_y_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_y_push_constants : PackedInt32Array = [
|
||||
sample_step_multiplier,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_y_push_constants_byte_array = tile_max_y_push_constants.to_byte_array()
|
||||
tile_max_y_push_constants_byte_array.append_array(int_tile_max_y_push_constants.to_byte_array())
|
||||
var neighbor_max_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_neighbor_max_push_constants : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var neighbor_max_push_constants_byte_array = neighbor_max_push_constants.to_byte_array()
|
||||
neighbor_max_push_constants_byte_array.append_array(int_neighbor_max_push_constants.to_byte_array())
|
||||
|
||||
var push_constant: PackedFloat32Array = [
|
||||
samples,
|
||||
temp_intensity,
|
||||
center_fade,
|
||||
Engine.get_frames_drawn() % 8,
|
||||
last_iteration_index,
|
||||
sample_step_multiplier,
|
||||
step_exponent_modifier,
|
||||
max_dilation_radius,
|
||||
]
|
||||
var int_push_constant : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var byte_array = push_constant.to_byte_array()
|
||||
byte_array.append_array(int_push_constant.to_byte_array())
|
||||
|
||||
var view_count = render_scene_buffers.get_view_count()
|
||||
for view in range(view_count):
|
||||
var color_image := render_scene_buffers.get_color_layer(view)
|
||||
var depth_image := render_scene_buffers.get_depth_layer(view)
|
||||
var output_color_image := render_scene_buffers.get_texture_slice(context, output_color, view, 0, 1, 1)
|
||||
var buffer_a_image := render_scene_buffers.get_texture_slice(context, buffer_a, view, 0, 1, 1)
|
||||
var buffer_b_image := render_scene_buffers.get_texture_slice(context, buffer_b, view, 0, 1, 1)
|
||||
var custom_velocity_image := render_scene_buffers.get_texture_slice(context, custom_velocity, view, 0, 1, 1)
|
||||
var tile_max_x_image := render_scene_buffers.get_texture_slice(context, tile_max_x, view, 0, 1, 1)
|
||||
var tile_max_image := render_scene_buffers.get_texture_slice(context, tile_max, view, 0, 1, 1)
|
||||
var neighbor_max_image := render_scene_buffers.get_texture_slice(context, neighbor_max, view, 0, 1, 1)
|
||||
|
||||
var x_groups := floori((render_size.x / sample_step_multiplier - 1) / 16 + 1)
|
||||
var y_groups := floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_x_stage,
|
||||
[
|
||||
get_sampler_uniform(custom_velocity_image, 0, false),
|
||||
get_image_uniform(tile_max_x_image, 1)
|
||||
],
|
||||
tile_max_x_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxX",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x / sample_step_multiplier - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y / sample_step_multiplier - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_y_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_x_image, 0, false),
|
||||
get_image_uniform(tile_max_image, 1)
|
||||
],
|
||||
tile_max_y_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxY",
|
||||
view)
|
||||
|
||||
for i in JFA_pass_count:
|
||||
var jf_push_constants : PackedInt32Array = [
|
||||
i,
|
||||
last_iteration_index,
|
||||
0,
|
||||
16
|
||||
]
|
||||
|
||||
var step_size : float = round(pow(2 + step_exponent_modifier, last_iteration_index - i));
|
||||
|
||||
var jf_float_push_constants_test : PackedFloat32Array = [
|
||||
perpen_error_threshold,
|
||||
sample_step_multiplier,
|
||||
temp_intensity,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
step_exponent_modifier,
|
||||
step_size,
|
||||
max_dilation_radius,
|
||||
0,
|
||||
0
|
||||
]
|
||||
|
||||
var jf_byte_array = jf_push_constants.to_byte_array()
|
||||
jf_byte_array.append_array(jf_float_push_constants_test.to_byte_array())
|
||||
|
||||
dispatch_stage(construct_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_image_uniform(buffer_a_image, 1),
|
||||
get_image_uniform(buffer_b_image, 2),
|
||||
get_sampler_uniform(buffer_a_image, 3, false),
|
||||
get_sampler_uniform(buffer_b_image, 4, false),
|
||||
],
|
||||
jf_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Construct Blur",
|
||||
view)
|
||||
|
||||
dispatch_stage(neighbor_max_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_sampler_uniform(buffer_b_image if last_iteration_index % 2 else buffer_a_image, 1, false),
|
||||
get_image_uniform(neighbor_max_image, 2)
|
||||
],
|
||||
neighbor_max_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"NeighborMax",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(blur_stage,
|
||||
[
|
||||
get_sampler_uniform(color_image, 0, false),
|
||||
get_sampler_uniform(depth_image, 1, false),
|
||||
get_sampler_uniform(custom_velocity_image, 2, false),
|
||||
get_sampler_uniform(neighbor_max_image, 3, false),
|
||||
get_image_uniform(output_color_image, 4),
|
||||
get_sampler_uniform(tile_max_image, 5, false),
|
||||
],
|
||||
byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Compute Blur",
|
||||
view)
|
||||
|
||||
dispatch_stage(overlay_stage,
|
||||
[
|
||||
get_sampler_uniform(output_color_image, 0),
|
||||
get_image_uniform(color_image, 1),
|
||||
],
|
||||
[],
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Overlay Result",
|
||||
view)
|
||||
|
||||
rd.draw_command_end_label()
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="ShaderStageResource" load_steps=3 format=3 uid="uid://bk5yd5plopwi2"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/BaseClasses/shader_pass_resource.gd" id="1_ljx3c"]
|
||||
[ext_resource type="RDShaderFile" uid="uid://c1vndulne5a5r" path="res://addons/SphynxMotionBlurToolkit/JumpFlood/ShaderFiles/jump_flood_simple_new_blur.glsl" id="2_i8sdd"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_ljx3c")
|
||||
shader_file = ExtResource("2_i8sdd")
|
||||
|
|
@ -1,264 +0,0 @@
|
|||
extends "res://addons/SphynxMotionBlurToolkit/JumpFlood/base_jump_flood_motion_blur.gd"
|
||||
class_name SphynxSimpleJumpFloodMotionBlur
|
||||
@export_group("Shader Stages")
|
||||
@export var tile_max_x_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_tile_max_x_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_x_stage)
|
||||
tile_max_x_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var tile_max_y_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_tile_max_y_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(tile_max_y_stage)
|
||||
tile_max_y_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var construct_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jf_simple_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(construct_stage)
|
||||
construct_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var neighbor_max_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_neighbor_max_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(neighbor_max_stage)
|
||||
neighbor_max_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var blur_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/simple_jf_blur_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(blur_stage)
|
||||
blur_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
@export var overlay_stage : ShaderStageResource = preload("res://addons/SphynxMotionBlurToolkit/JumpFlood/jump_flood_overlay_stage.tres"):
|
||||
set(value):
|
||||
unsubscribe_shader_stage(overlay_stage)
|
||||
overlay_stage = value
|
||||
subscirbe_shader_stage(value)
|
||||
|
||||
var tile_max_x : StringName = "tile_max_x"
|
||||
|
||||
var tile_max : StringName = "tile_max"
|
||||
|
||||
var neighbor_max : StringName = "neighbor_max"
|
||||
|
||||
var output_color : StringName = "output_color"
|
||||
|
||||
var buffer_a : StringName = "buffer_a"
|
||||
var buffer_b : StringName = "buffer_b"
|
||||
|
||||
var custom_velocity : StringName = "custom_velocity"
|
||||
var temp_intensity : float
|
||||
|
||||
var previous_time : float = 0
|
||||
|
||||
func _render_callback_2(render_size : Vector2i, render_scene_buffers : RenderSceneBuffersRD, render_scene_data : RenderSceneDataRD):
|
||||
var time : float = float(Time.get_ticks_msec()) / 1000
|
||||
|
||||
var delta_time : float = time - previous_time
|
||||
|
||||
previous_time = time
|
||||
|
||||
temp_intensity = intensity
|
||||
|
||||
if framerate_independent:
|
||||
var capped_frame_time : float = 1 / target_constant_framerate
|
||||
|
||||
if !uncapped_independence:
|
||||
capped_frame_time = min(capped_frame_time, delta_time)
|
||||
|
||||
temp_intensity = intensity * capped_frame_time / delta_time
|
||||
|
||||
ensure_texture(custom_velocity, render_scene_buffers)
|
||||
ensure_texture(tile_max_x, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1.))
|
||||
ensure_texture(tile_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(buffer_a, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(buffer_b, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(neighbor_max, render_scene_buffers, RenderingDevice.DATA_FORMAT_R16G16B16A16_SFLOAT, Vector2(1. / sample_step_multiplier, 1. / sample_step_multiplier))
|
||||
ensure_texture(output_color, render_scene_buffers)
|
||||
|
||||
rd.draw_command_begin_label("Motion Blur", Color(1.0, 1.0, 1.0, 1.0))
|
||||
|
||||
var last_iteration_index : int = JFA_pass_count - 1;
|
||||
|
||||
var max_dilation_radius : float = pow(2 + step_exponent_modifier, last_iteration_index) * sample_step_multiplier;
|
||||
|
||||
var tile_max_x_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_x_push_constants : PackedInt32Array = [
|
||||
sample_step_multiplier,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_x_push_constants_byte_array = tile_max_x_push_constants.to_byte_array()
|
||||
tile_max_x_push_constants_byte_array.append_array(int_tile_max_x_push_constants.to_byte_array())
|
||||
|
||||
var tile_max_y_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_tile_max_y_push_constants : PackedInt32Array = [
|
||||
sample_step_multiplier,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var tile_max_y_push_constants_byte_array = tile_max_y_push_constants.to_byte_array()
|
||||
tile_max_y_push_constants_byte_array.append_array(int_tile_max_y_push_constants.to_byte_array())
|
||||
var neighbor_max_push_constants: PackedFloat32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var int_neighbor_max_push_constants : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var neighbor_max_push_constants_byte_array = neighbor_max_push_constants.to_byte_array()
|
||||
neighbor_max_push_constants_byte_array.append_array(int_neighbor_max_push_constants.to_byte_array())
|
||||
|
||||
var push_constant: PackedFloat32Array = [
|
||||
samples,
|
||||
temp_intensity,
|
||||
center_fade,
|
||||
Engine.get_frames_drawn() % 8,
|
||||
last_iteration_index,
|
||||
sample_step_multiplier,
|
||||
step_exponent_modifier,
|
||||
max_dilation_radius,
|
||||
]
|
||||
var int_push_constant : PackedInt32Array = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var byte_array = push_constant.to_byte_array()
|
||||
byte_array.append_array(int_push_constant.to_byte_array())
|
||||
|
||||
var view_count = render_scene_buffers.get_view_count()
|
||||
for view in range(view_count):
|
||||
var color_image := render_scene_buffers.get_color_layer(view)
|
||||
var depth_image := render_scene_buffers.get_depth_layer(view)
|
||||
var output_color_image := render_scene_buffers.get_texture_slice(context, output_color, view, 0, 1, 1)
|
||||
var buffer_a_image := render_scene_buffers.get_texture_slice(context, buffer_a, view, 0, 1, 1)
|
||||
var buffer_b_image := render_scene_buffers.get_texture_slice(context, buffer_b, view, 0, 1, 1)
|
||||
var custom_velocity_image := render_scene_buffers.get_texture_slice(context, custom_velocity, view, 0, 1, 1)
|
||||
var tile_max_x_image := render_scene_buffers.get_texture_slice(context, tile_max_x, view, 0, 1, 1)
|
||||
var tile_max_image := render_scene_buffers.get_texture_slice(context, tile_max, view, 0, 1, 1)
|
||||
var neighbor_max_image := render_scene_buffers.get_texture_slice(context, neighbor_max, view, 0, 1, 1)
|
||||
|
||||
var x_groups := floori((render_size.x / sample_step_multiplier - 1) / 16 + 1)
|
||||
var y_groups := floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_x_stage,
|
||||
[
|
||||
get_sampler_uniform(custom_velocity_image, 0, false),
|
||||
get_image_uniform(tile_max_x_image, 1)
|
||||
],
|
||||
tile_max_x_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxX",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x / sample_step_multiplier - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y / sample_step_multiplier - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(tile_max_y_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_x_image, 0, false),
|
||||
get_image_uniform(tile_max_image, 1)
|
||||
],
|
||||
tile_max_y_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"TileMaxY",
|
||||
view)
|
||||
|
||||
for i in JFA_pass_count:
|
||||
var jf_push_constants : PackedInt32Array = [
|
||||
i,
|
||||
last_iteration_index,
|
||||
0,
|
||||
16
|
||||
]
|
||||
|
||||
var jf_float_push_constants_test : PackedFloat32Array = [
|
||||
perpen_error_threshold,
|
||||
sample_step_multiplier,
|
||||
temp_intensity,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
step_exponent_modifier,
|
||||
0,
|
||||
max_dilation_radius,
|
||||
0,
|
||||
0
|
||||
]
|
||||
var jf_byte_array = jf_push_constants.to_byte_array()
|
||||
jf_byte_array.append_array(jf_float_push_constants_test.to_byte_array())
|
||||
|
||||
dispatch_stage(construct_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_image_uniform(buffer_a_image, 1),
|
||||
get_image_uniform(buffer_b_image, 2),
|
||||
get_sampler_uniform(buffer_a_image, 3, false),
|
||||
get_sampler_uniform(buffer_b_image, 4, false),
|
||||
],
|
||||
jf_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Construct Blur",
|
||||
view)
|
||||
|
||||
dispatch_stage(neighbor_max_stage,
|
||||
[
|
||||
get_sampler_uniform(tile_max_image, 0, false),
|
||||
get_sampler_uniform(buffer_b_image if last_iteration_index % 2 else buffer_a_image, 1, false),
|
||||
get_image_uniform(neighbor_max_image, 2)
|
||||
],
|
||||
neighbor_max_push_constants_byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"NeighborMax",
|
||||
view)
|
||||
|
||||
x_groups = floori((render_size.x - 1) / 16 + 1)
|
||||
y_groups = floori((render_size.y - 1) / 16 + 1)
|
||||
|
||||
dispatch_stage(blur_stage,
|
||||
[
|
||||
get_sampler_uniform(color_image, 0, false),
|
||||
get_sampler_uniform(depth_image, 1, false),
|
||||
get_sampler_uniform(custom_velocity_image, 2, false),
|
||||
get_sampler_uniform(neighbor_max_image, 3, false),
|
||||
get_image_uniform(output_color_image, 4),
|
||||
get_sampler_uniform(tile_max_image, 5, false),
|
||||
],
|
||||
byte_array,
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Compute Blur",
|
||||
view)
|
||||
|
||||
dispatch_stage(overlay_stage,
|
||||
[
|
||||
get_sampler_uniform(output_color_image, 0),
|
||||
get_image_uniform(color_image, 1),
|
||||
],
|
||||
[],
|
||||
Vector3i(x_groups, y_groups, 1),
|
||||
"Overlay Result",
|
||||
view)
|
||||
|
||||
rd.draw_command_end_label()
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2024 sphynx-owner
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
@ -1,152 +0,0 @@
|
|||
shader_type spatial;
|
||||
|
||||
render_mode unshaded, depth_draw_always, fog_disabled;
|
||||
|
||||
uniform sampler2D screen_texture : hint_screen_texture, filter_nearest;
|
||||
uniform sampler2D depth_texture : hint_depth_texture, filter_nearest;
|
||||
|
||||
uniform vec3 local_stretch_axis = vec3(0, 1, 0);
|
||||
|
||||
uniform float movement_speed = 0;
|
||||
|
||||
uniform int sample_count = 8;
|
||||
|
||||
uniform float debug_toggle = 0;
|
||||
|
||||
uniform vec4 debug_color : source_color = vec4(0);
|
||||
|
||||
//https://www.shadertoy.com/view/fdtfWM
|
||||
vec3 rotate(float angle, vec3 axis, vec3 point) // NOTE: axis must be unit!
|
||||
{
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
return c * point + s * cross(axis, point) + (1.0 - c) * (dot(point, axis) * axis); // Rodrigues' Rotation Formula
|
||||
}
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
float interleaved_gradient_noise(vec2 uv, int FrameId){
|
||||
uv += float(FrameId) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
|
||||
vec3 get_projection_onto_plane(vec3 plane_origin, vec3 normal, vec3 vector)
|
||||
{
|
||||
float plane_distance = dot(plane_origin, normal);
|
||||
return vector * plane_distance / dot(normal, vector);
|
||||
}
|
||||
|
||||
float soft_depth_compare(float x, float y, float sze)
|
||||
{
|
||||
return clamp(1. - (x - y) / sze, 0., 1.);
|
||||
}
|
||||
|
||||
vec2 intersect_cylinder(vec3 eye_point, vec3 end_point, vec3 origin, vec3 axis, float radius)
|
||||
{
|
||||
eye_point -= axis * dot(eye_point - origin, axis) + origin;
|
||||
|
||||
end_point -= axis * dot(end_point - origin, axis) + origin;
|
||||
|
||||
vec3 direction = end_point - eye_point;
|
||||
|
||||
float A = dot(direction, direction);
|
||||
float B = 2. * dot(eye_point, direction);
|
||||
float C = dot(eye_point, eye_point) - radius * radius;
|
||||
|
||||
float square_component = sqrt(B * B - 4. * A * C);
|
||||
|
||||
return vec2(-B + square_component, -B - square_component) / (2. * A);
|
||||
}
|
||||
|
||||
vec2 within_cylinder(vec3 point, vec3 origin, vec3 axis, float radius, float depth, float axis_offset)
|
||||
{
|
||||
float within_depth = step(abs(dot(point - origin - axis * axis_offset, axis)), depth / 2.);
|
||||
vec3 perpendicular_component = point - axis * dot(axis, point - origin) - origin;
|
||||
float within_radius = step(dot(perpendicular_component, perpendicular_component), radius * radius);
|
||||
|
||||
return vec2(within_depth * within_radius, step(0, dot(point - origin, axis)));
|
||||
}
|
||||
|
||||
vec3 color_corrected(vec3 color)
|
||||
{
|
||||
return color / mix(
|
||||
pow((vec3(1.) + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)),
|
||||
vec3(1.) * (1.0 / 12.92),
|
||||
lessThan(vec3(1.), vec3(0.04045)));
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 screen_uv = SCREEN_UV;
|
||||
|
||||
float depth = texture(depth_texture, screen_uv).x;
|
||||
vec3 ndc = vec3(screen_uv * 2.0 - 1.0, depth);
|
||||
vec4 world_position = INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
|
||||
world_position.xyz /= world_position.w;
|
||||
|
||||
vec4 world_mesh_position = INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(screen_uv * 2.0 - 1.0, FRAGCOORD.z, 1.0);
|
||||
world_mesh_position.xyz /= world_mesh_position.w;
|
||||
|
||||
vec3 node_relative_position = world_position.xyz - NODE_POSITION_WORLD;
|
||||
|
||||
vec3 camera_node_position = NODE_POSITION_WORLD - CAMERA_POSITION_WORLD;
|
||||
|
||||
vec3 camera_relative_position = world_position.xyz - CAMERA_POSITION_WORLD;
|
||||
|
||||
float on_mesh = 1.;
|
||||
|
||||
vec3 raw_clamped_difference = vec3(0.);
|
||||
|
||||
node_relative_position = world_mesh_position.xyz - NODE_POSITION_WORLD;
|
||||
|
||||
float noise_variation = interleaved_gradient_noise(SCREEN_UV * vec2(textureSize(screen_texture, 0)), int(TIME * 100.)) / float(sample_count);
|
||||
|
||||
float sum = 1.;
|
||||
|
||||
vec4 base_sample = texture(screen_texture, screen_uv);
|
||||
|
||||
vec4 col = base_sample;
|
||||
|
||||
float original_depth = 0.05 / depth;
|
||||
|
||||
for(int i = 0; i < sample_count; i++)
|
||||
{
|
||||
vec3 node_rotated_sample = node_relative_position.xyz + mat3(MODEL_MATRIX) * vec3(movement_speed * (local_stretch_axis * (float(i) / float(sample_count) + noise_variation)));
|
||||
|
||||
vec4 current_ndc = (PROJECTION_MATRIX * VIEW_MATRIX * (vec4(node_rotated_sample, 1) + vec4(NODE_POSITION_WORLD, 0)));
|
||||
|
||||
current_ndc.xyz /= current_ndc.w;
|
||||
|
||||
vec2 current_uv_sample = ((current_ndc + 1.) / 2.).xy ;
|
||||
|
||||
float current_depth = texture(depth_texture, current_uv_sample).x;
|
||||
|
||||
vec4 current_world_position = INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(vec3(current_ndc.xy, current_depth), 1.0);
|
||||
|
||||
current_world_position.xyz /= current_world_position.w;
|
||||
|
||||
current_depth = 0.05 / current_depth;
|
||||
|
||||
float current_sample_depth = 0.05 / current_ndc.z;
|
||||
|
||||
if (current_uv_sample.x < 0. || current_uv_sample.x > 1. || current_uv_sample.y < 0. || current_uv_sample.y > 1.)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float is_inside = step(current_depth - current_sample_depth, 1);
|
||||
|
||||
float original_inside = 1. - step(current_depth - original_depth, 1);
|
||||
|
||||
float revert_texture = max(is_inside, original_inside);
|
||||
|
||||
float weight = 1.;
|
||||
sum += weight;
|
||||
col += mix(base_sample, texture(screen_texture, current_uv_sample), revert_texture) * weight;
|
||||
}
|
||||
|
||||
col /= sum;
|
||||
|
||||
ALBEDO = col.xyz + debug_color.xyz;//vec3(depth * 10.);//
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://b8aytbebcsmv8"]
|
||||
|
||||
[ext_resource type="Shader" path="res://addons/SphynxMotionBlurToolkit/LinearBlurToolkit/LinearMotionBlurMesh.gdshader" id="1_m7mjv"]
|
||||
[ext_resource type="Script" path="res://addons/SphynxMotionBlurToolkit/LinearBlurToolkit/linear_motion_blur_mesh.gd" id="2_glqur"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_lylv4"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_oosyj"]
|
||||
resource_local_to_scene = true
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_m7mjv")
|
||||
shader_parameter/local_stretch_axis = Vector3(0, 1, 0)
|
||||
shader_parameter/movement_speed = 0.0
|
||||
shader_parameter/sample_count = 8
|
||||
shader_parameter/debug_toggle = 0.0
|
||||
shader_parameter/debug_color = Color(0, 0, 0, 0)
|
||||
|
||||
[node name="LinearMotionBlurMesh" type="MeshInstance3D"]
|
||||
mesh = SubResource("BoxMesh_lylv4")
|
||||
surface_material_override/0 = SubResource("ShaderMaterial_oosyj")
|
||||
script = ExtResource("2_glqur")
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
extends MeshInstance3D
|
||||
class_name LinearMotionBlurMesh
|
||||
|
||||
@export var target_node : Node3D
|
||||
|
||||
## the rotation vector the current mesh blur's around
|
||||
## locally
|
||||
@export_enum("x", "y", "z") var local_stretch_axis : int
|
||||
|
||||
@export var negate_local_stretch_axis : bool = false
|
||||
|
||||
@onready var local_stretch_vector : Vector3 = Vector3(1 if local_stretch_axis == 0 else 0, 1 if local_stretch_axis == 1 else 0, 1 if local_stretch_axis == 2 else 0) * (1 if !negate_local_stretch_axis else -1)
|
||||
|
||||
## At what speed does the mesh become visible and start blurring
|
||||
@export var speed_visibility_threshold : float = 0.2
|
||||
|
||||
## make mesh visible for debugging
|
||||
@export var show_debug : bool = false
|
||||
|
||||
var previous_mesh_transform : Transform3D = Transform3D()
|
||||
|
||||
var shape_depth : float = 0
|
||||
|
||||
func _ready():
|
||||
get_surface_override_material(0).set_shader_parameter("debug_color", Color(0, 0, 0, 0) if !show_debug else Color(1, 0, 0, 0))
|
||||
|
||||
var mesh_aabb : AABB = mesh.get_aabb()
|
||||
|
||||
var extent : Vector3 = mesh_aabb.size * global_basis.get_scale()
|
||||
|
||||
var center : Vector3 = mesh_aabb.get_center() * global_basis.get_scale()
|
||||
|
||||
var all_axis : Array[float] = [extent.x, extent.y, extent.z]
|
||||
|
||||
shape_depth = all_axis[local_stretch_axis]
|
||||
|
||||
previous_mesh_transform = target_node.global_transform
|
||||
|
||||
deferred_update_cylinder_data.call_deferred()
|
||||
|
||||
func deferred_update_cylinder_data():
|
||||
get_surface_override_material(0).set_shader_parameter("local_stretch_axis", local_stretch_vector)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var target_transform : Transform3D = target_node.global_transform
|
||||
|
||||
var offset : Vector3 = target_transform.origin - previous_mesh_transform.origin
|
||||
|
||||
var distance : float = (offset).length()
|
||||
|
||||
visible = distance > speed_visibility_threshold
|
||||
|
||||
get_surface_override_material(0).set_shader_parameter("movement_speed", distance / (distance + shape_depth))
|
||||
|
||||
global_position = target_transform.origin - offset / 2
|
||||
|
||||
previous_mesh_transform = target_transform
|
||||
|
||||
var alignment_quaternion : Quaternion = Quaternion(global_basis.orthonormalized() * local_stretch_vector, offset.normalized())
|
||||
|
||||
global_basis = Basis(alignment_quaternion) * global_basis;
|
||||
|
||||
scale = scale * (Vector3(1, 1, 1) - local_stretch_vector) + local_stretch_vector * (distance + shape_depth)
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D color_sampler;
|
||||
layout(set = 0, binding = 1) uniform sampler2D depth_sampler;
|
||||
layout(set = 0, binding = 2) uniform sampler2D velocity_sampler;
|
||||
layout(set = 0, binding = 3) uniform sampler2D neighbor_max;
|
||||
layout(set = 0, binding = 4) uniform sampler2D tile_variance;
|
||||
layout(rgba16f, set = 0, binding = 5) uniform writeonly image2D output_color;
|
||||
layout(rgba16f, set = 0, binding = 6) uniform image2D past_color_image;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int sample_count;
|
||||
int frame;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
// McGuire's functions https://docs.google.com/document/d/1IIlAKTj-O01hcXEdGxTErQbCHO9iBmRx6oFUy_Jm0fI/edit
|
||||
// ----------------------------------------------------------
|
||||
float soft_depth_compare(float depth_X, float depth_Y, float sze)
|
||||
{
|
||||
return clamp(1 - (depth_X - depth_Y) / sze, 0, 1);
|
||||
}
|
||||
|
||||
float cone(float T, float v)
|
||||
{
|
||||
return clamp(1 - abs(T) / v, 0, 1);
|
||||
}
|
||||
|
||||
float cylinder(float T, float v)
|
||||
{
|
||||
return 1.0 - smoothstep(0.95 * v, 1.05 * v, abs(T));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// Guertin's functions https://research.nvidia.com/sites/default/files/pubs/2013-11_A-Fast-and/Guertin2013MotionBlur-small.pdf
|
||||
// ----------------------------------------------------------
|
||||
float z_compare(float a, float b, float multiplier)
|
||||
{
|
||||
return clamp(1. + (a - b) * multiplier, 0, 1);
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
// from https://www.shadertoy.com/view/ftKfzc
|
||||
// ----------------------------------------------------------
|
||||
float interleaved_gradient_noise(vec2 uv, int FrameId){
|
||||
uv += float(FrameId) * (vec2(47, 17) * 0.695);
|
||||
|
||||
vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 );
|
||||
|
||||
return fract(magic.z * fract(dot(uv, magic.xy)));
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
|
||||
vec2 sample_random_offset(vec2 uv, float j)
|
||||
{
|
||||
return vec2(0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(color_sampler, 0));
|
||||
ivec2 tile_render_size = ivec2(textureSize(neighbor_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 x = (vec2(uvi) + vec2(0.5)) / vec2(render_size);
|
||||
|
||||
vec2 vn = textureLod(neighbor_max, x, 0.0).xy * render_size / 2;
|
||||
|
||||
float vn_length = max(0.5, length(vn));
|
||||
|
||||
vec4 base_color = textureLod(color_sampler, x, 0.0);
|
||||
|
||||
if(vn_length <= 0.5)
|
||||
{
|
||||
imageStore(output_color, uvi, base_color);
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 vx = textureLod(velocity_sampler, x, 0.0).xy * render_size / 2;
|
||||
|
||||
float zx = -0.05 / textureLod(depth_sampler, x, 0.0).x;
|
||||
|
||||
float vx_length = max(0.5, length(vx));
|
||||
|
||||
float weight = 1. / vx_length;
|
||||
|
||||
vec4 sum = base_color * weight;
|
||||
|
||||
float j = interleaved_gradient_noise(uvi, params.frame) - 0.5;
|
||||
|
||||
for(int i = 0; i < params.sample_count; i++)
|
||||
{
|
||||
if(i == (params.sample_count - 1) / 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float t = mix(-1, 1, (i + j + 1.0) / (params.sample_count + 1.0));
|
||||
|
||||
float T = t * vn_length;
|
||||
|
||||
vec2 y = x + (vn / render_size) * t;
|
||||
|
||||
vec2 vy = textureLod(velocity_sampler, y, 0.0).xy * render_size / 2;
|
||||
|
||||
float vy_length = max(0.5, length(vy));
|
||||
|
||||
float zy = -0.05 / textureLod(depth_sampler, y, 0.0).x;
|
||||
|
||||
float f = soft_depth_compare(zx, zy, 0.01);
|
||||
float b = soft_depth_compare(zy, zx, 0.01);
|
||||
|
||||
float ay = f * cone(T, vy_length) + b * cone(T, vx_length) + cylinder(T, vy_length) * cylinder(T, vx_length) * 2;
|
||||
|
||||
weight += ay;
|
||||
sum += ay * textureLod(color_sampler, y, 0.0);
|
||||
}
|
||||
|
||||
sum /= weight;
|
||||
|
||||
imageStore(output_color, uvi, sum);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://7fjex8wuiejk"
|
||||
path="res://.godot/imported/mcguire_blur.glsl-0cc0e90626b85e4aae8d4b21c9368b86.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_blur.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_blur.glsl-0cc0e90626b85e4aae8d4b21c9368b86.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D neighbor_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int nan1;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max, 0));
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uvi.x >= render_size.x) || (uvi.y >= render_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 max_neighbor_velocity = vec2(0);
|
||||
|
||||
float max_neighbor_velocity_length = 0;
|
||||
|
||||
for(int i = -1; i < 2; i++)
|
||||
{
|
||||
for(int j = -1; j < 2; j++)
|
||||
{
|
||||
vec2 current_offset = vec2(1) / vec2(render_size) * vec2(i, j);
|
||||
vec2 current_uv = uvn + current_offset;
|
||||
if(current_uv.x < 0 || current_uv.x > 1 || current_uv.y < 0 || current_uv.y > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_diagonal = (abs(i) + abs(j) == 2);
|
||||
|
||||
vec2 current_neighbor_velocity = textureLod(tile_max, current_uv, 0.0).xy;
|
||||
|
||||
bool facing_center = dot(current_neighbor_velocity, current_offset) > 0;
|
||||
|
||||
if(is_diagonal && !facing_center)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float current_neighbor_velocity_length = dot(current_neighbor_velocity, current_neighbor_velocity);
|
||||
if(current_neighbor_velocity_length > max_neighbor_velocity_length)
|
||||
{
|
||||
max_neighbor_velocity_length = current_neighbor_velocity_length;
|
||||
max_neighbor_velocity = current_neighbor_velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imageStore(neighbor_max, uvi, vec4(max_neighbor_velocity, 0, 1));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://byfogr1qtbafi"
|
||||
path="res://.godot/imported/mcguire_neighbor_max.glsl-aa40cc8d534a08ad7aaf84bf0615cc3a.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_neighbor_max.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_neighbor_max.glsl-aa40cc8d534a08ad7aaf84bf0615cc3a.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D blur_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform image2D color_image;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(blur_sampler, 0));
|
||||
ivec2 output_size = imageSize(color_image);
|
||||
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
|
||||
if ((uv.x >= output_size.x) || (uv.y >= output_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
imageStore(color_image, uv, textureLod(blur_sampler, (vec2(uv) + 0.5) / output_size, 0.0));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://ylkrbqh7unvl"
|
||||
path="res://.godot/imported/mcguire_overlay.glsl-a331e470c95eacb608a05976de7b2202.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_overlay.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_overlay.glsl-a331e470c95eacb608a05976de7b2202.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D velocity_sampler;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D tile_max_x;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(velocity_sampler, 0));
|
||||
ivec2 output_size = imageSize(tile_max_x);
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
ivec2 global_uvi = uvi * ivec2(params.tile_size, 1);
|
||||
if ((uvi.x >= output_size.x) || (uvi.y >= output_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(global_uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 max_velocity = vec2(0);
|
||||
|
||||
float max_velocity_length = 0;
|
||||
|
||||
for(int i = 0; i < params.tile_size; i++)
|
||||
{
|
||||
vec2 current_uv = uvn + vec2(float(i) / render_size.x, 0);
|
||||
vec2 velocity_sample = textureLod(velocity_sampler, current_uv, 0.0).xy;
|
||||
float current_velocity_length = dot(velocity_sample, velocity_sample);
|
||||
if(current_velocity_length > max_velocity_length)
|
||||
{
|
||||
max_velocity_length = current_velocity_length;
|
||||
max_velocity = velocity_sample;
|
||||
}
|
||||
}
|
||||
imageStore(tile_max_x, uvi, vec4(max_velocity, 0, 1));
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://bp5jl5351ph2d"
|
||||
path="res://.godot/imported/mcguire_tile_max_x.glsl-9c459b3d537ec225893d39ee91be1c1e.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/SphynxMotionBlurToolkit/McGuire/ShaderFiles/mcguire_tile_max_x.glsl"
|
||||
dest_files=["res://.godot/imported/mcguire_tile_max_x.glsl-9c459b3d537ec225893d39ee91be1c1e.res"]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D tile_max_x;
|
||||
layout(rgba16f, set = 0, binding = 1) uniform writeonly image2D tile_max;
|
||||
|
||||
layout(push_constant, std430) uniform Params
|
||||
{
|
||||
float nan5;
|
||||
float nan6;
|
||||
float nan7;
|
||||
float nan8;
|
||||
int tile_size;
|
||||
int nan2;
|
||||
int nan3;
|
||||
int nan4;
|
||||
} params;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 render_size = ivec2(textureSize(tile_max_x, 0));
|
||||
ivec2 output_size = imageSize(tile_max);
|
||||
ivec2 uvi = ivec2(gl_GlobalInvocationID.xy);
|
||||
ivec2 global_uvi = uvi * ivec2(1, params.tile_size);
|
||||
if ((uvi.x >= output_size.x) || (uvi.y >= output_size.y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vec2 uvn = (vec2(global_uvi) + vec2(0.5)) / render_size;
|
||||
|
||||
vec2 max_velocity = vec2(0);
|
||||
|
||||
float max_velocity_length = 0;
|
||||
|
||||
for(int i = 0; i < params.tile_size; i++)
|
||||
{
|
||||
vec2 current_uv = uvn + vec2(0, float(i) / render_size.y);
|
||||
vec2 velocity_sample = textureLod(tile_max_x, current_uv, 0.0).xy;
|
||||
float current_velocity_length = dot(velocity_sample, velocity_sample);
|
||||
if(current_velocity_length > max_velocity_length)
|
||||
{
|
||||
max_velocity_length = current_velocity_length;
|
||||
max_velocity = velocity_sample;
|
||||
}
|
||||
}
|
||||
imageStore(tile_max, uvi, vec4(max_velocity, 0, 1));
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user