diff --git a/post_processing/node/children/Bloom.tscn b/post_processing/node/children/Bloom.tscn index e841f2a..c731f15 100644 --- a/post_processing/node/children/Bloom.tscn +++ b/post_processing/node/children/Bloom.tscn @@ -10,6 +10,7 @@ shader_parameter/blur_radius = 1.0 shader_parameter/blur_direction = Vector2(1, 1) [node name="Bloom" type="CanvasLayer"] +layer = 100 [node name="ColorRect" type="ColorRect" parent="."] material = SubResource("ShaderMaterial_s3kyv") diff --git a/post_processing/node/children/ChromaticAberration.tscn b/post_processing/node/children/ChromaticAberration.tscn index 8320972..7002b1a 100644 --- a/post_processing/node/children/ChromaticAberration.tscn +++ b/post_processing/node/children/ChromaticAberration.tscn @@ -4,9 +4,10 @@ [sub_resource type="ShaderMaterial" id="ShaderMaterial_ke5y5"] shader = ExtResource("1_qxjen") -shader_parameter/offset = 5.0 +shader_parameter/offset = 50.0 [node name="ChromaticAberration" type="CanvasLayer"] +layer = 102 [node name="data" type="ColorRect" parent="."] material = SubResource("ShaderMaterial_ke5y5") diff --git a/post_processing/node/children/blur.tscn b/post_processing/node/children/blur.tscn index bebdb6f..1bfdb8e 100644 --- a/post_processing/node/children/blur.tscn +++ b/post_processing/node/children/blur.tscn @@ -4,9 +4,10 @@ [sub_resource type="ShaderMaterial" id="ShaderMaterial_efbmf"] shader = ExtResource("1_6v1pv") -shader_parameter/lod = 1.0 +shader_parameter/lod = 1.287 [node name="Blur" type="CanvasLayer"] +layer = 101 [node name="data" type="ColorRect" parent="."] material = SubResource("ShaderMaterial_efbmf") diff --git a/post_processing/node/children/fish_eye.tscn b/post_processing/node/children/fish_eye.tscn new file mode 100644 index 0000000..a81626f --- /dev/null +++ b/post_processing/node/children/fish_eye.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=3 uid="uid://c5qv7q54m4xn6"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/fish_eye.gdshader" id="1_eks6e"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_v56sw"] +shader = ExtResource("1_eks6e") +shader_parameter/effect_amount = 1.635 + +[node name="FishEye" type="CanvasLayer"] +layer = 103 + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_v56sw") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/post_processing/node/children/glitch.tscn b/post_processing/node/children/glitch.tscn new file mode 100644 index 0000000..c5fd571 --- /dev/null +++ b/post_processing/node/children/glitch.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=3 format=3 uid="uid://dwioerk4ps6rr"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/glitch.gdshader" id="1_3euvy"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_gdr74"] +shader = ExtResource("1_3euvy") +shader_parameter/range = 0.055 +shader_parameter/noiseQuality = 250.0 +shader_parameter/noiseIntensity = 0.0088 +shader_parameter/offsetIntensity = 0.03 +shader_parameter/colorOffsetIntensity = 1.3 + +[node name="Glitch" type="CanvasLayer"] +layer = 104 + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_gdr74") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/post_processing/node/children/kaleidoscope.gdshader b/post_processing/node/children/kaleidoscope.gdshader new file mode 100644 index 0000000..08328b9 --- /dev/null +++ b/post_processing/node/children/kaleidoscope.gdshader @@ -0,0 +1,309 @@ +shader_type canvas_item; + +// CC0: Truchet + Kaleidoscope FTW +// Bit of experimenting with kaleidoscopes and truchet turned out nice +// Quite similar to an earlier shader I did but I utilized a different truchet pattern this time + +uniform float animate_speed = 0.25; +uniform float resolution = 1.0; + +// License: Unknown, author: Unknown, found: don't remember +vec4 alphaBlend(vec4 back, vec4 front) { + float w = front.w + back.w*(1.0-front.w); + vec3 xyz = (front.xyz*front.w + back.xyz*back.w*(1.0-front.w))/w; + return w > 0.0 ? vec4(xyz, w) : vec4(0.0); + +} +mat2 ROT(float a){ + return mat2(vec2(cos(a),sin(a)),vec2(-sin(a),cos(a))); +} +float PCOS(float x){ + return 0.5+0.5*cos(x); +} + +// License: Unknown, author: Unknown, found: don't remember +vec3 alphaBlend34(vec3 back, vec4 front) { + return mix(back, front.xyz, front.w); +} + +// License: Unknown, author: Unknown, found: don't remember +float hashf(float co) { + return fract(sin(co*12.9898) * 13758.5453); +} + +// License: Unknown, author: Unknown, found: don't remember +float hashv(vec2 p) { + float a = dot(p, vec2 (127.1, 311.7)); + return fract(sin (a)*43758.5453123); +} + +// License: Unknown, author: Unknown, found: don't remember +float tanh_approx(float x) { + // Found this somewhere on the interwebs + // return tanh(x); + float x2 = x*x; + return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0); +} + +// License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/articles/smin/smin.htm +float pmin(float a, float b, float k) { + float h = clamp(0.5+0.5*(b-a)/k, 0.0, 1.0); + return mix(b, a, h) - k*h*(1.0-h); +} + +// License: MIT, author: Inigo Quilez, found: https://www.iquilezles.org/www/index.htm +vec3 postProcess(vec3 col, vec2 q) { + col = clamp(col, 0.0, 1.0); + col = pow(col, vec3(1.0/2.2)); + col = col*0.6+0.4*col*col*(3.0-2.0*col); + col = mix(col, vec3(dot(col, vec3(0.33))), -0.4); + col *=0.5+0.5*pow(19.0*q.x*q.y*(1.0-q.x)*(1.0-q.y),0.7); + return col; +} + +float pmax(float a, float b, float k) { + return -pmin(-a, -b, k); +} + +float pabs(float a, float k) { + return pmax(a, -a, k); +} + +vec2 toPolar(vec2 p) { + return vec2(length(p), atan(p.y, p.x)); +} + +vec2 toRect(vec2 p) { + return vec2(p.x*cos(p.y), p.x*sin(p.y)); +} + +// License: MIT OR CC-BY-NC-4.0, author: mercury, found: https://mercury.sexy/hg_sdf/ +float modMirror1(inout float p, float size) { + float halfsize = size*0.5; + float c = floor((p + halfsize)/size); + p = mod(p + halfsize,size) - halfsize; + p *= mod(c, 2.0)*2.0 - 1.0; + return c; +} + +float smoothKaleidoscope(inout vec2 p, float sm, float rep) { + vec2 hp = p; + + vec2 hpp = toPolar(hp); + float rn = modMirror1(hpp.y, 2.0*PI/rep); + + float sa = PI/rep - pabs(PI/rep - abs(hpp.y), sm); + hpp.y = sign(hpp.y)*(sa); + + hp = toRect(hpp); + + p = hp; + + return rn; +} + +// The path function +vec3 offset(float z) { + float a = z; + vec2 p = -0.075*(vec2(cos(a), sin(a*sqrt(2.0))) + vec2(cos(a*sqrt(0.75)), sin(a*sqrt(0.5)))); + return vec3(p, z); +} + +// The derivate of the path function +// Used to generate where we are looking +vec3 doffset(float z) { + float eps = 0.1; + return 0.5*(offset(z + eps) - offset(z - eps))/eps; +} + +// The second derivate of the path function +// Used to generate tilt +vec3 ddoffset(float z) { + float eps = 0.1; + return 0.125*(doffset(z + eps) - doffset(z - eps))/eps; +} + +vec2 cell_df(float r, vec2 np, vec2 mp, vec2 off) { + + vec2 n0 = normalize(vec2(1.0, 1.0)); + vec2 n1 = normalize(vec2(1.0, -1.0)); + + np += off; + mp -= off; + + float hh = hashv(np); + float h0 = hh; + + vec2 p0 = mp; + p0 = abs(p0); + p0 -= 0.5; + float d0 = length(p0); + float d1 = abs(d0-r); + + float dot0 = dot(n0, mp); + float dot1 = dot(n1, mp); + + float d2 = abs(dot0); + float t2 = dot1; + d2 = abs(t2) > sqrt(0.5) ? d0 : d2; + + float d3 = abs(dot1); + float t3 = dot0; + d3 = abs(t3) > sqrt(0.5) ? d0 : d3; + + + float d = d0; + d = min(d, d1); + if (h0 > .85) + { + d = min(d, d2); + d = min(d, d3); + } + else if(h0 > 0.5) + { + d = min(d, d2); + } + else if(h0 > 0.15) + { + d = min(d, d3); + } + + return vec2(d, (d0-r)); +} + +vec2 truchet_df(float r, vec2 p) { + vec2 np = floor(p+0.5); + vec2 mp = fract(p+0.5) - 0.5; + return cell_df(r, np, mp, vec2(0.0)); +} + +vec4 plane(vec3 ro, vec3 rd, vec3 pp, vec3 off, float aa, float n) { + float h_ = hashf(n); + float h0 = fract(1777.0*h_); + float h1 = fract(2087.0*h_); + float h2 = fract(2687.0*h_); + float h3 = fract(3167.0*h_); + float h4 = fract(3499.0*h_); + + float l = length(pp - ro); + + vec3 hn; + vec2 p = (pp-off*vec3(1.0, 1.0, 0.0)).xy; + p *= ROT(0.5*(h4 - 0.5)*TIME); + float rep = 2.0*round(mix(5.0, 30.0, h2)); + float sm = 0.05*20.0/rep; + float sn = smoothKaleidoscope(p, sm, rep); + p *= ROT(2.0*PI*h0+0.025*TIME); + float z = mix(0.2, 0.4, h3); + p /= z; + p+=0.5+floor(h1*1000.0); + float tl = tanh_approx(0.33*l); + float r = mix(0.30, 0.45, PCOS(0.1*n)); + vec2 d2 = truchet_df(r, p); + d2 *= z; + float d = d2.x; + float lw =0.025*z; + d -= lw; + + vec3 col = mix(vec3(1.0), vec3(0.0), smoothstep(aa, -aa, d)); + col = mix(col, vec3(0.0), smoothstep(mix(1.0, -0.5, tl), 1.0, sin(PI*100.0*d))); +// float t0 = smoothstep(aa, -aa, -d2.y-lw); + col = mix(col, vec3(0.0), step(d2.y, 0.0)); + //float t = smoothstep(3.0*lw, 0.0, -d2.y); +// float t = smoothstep(aa, -aa, -d2.y-lw); + float t = smoothstep(aa, -aa, -d2.y-3.0*lw)*mix(0.5, 1.0, smoothstep(aa, -aa, -d2.y-lw)); + return vec4(col, t); +} + +vec3 skyColor(vec3 ro, vec3 rd) { + float d = pow(max(dot(rd, vec3(0.0, 0.0, 1.0)), 0.0), 20.0); + return vec3(d); +} + + +vec3 color(vec3 ww, vec3 uu, vec3 vv, vec3 ro, vec2 p){ + float lp = length(p); + vec2 np = p + 1.0/vec2(1920.0*resolution,1080.0*resolution) ; + float rdd = (2.0+1.0*tanh_approx(lp)); +// float rdd = 2.0; + vec3 rd = normalize(p.x*uu + p.y*vv + rdd*ww); + vec3 nrd = normalize(np.x*uu + np.y*vv + rdd*ww); + + float planeDist = 1.0-0.25; + int furthest = 6; + int fadeFrom = max(furthest-5, 0); + + float fadeDist = planeDist*float(furthest - fadeFrom); + float nz = floor(ro.z / planeDist); + + vec3 skyCol = skyColor(ro, rd); + + + vec4 acol = vec4(0.0); + float cutOff = 0.95; + bool cutOut = false; + + // Steps from nearest to furthest plane and accumulates the color + for (int i = 1; i <= furthest; ++i) { + float pz = planeDist*nz + planeDist*float(i); + + float pd = (pz - ro.z)/rd.z; + + if (pd > 0.0 && acol.w < cutOff) { + vec3 pp = ro + rd*pd; + vec3 npp = ro + nrd*pd; + + float aa = 3.0*length(pp - npp); + + vec3 off = offset(pp.z); + + vec4 pcol = plane(ro, rd, pp, off, aa, nz+float(i)); + + float nz1 = pp.z-ro.z; + float fadeIn = smoothstep(planeDist*float(furthest), planeDist*float(fadeFrom), nz1); + float fadeOut = smoothstep(0.0, planeDist*0.1, nz1); + pcol.xyz = mix(skyCol, pcol.xyz, fadeIn); + pcol.w *= fadeOut; + pcol = clamp(pcol, 0.0, 1.0); + + acol = alphaBlend(pcol, acol); + } else { + cutOut = true; + break; + } + + } + + vec3 col = alphaBlend34(skyCol, acol); +// To debug cutouts due to transparency +// col += cutOut ? vec3(1.0, -1.0, 0.0) : vec3(0.0); + return col; +} +vec3 effect(vec2 p, vec2 q) { + float tm = TIME*animate_speed; + vec3 ro = offset(tm); + vec3 dro = doffset(tm); + vec3 ddro = ddoffset(tm); + + vec3 ww = normalize(dro); + vec3 uu = normalize(cross(normalize(vec3(0.0,1.0,0.0)+ddro), ww)); + vec3 vv = normalize(cross(ww, uu)); + + vec3 col = color(ww, uu, vv, ro, p); + + return col; +} +void fragment(){ + + + + vec2 q = FRAGCOORD.xy/(1.0 / SCREEN_PIXEL_SIZE).xy; + vec2 p = -1. + 2. * q; + p.x *= (1.0 / SCREEN_PIXEL_SIZE).x/(1.0 / SCREEN_PIXEL_SIZE).y; + + vec3 col = effect(p, q); + col *= smoothstep(0.0, 4.0, TIME); + col = postProcess(col, q); + + COLOR = vec4(col, 1.0); +} \ No newline at end of file diff --git a/post_processing/node/children/outline.gdshader b/post_processing/node/children/outline.gdshader new file mode 100644 index 0000000..84f453e --- /dev/null +++ b/post_processing/node/children/outline.gdshader @@ -0,0 +1,41 @@ +// NekotoArts YouTube: https://www.youtube.com/channel/UCD7K_FECPHTF0z5okAVlh0g +// Adapted from https://www.shadertoy.com/view/ldsfRn + +shader_type canvas_item; + +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; + +uniform vec4 edge_color : source_color = vec4(0.0, 0.0, 0.0, 1.0); +uniform float threshold = 0.0; +uniform float blend = 0.01; + +float getGrayScale(sampler2D sampler, vec2 coods){ + vec4 color = texture(sampler,coods); + float gray = (color.r + color.g + color.b)/3.0; + return gray; +} + +void fragment(){ + vec2 delta = vec2(0.0,0.003); + vec2 iResolution = 1.0 / SCREEN_PIXEL_SIZE; + float m = max(iResolution.x,iResolution.y); + vec2 texCoords = SCREEN_UV; + + vec3 screen_color = texture(SCREEN_TEXTURE, SCREEN_UV).rgb; + + float c1y = getGrayScale(SCREEN_TEXTURE, texCoords.xy-delta/2.0); + float c2y = getGrayScale(SCREEN_TEXTURE, texCoords.xy+delta/2.0); + + float c1x = getGrayScale(SCREEN_TEXTURE, texCoords.xy-delta.yx/2.0); + float c2x = getGrayScale(SCREEN_TEXTURE, texCoords.xy+delta.yx/2.0); + + float dcdx = (c2x - c1x)/(delta.y*10.0); + float dcdy = (c2y - c1y)/(delta.y*10.0); + + vec2 dcdi = vec2(dcdx,dcdy); + float edge = length(dcdi)/10.0; + edge = 1.0 - edge; + edge = smoothstep(threshold, threshold + blend, edge); + + COLOR.rgb = mix(edge_color.rgb, screen_color.rgb, edge); +} \ No newline at end of file diff --git a/post_processing/node/children/outline.tscn b/post_processing/node/children/outline.tscn new file mode 100644 index 0000000..eedbfc2 --- /dev/null +++ b/post_processing/node/children/outline.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=3 format=3 uid="uid://c0d4h1un0350r"] + +[ext_resource type="Shader" path="res://addons/post_processing/node/children/outline.gdshader" id="1_x8jvf"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_yuki3"] +shader = ExtResource("1_x8jvf") +shader_parameter/edge_color = Color(0, 0, 0, 1) +shader_parameter/threshold = 0.0 +shader_parameter/blend = 0.1 + +[node name="Outline" type="CanvasLayer"] + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_yuki3") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/post_processing/node/children/vignette.tscn b/post_processing/node/children/vignette.tscn new file mode 100644 index 0000000..96c2940 --- /dev/null +++ b/post_processing/node/children/vignette.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=3 format=3 uid="uid://crm7gskny246i"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/vignette.gdshader" id="1_1fqty"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_jiuwk"] +shader = ExtResource("1_1fqty") +shader_parameter/vignette_intensity = 1.48 +shader_parameter/vignette_opacity = 1.0 +shader_parameter/vignette_rgb = Color(0, 0, 0, 1) + +[node name="Vignette" type="CanvasLayer"] + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_jiuwk") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/post_processing/node/post_process.gd b/post_processing/node/post_process.gd index 33b26fe..4fd5c28 100644 --- a/post_processing/node/post_process.gd +++ b/post_processing/node/post_process.gd @@ -8,62 +8,140 @@ extends CanvasLayer @export_category("Blur") @export var Blur: bool @export_range(0.0, 5) var L_O_D = 1.0 +@export_category("Fish Eye") +@export var FishEye: bool +@export_range(-2.5, 2.5) var FishEyeAmount: float +@export_category("Vignette") +@export var Vignette: bool +@export var VignetteIntensity = 0.4 +@export_range(0.0, 1.0) var VignetteOpacity = 0.5 +@export var VignetteR_G_B: Color = Color(0.0, 0.0, 0.0, 1.0); +@export_category("Glitch") +@export var Glitch: bool +@export_range(0.0, 0.1, 0.005) var GlitchRange = 0.05 +@export_range(0.0, 300, 0.1) var GlitchNoiseQuality = 250.0 +@export_range(-0.6, 0.6, 0.0010) var GlitchIntenity = 0.0088 +@export_range(-0.1, 0.1, 0.001) var GlitchOffset = 0.03 +@export_range(0.0, 5.0, 0.001) var GlitchColorOffset = 1.3 +@export_category("Outline") +@export var Outline: bool +@export var OutlineColor: Color = Color(0.0, 0.0, 0.0, 1.0) +@export_range(0.0, 1.0) var OutlineThreshold = 0.0 +@export_range(0.0, 1.0) var OutlineBlend = 0.01 + + #@export_category("Bloom") var Bloom: bool = false var BloomDirection = Vector2(0,0) var BloomRadius = 0.0 var BloomIntensity = 0.0 -func _enter_tree(): - var ca = load("res://addons/post_processing/node/children/ChromaticAberration.tscn") - add_child(ca.instantiate()) - print("created CA") - var bl = load("res://addons/post_processing/node/children/blur.tscn") - add_child(bl.instantiate()) - print("created BL") - var blr = load("res://addons/post_processing/node/children/Bloom.tscn") - add_child(blr.instantiate()) - print("created BLR") - -func _process(delta): - if Engine.is_editor_hint() or !Engine.is_editor_hint(): - for child in get_children(): - if child.name == "ChromaticAberration": - var data = child.get_child(0) - data.material.set_shader_parameter("offset", StrenghtCA) - elif child.name == "Blur": - var data = child.get_child(0) - data.material.set_shader_parameter("lod", L_O_D) - elif child.name == "Bloom": - var data = child.get_child(0) - data.material.set_shader_parameter("blur_direction", BloomDirection) - data.material.set_shader_parameter("blur_radius", BloomRadius) - data.material.set_shader_parameter("blur_amount", BloomIntensity) +func _update_shaders(): + for child in get_children(): + if child.name == "ChromaticAberration": + var data = child.get_child(0) + data.material.set_shader_parameter("offset", StrenghtCA) + elif child.name == "Blur": + var data = child.get_child(0) + data.material.set_shader_parameter("lod", L_O_D) + elif child.name == "FishEye": + var data = child.get_child(0) + data.material.set_shader_parameter("effect_amount", FishEyeAmount) + elif child.name == "Vignette": + var data = child.get_child(0) + data.material.set_shader_parameter("vignette_intensity", VignetteIntensity) + data.material.set_shader_parameter("vignette_opacity", VignetteOpacity) + data.material.set_shader_parameter("vignette_rgb", VignetteR_G_B) + elif child.name == "Glitch": + var data = child.get_child(0) + data.material.set_shader_parameter("range", GlitchRange) + data.material.set_shader_parameter("noiseQuality", GlitchNoiseQuality) + data.material.set_shader_parameter("noiseIntensity", GlitchIntenity) + data.material.set_shader_parameter("offsetIntensity", GlitchOffset) + data.material.set_shader_parameter("colorOffsetIntensity", GlitchColorOffset) + elif child.name == "Outline": + var data = child.get_child(0) + data.material.set_shader_parameter("edge_color", OutlineColor) + data.material.set_shader_parameter("threshold", OutlineThreshold) + data.material.set_shader_parameter("blend", OutlineBlend) - - if ChromaticAberration == true: + if ChromaticAberration == true: + for child in get_children(): + if child.name.begins_with("ChromaticAberration"): + child.visible = true + else: + for child in get_children(): + if child.name.begins_with("ChromaticAberration"): + child.visible = false + if Blur == true: for child in get_children(): - if child.name == "ChromaticAberration": + if child.name.begins_with("Blur"): child.visible = true else: for child in get_children(): - if child.name == "ChromaticAberration": + if child.name.begins_with("Blur"): child.visible = false - if Blur == true: + if FishEye == true: + for child in get_children(): + if child.name.begins_with("FishEye"): + child.visible = true + else: + for child in get_children(): + if child.name.begins_with("FishEye"): + child.visible = false + if Vignette == true: + for child in get_children(): + if child.name.begins_with("Vignette"): + child.visible = true + else: for child in get_children(): - if child.name == "Blur": + if child.name.begins_with("Vignette"): + child.visible = false + if Glitch == true: + for child in get_children(): + if child.name.begins_with("Glitch"): child.visible = true else: for child in get_children(): - if child.name == "Blur": + if child.name.begins_with("Glitch"): child.visible = false - if Bloom == true: + if Outline == true: for child in get_children(): - if child.name == "Bloom": + if child.name.begins_with("Outline"): child.visible = true else: for child in get_children(): - if child.name == "Bloom": + if child.name.begins_with("Outline"): child.visible = false + + + +func _enter_tree(): + var ca = load("res://addons/post_processing/node/children/ChromaticAberration.tscn") + add_child(ca.instantiate()) + print("created CA") + var bl = load("res://addons/post_processing/node/children/blur.tscn") + add_child(bl.instantiate()) + print("created BL") + var feye = load("res://addons/post_processing/node/children/fish_eye.tscn") + add_child(feye.instantiate()) + print("created FEYE") + var vin = load("res://addons/post_processing/node/children/vignette.tscn") + add_child(vin.instantiate()) + print("created VIN") + var gli = load("res://addons/post_processing/node/children/glitch.tscn") + add_child(gli.instantiate()) + print("created GLI") + var out = load("res://addons/post_processing/node/children/outline.tscn") + add_child(out.instantiate()) + print("created OUT") + + + _update_shaders() + + +func _process(delta): + if Engine.is_editor_hint() or !Engine.is_editor_hint(): + _update_shaders() diff --git a/post_processing/node/post_process.svg.import b/post_processing/node/post_process.svg.import new file mode 100644 index 0000000..e5d5a75 --- /dev/null +++ b/post_processing/node/post_process.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c76ob2amhl0ln" +path="res://.godot/imported/post_process.svg-a28c497815b0e679908309d25a9b379d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/post_processing/node/post_process.svg" +dest_files=["res://.godot/imported/post_process.svg-a28c497815b0e679908309d25a9b379d.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/post_processing/plugin.gd b/post_processing/plugin.gd index f139fcb..beda896 100644 --- a/post_processing/plugin.gd +++ b/post_processing/plugin.gd @@ -3,7 +3,7 @@ extends EditorPlugin func _enter_tree(): - add_custom_type("PostProcess", "CanvasLayer", preload("res://addons/post_processing/node/post_process.gd"), preload("res://addons/post_processing/node/post_process.svg")) + add_custom_type("PostProcess", "CanvasLayer", load("res://addons/post_processing/node/post_process.gd"), load("res://addons/post_processing/node/post_process.svg")) func _exit_tree(): diff --git a/post_processing/shaders/fish_eye.gdshader b/post_processing/shaders/fish_eye.gdshader new file mode 100644 index 0000000..cdb6b9f --- /dev/null +++ b/post_processing/shaders/fish_eye.gdshader @@ -0,0 +1,49 @@ +shader_type canvas_item; +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; + + +uniform float effect_amount : hint_range(-2.5, 2.2) = 1.0; + +void fragment(){ + vec2 iResolution = 1.0 / SCREEN_PIXEL_SIZE; + vec4 fragCoord = FRAGCOORD; + + vec2 p = fragCoord.xy / iResolution.x; + + float prop = iResolution.x / iResolution.y; + + vec2 m = vec2(0.5, 0.5 / prop); + + vec2 d = p - m; + + float r = sqrt(dot(d, d)); + + float power = effect_amount; + + float bind; + + if (power > 0.0) + bind = sqrt(dot(m, m)); + else{ + if (prop < 1.0) + bind = m.x; + else + bind = m.y; + } + + vec2 uv; + + //fisheye + if (power > 0.0) + uv = m + normalize(d) * tan(r * power) * bind / tan(bind * power); + else if (power < 0.0) + uv = m + normalize(d) * atan(r * -power, 10.0) * bind / atan(-power * bind * 10.0); + //no effect for power = 1.0 + else + uv = p; + uv.y *= prop; + + vec3 col = texture(SCREEN_TEXTURE, uv).rgb; + + COLOR = vec4(col, 1.0); +} \ No newline at end of file diff --git a/post_processing/shaders/glitch.gdshader b/post_processing/shaders/glitch.gdshader new file mode 100644 index 0000000..3a453fd --- /dev/null +++ b/post_processing/shaders/glitch.gdshader @@ -0,0 +1,49 @@ +shader_type canvas_item; + +uniform float range : hint_range(0.0, 0.1, 0.005)= 0.05; +uniform float noiseQuality : hint_range(0.0, 300.0, 0.1)= 250.0; +uniform float noiseIntensity : hint_range(-0.6, 0.6, 0.0010)= 0.0088; +uniform float offsetIntensity : hint_range(-0.1, 0.1, 0.001) = 0.03; +uniform float colorOffsetIntensity : hint_range(0.0, 5.0, 0.001) = 1.3; +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture; +float rand(vec2 co) +{ + return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); +} + +float verticalBar(float pos, float UVY, float offset) +{ + float edge0 = (pos - range); + float edge1 = (pos + range); + + float x = smoothstep(edge0, pos, UVY) * offset; + x -= smoothstep(pos, edge1, UVY) * offset; + return x; +} +const float saturation = 0.2; +void fragment() +{ + vec2 uv = SCREEN_UV; + for (float i = 0.0; i < 0.71; i += 0.1313) + { + float d = mod(TIME * i, 1.7); + float o = sin(1.0 - tan(TIME * 0.24 * i)); + o *= offsetIntensity; + uv.x += verticalBar(d, UV.y, o); + } + + float UVY = uv.y; + UVY *= noiseQuality; + UVY = float(int(UVY)) * (1.0 / noiseQuality); + float noise = rand(vec2(TIME * 0.00001, UVY)); + uv.x += noise * noiseIntensity; + + vec2 offsetR = vec2(0.009 * sin(TIME), 0.0) * colorOffsetIntensity; + vec2 offsetG = vec2(0.0073 * (cos(TIME * 0.97)), 0.0) * colorOffsetIntensity; + + float r = texture(SCREEN_TEXTURE, uv + offsetR).r; + float g = texture(SCREEN_TEXTURE, uv + offsetG).g; + float b = texture(SCREEN_TEXTURE, uv).b; + vec4 tex = vec4(r, g, b, 1.0); + COLOR = tex; +} \ No newline at end of file diff --git a/post_processing/shaders/vignette.gdshader b/post_processing/shaders/vignette.gdshader new file mode 100644 index 0000000..44eb30d --- /dev/null +++ b/post_processing/shaders/vignette.gdshader @@ -0,0 +1,23 @@ +shader_type canvas_item; + +uniform float vignette_intensity = 0.4; +uniform float vignette_opacity : hint_range(0.0, 1.0) = 0.5; +uniform vec4 vignette_rgb : source_color = vec4(0.0, 0.0, 0.0, 1.0); + +uniform sampler2D screen_vec : hint_screen_texture; + +float vignette(vec2 uv){ + uv *= 1.0 - uv.xy; + float vignette = uv.x * uv.y * 15.0; + return pow(vignette, vignette_intensity * vignette_opacity); +} + +void fragment(){ + vec4 color = texture(screen_vec, SCREEN_UV); + vec4 text = texture(TEXTURE, UV); + + text.rgba *= (vignette_rgb.rgba); + text.rgba *= (1.0 - vignette(UV)); + + COLOR = vec4((text.rgb)*color.rgb,text.a); +} \ No newline at end of file