From cac890d6deb5df043be27451f28d688bfa1584d5 Mon Sep 17 00:00:00 2001 From: Mario Brandao Date: Fri, 15 Dec 2023 09:06:36 +0100 Subject: [PATCH] A mirage? --- camera-effects.tscn | 29 +++++++++- camera-effects/chromatic-aberration.gdshader | 12 +++- camera-effects/chromatic_aberration.tscn | 4 +- camera-effects/mirage.gdshader | 14 +++++ camera-effects/under-water.gdshader | 60 ++++++++++++++++++++ camera-effects/under_water.tscn | 20 +++++++ 6 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 camera-effects/mirage.gdshader create mode 100644 camera-effects/under-water.gdshader create mode 100644 camera-effects/under_water.tscn diff --git a/camera-effects.tscn b/camera-effects.tscn index b351024..dccb069 100644 --- a/camera-effects.tscn +++ b/camera-effects.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=3 uid="uid://c051w6upl0t16"] +[gd_scene load_steps=21 format=3 uid="uid://c051w6upl0t16"] [ext_resource type="Script" path="res://camera-effects/camera-effects-scene.gd" id="1_ct3xk"] [ext_resource type="PackedScene" uid="uid://bvk23npqj2u2a" path="res://commons/halloween_village.tscn" id="2_8870h"] @@ -7,7 +7,9 @@ [ext_resource type="PackedScene" uid="uid://ds5xw2us1br3q" path="res://camera-effects/vignette.tscn" id="9_q1phu"] [ext_resource type="PackedScene" uid="uid://dv3o1u4hc11vn" path="res://camera-effects/sepia.tscn" id="10_rqewe"] [ext_resource type="PackedScene" uid="uid://cf1adbox8xy7e" path="res://camera-effects/grain_noise.tscn" id="11_3qobw"] +[ext_resource type="PackedScene" uid="uid://dfy4v47aijqqp" path="res://camera-effects/under_water.tscn" id="12_76kh0"] [ext_resource type="PackedScene" path="res://camera-effects/hexagon_mosaic.tscn" id="12_uvrob"] +[ext_resource type="Shader" path="res://camera-effects/mirage.gdshader" id="13_rl5nt"] [ext_resource type="PackedScene" path="res://camera-effects/camera_shake.tscn" id="14_qhoe5"] [ext_resource type="Texture2D" uid="uid://etnwfy334jt" path="res://addons/kenney_particle_pack/window_03.png" id="14_ydbvf"] [ext_resource type="PackedScene" uid="uid://kli822acdl5m" path="res://camera-effects/blur.tscn" id="15_kmr3r"] @@ -17,6 +19,11 @@ [sub_resource type="Environment" id="Environment_tln01"] glow_blend_mode = 4 +[sub_resource type="ShaderMaterial" id="ShaderMaterial_03j04"] +shader = ExtResource("13_rl5nt") +shader_parameter/blur_amount = 0.9 +shader_parameter/strength = 0.01 + [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_24bae"] bg_color = Color(0.278431, 0, 0.141176, 0.392157) @@ -66,6 +73,7 @@ light_energy = 2.0 unique_name_in_owner = true [node name="Chromatic Aberration" parent="Effects" instance=ExtResource("7_uoado")] +visible = false [node name="Pixelate" parent="Effects" instance=ExtResource("8_fshcg")] visible = false @@ -91,6 +99,17 @@ visible = false [node name="Fish Eye" parent="Effects" instance=ExtResource("16_nmfpv")] visible = false +[node name="Under Water" parent="Effects" instance=ExtResource("12_76kh0")] +visible = false + +[node name="Mirage" type="ColorRect" parent="Effects"] +material = SubResource("ShaderMaterial_03j04") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + [node name="CanvasLayer UI" type="CanvasLayer" parent="."] [node name="SideBar" type="HBoxContainer" parent="CanvasLayer UI"] @@ -194,6 +213,13 @@ toggle_mode = true button_group = ExtResource("16_r0ag1") text = "Fish Eye" +[node name="Button Under Water" type="Button" parent="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 24 +toggle_mode = true +button_group = ExtResource("16_r0ag1") +text = "Under Water" + [node name="ToggleButton" type="TextureButton" parent="CanvasLayer UI/SideBar"] custom_minimum_size = Vector2(64, 2.08165e-12) layout_mode = 2 @@ -237,4 +263,5 @@ libraries = { [connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonCameraShake" to="." method="updateVisibleEffects"] [connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/ButtonBlur" to="." method="updateVisibleEffects"] [connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/Button Fish Eye" to="." method="updateVisibleEffects"] +[connection signal="toggled" from="CanvasLayer UI/SideBar/SideBar Menu/MarginContainer/VBoxContainer/Button Under Water" to="." method="updateVisibleEffects"] [connection signal="pressed" from="CanvasLayer UI/SideBar/ToggleButton" to="." method="toggleSideBar"] diff --git a/camera-effects/chromatic-aberration.gdshader b/camera-effects/chromatic-aberration.gdshader index f49c112..9c81d72 100644 --- a/camera-effects/chromatic-aberration.gdshader +++ b/camera-effects/chromatic-aberration.gdshader @@ -4,12 +4,18 @@ shader_type canvas_item; uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear; uniform float strength = 20.0; +uniform float focus_radius : hint_range(0.0, 1.0) = 0.0; +uniform float focus_edge : hint_range(0.0, 1.0) = 0.0; void fragment() { - vec2 ca_offset = vec2(strength, 0.0) * SCREEN_PIXEL_SIZE; - float red = texture(SCREEN_TEXTURE, SCREEN_UV - ca_offset).r; + vec2 CENTER = vec2(0.5, 0.5); + float d = distance(SCREEN_UV, CENTER); + float within_radius = smoothstep(focus_radius, focus_radius + focus_edge, d); + + vec2 offset = vec2(strength * within_radius, 0.0) * SCREEN_PIXEL_SIZE; + float red = texture(SCREEN_TEXTURE, SCREEN_UV - offset).r; float green = texture(SCREEN_TEXTURE, SCREEN_UV).g; - float blue = texture(SCREEN_TEXTURE, SCREEN_UV + ca_offset).b; + float blue = texture(SCREEN_TEXTURE, SCREEN_UV + offset).b; COLOR = vec4(red, green, blue, 1.0); } diff --git a/camera-effects/chromatic_aberration.tscn b/camera-effects/chromatic_aberration.tscn index fe47c1b..b8915d2 100644 --- a/camera-effects/chromatic_aberration.tscn +++ b/camera-effects/chromatic_aberration.tscn @@ -4,7 +4,9 @@ [sub_resource type="ShaderMaterial" id="ShaderMaterial_bla75"] shader = ExtResource("1_qe316") -shader_parameter/ca_strength = 20.0 +shader_parameter/strength = 20.0 +shader_parameter/focus_radius = 0.0 +shader_parameter/focus_edge = 0.0 [node name="Chromatic Aberration" type="ColorRect"] material = SubResource("ShaderMaterial_bla75") diff --git a/camera-effects/mirage.gdshader b/camera-effects/mirage.gdshader new file mode 100644 index 0000000..a13fbb8 --- /dev/null +++ b/camera-effects/mirage.gdshader @@ -0,0 +1,14 @@ +shader_type canvas_item; + +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; +uniform float blur_amount : hint_range(-2.0, 10.0) = .2; +uniform float strength : hint_range(0.0, 1.0) = .01; + +void fragment() { + float yFromCenter = 1.0 - abs(UV.y - .5); + float blurImpact = blur_amount * yFromCenter; + vec2 uv = vec2(SCREEN_UV.x + sin(yFromCenter) * strength, SCREEN_UV.y); + vec4 blurred = textureLod(SCREEN_TEXTURE, uv, blurImpact); + + COLOR = blurred; +} diff --git a/camera-effects/under-water.gdshader b/camera-effects/under-water.gdshader new file mode 100644 index 0000000..3a16759 --- /dev/null +++ b/camera-effects/under-water.gdshader @@ -0,0 +1,60 @@ +shader_type canvas_item; + +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; + +uniform float speed : hint_range(0.0, 5.0) = .5; +uniform float strength : hint_range(0.0, 1.0) = .5; +uniform float intensity : hint_range(0.0, 1.0) = .5; +uniform int maximumIterations : hint_range(0, 10) = 5; +uniform bool showTiling = false; +uniform bool showYellowLine = false; + +// source: https://www.shadertoy.com/view/MdlXz8 + +#define TAU 6.28318530718 + +void fragment() { + float time = TIME * speed + 23.0; + // uv should be the 0-1 uv of texture... + vec2 iResolution = 1.0 / SCREEN_PIXEL_SIZE; + vec2 uv = FRAGCOORD.xy / iResolution.xy; + + vec2 p; + if (showTiling) { + p = mod(uv*TAU*2.0, TAU) - 250.0; + } else { + p = mod(uv*TAU, TAU) - 250.0; + } + + vec2 i = vec2(p); + float c = 1.0; + float inten = intensity / 100.0; + + for (int n = 0; n < maximumIterations; n++) + { + float t = time * (1.0 - (3.5 / float(n+1))); + i = p + vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x)); + c += 1.0/length(vec2(p.x / (sin(i.x+t)/inten),p.y / (cos(i.y+t)/inten))); + } + c /= float(maximumIterations); + c = 1.17-pow(c, 1.4); + vec3 colour = vec3(pow(abs(c), 8.0)); + colour = clamp(colour + vec3(0.0, 0.35, 0.5), 0.0, 1.0); + + if (showTiling) { + // Flash tile borders... + vec2 pixel = 2.0 / iResolution.xy; + uv *= 2.0; + float f = floor(mod(TIME * speed, 2.0)); // Flash value. + vec2 first = step(pixel, uv) * f; // Rule out first screen pixels and flash. + uv = step(fract(uv), pixel); // Add one line of pixels per tile. + + if (showYellowLine) + colour = mix(colour, vec3(1.0, 1.0, 0.0), (uv.x + uv.y) * first.x * first.y); // Yellow line + } + + vec4 pixelColor = texture(SCREEN_TEXTURE, UV); + vec3 appliedColor = mix(pixelColor.rgb, colour, strength); + + COLOR = vec4(appliedColor, 1.0); +} diff --git a/camera-effects/under_water.tscn b/camera-effects/under_water.tscn new file mode 100644 index 0000000..fea5fd7 --- /dev/null +++ b/camera-effects/under_water.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://dfy4v47aijqqp"] + +[ext_resource type="Shader" path="res://camera-effects/under-water.gdshader" id="1_ufumj"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_mmpr8"] +shader = ExtResource("1_ufumj") +shader_parameter/speed = 0.5 +shader_parameter/strength = 0.5 +shader_parameter/intensity = 0.5 +shader_parameter/maximumIterations = 5 +shader_parameter/showTiling = true +shader_parameter/showYellowLine = false + +[node name="Under Water" type="ColorRect"] +material = SubResource("ShaderMaterial_mmpr8") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2