diff --git a/addons/post_processing/AboutShaders.txt b/addons/post_processing/AboutShaders.txt new file mode 100644 index 0000000..23e8859 --- /dev/null +++ b/addons/post_processing/AboutShaders.txt @@ -0,0 +1 @@ +Hey, you may notice that when exploring the /shaders/ directory there are some unused shaders, that means that they either are worked on or werent properly removed! diff --git a/addons/post_processing/assets/ascii.png b/addons/post_processing/assets/ascii.png new file mode 100644 index 0000000..f2b6acb Binary files /dev/null and b/addons/post_processing/assets/ascii.png differ diff --git a/addons/post_processing/assets/ascii.png.import b/addons/post_processing/assets/ascii.png.import new file mode 100644 index 0000000..be17bfa --- /dev/null +++ b/addons/post_processing/assets/ascii.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://5rj5tlylm7bt" +path="res://.godot/imported/ascii.png-152231094f5e4e2669cec888e3c259a5.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/post_processing/assets/ascii.png" +dest_files=["res://.godot/imported/ascii.png-152231094f5e4e2669cec888e3c259a5.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 diff --git a/addons/post_processing/assets/green_palette.png b/addons/post_processing/assets/green_palette.png new file mode 100644 index 0000000..503a34f Binary files /dev/null and b/addons/post_processing/assets/green_palette.png differ diff --git a/addons/post_processing/assets/green_palette.png.import b/addons/post_processing/assets/green_palette.png.import new file mode 100644 index 0000000..85cb6cf --- /dev/null +++ b/addons/post_processing/assets/green_palette.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dovbwkiwlo153" +path="res://.godot/imported/green_palette.png-6c780678de384f7686b5b49556c64591.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/post_processing/assets/green_palette.png" +dest_files=["res://.godot/imported/green_palette.png-6c780678de384f7686b5b49556c64591.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 diff --git a/addons/post_processing/assets/interesting_palette.png b/addons/post_processing/assets/interesting_palette.png new file mode 100644 index 0000000..18ebfbc Binary files /dev/null and b/addons/post_processing/assets/interesting_palette.png differ diff --git a/addons/post_processing/assets/interesting_palette.png.import b/addons/post_processing/assets/interesting_palette.png.import new file mode 100644 index 0000000..e346b1b --- /dev/null +++ b/addons/post_processing/assets/interesting_palette.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://nf2dcuadvrh7" +path="res://.godot/imported/interesting_palette.png-f0563a3abea2f173a022c18d0ec48433.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/post_processing/assets/interesting_palette.png" +dest_files=["res://.godot/imported/interesting_palette.png-f0563a3abea2f173a022c18d0ec48433.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 diff --git a/addons/post_processing/assets/lens_aura.png b/addons/post_processing/assets/lens_aura.png new file mode 100644 index 0000000..e97e394 Binary files /dev/null and b/addons/post_processing/assets/lens_aura.png differ diff --git a/addons/post_processing/assets/lens_aura.png.import b/addons/post_processing/assets/lens_aura.png.import new file mode 100644 index 0000000..c91b123 --- /dev/null +++ b/addons/post_processing/assets/lens_aura.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://3ee7ii2w44gd" +path="res://.godot/imported/lens_aura.png-e27f19e14a0272728e7b44bd21dd8800.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/post_processing/assets/lens_aura.png" +dest_files=["res://.godot/imported/lens_aura.png-e27f19e14a0272728e7b44bd21dd8800.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 diff --git a/addons/post_processing/assets/lens_divine.png b/addons/post_processing/assets/lens_divine.png new file mode 100644 index 0000000..b0f9838 Binary files /dev/null and b/addons/post_processing/assets/lens_divine.png differ diff --git a/addons/post_processing/assets/lens_divine.png.import b/addons/post_processing/assets/lens_divine.png.import new file mode 100644 index 0000000..4dcba9f --- /dev/null +++ b/addons/post_processing/assets/lens_divine.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dhlg318yf5dvo" +path="res://.godot/imported/lens_divine.png-f89592ebc844543be1487a3ee051ee93.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/post_processing/assets/lens_divine.png" +dest_files=["res://.godot/imported/lens_divine.png-f89592ebc844543be1487a3ee051ee93.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 diff --git a/addons/post_processing/assets/lens_flare.gd b/addons/post_processing/assets/lens_flare.gd new file mode 100644 index 0000000..ce5c59c --- /dev/null +++ b/addons/post_processing/assets/lens_flare.gd @@ -0,0 +1,35 @@ +extends CanvasLayer + +# In your main scene script + +var camera = null +var light_source = null +var light_pos_world = null +var screen_pos = null +var light_pos_screen = null +var material = null + +func _ready(): + # Get camera node automatically based on type + camera = get_tree().get_root().find_child("Camera3D", true, true) # Searches entire scene tree + if not camera: + print("Warning: No Camera node found in scene!") + return + + # Get first light node (adjust if you need a specific light) + light_source = get_tree().get_root().find_child("Light3D", true, true) # Searches entire scene tree + if not light_source: + print("Warning: No Light node found in scene!") + return + +func _physics_process(delta): + if not camera or not light_source: + return # Skip if camera or light not found + + # Calculate and set light position as before + light_pos_world = light_source.global_transform.origin + screen_pos = camera.project_world_ray(light_pos_world) + light_pos_screen = screen_pos / screen_pos.w + + material = $data.material + material.set_uniform("LightPositionWorldSpace", light_pos_screen) diff --git a/addons/post_processing/node/children/CRT.tscn b/addons/post_processing/node/children/CRT.tscn new file mode 100644 index 0000000..d562993 --- /dev/null +++ b/addons/post_processing/node/children/CRT.tscn @@ -0,0 +1,40 @@ +[gd_scene load_steps=3 format=3 uid="uid://mfrkdk8k6ojn"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/CRT.gdshader" id="1_7bog5"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_ju4eq"] +shader = ExtResource("1_7bog5") +shader_parameter/overlay = false +shader_parameter/scanlines_opacity = 0.4 +shader_parameter/scanlines_width = 0.25 +shader_parameter/grille_opacity = 0.3 +shader_parameter/resolution = Vector2(640, 480) +shader_parameter/pixelate = true +shader_parameter/roll = true +shader_parameter/roll_speed = 8.0 +shader_parameter/roll_size = 15.0 +shader_parameter/roll_variation = 1.8 +shader_parameter/distort_intensity = 0.05 +shader_parameter/noise_opacity = 0.4 +shader_parameter/noise_speed = 5.0 +shader_parameter/static_noise_intensity = 0.06 +shader_parameter/aberration = 0.03 +shader_parameter/brightness = 1.4 +shader_parameter/discolor = true +shader_parameter/warp_amount = 1.0 +shader_parameter/clip_warp = false +shader_parameter/vignette_intensity = 0.4 +shader_parameter/vignette_opacity = 0.5 + +[node name="CRT" type="CanvasLayer"] +layer = 103 +visible = false + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_ju4eq") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/ChromaticAberration.tscn b/addons/post_processing/node/children/ChromaticAberration.tscn new file mode 100644 index 0000000..0491e51 --- /dev/null +++ b/addons/post_processing/node/children/ChromaticAberration.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://ccxkudlhbgmv7"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/chromatic.gdshader" id="1_qxjen"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_ke5y5"] +shader = ExtResource("1_qxjen") +shader_parameter/offset = 5.23 + +[node name="ChromaticAberration" type="CanvasLayer"] +visible = false +layer = 102 + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_ke5y5") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/analog_monitor.tscn b/addons/post_processing/node/children/analog_monitor.tscn new file mode 100644 index 0000000..eacf31a --- /dev/null +++ b/addons/post_processing/node/children/analog_monitor.tscn @@ -0,0 +1,29 @@ +[gd_scene load_steps=3 format=3 uid="uid://ctdvjs742haos"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/analog_monitor.gdshader" id="1_yo3om"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_s1g6v"] +shader = ExtResource("1_yo3om") +shader_parameter/res = Vector2(256, 256) +shader_parameter/mask_type = 0 +shader_parameter/bloom_type = 1 +shader_parameter/hardScan = -8.0 +shader_parameter/hardPix = -2.0 +shader_parameter/hardBloomScan = -2.0 +shader_parameter/hardBloomPix = -1.5 +shader_parameter/bloomAmount = 2.12 +shader_parameter/warp = Vector2(64, 24) +shader_parameter/maskDark = 0.5 +shader_parameter/maskLight = 1.5 + +[node name="AnalogMonitor" type="CanvasLayer"] +visible = false + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_s1g6v") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/ascii.tscn b/addons/post_processing/node/children/ascii.tscn new file mode 100644 index 0000000..59f0ff0 --- /dev/null +++ b/addons/post_processing/node/children/ascii.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=4 format=3 uid="uid://k8tnsut5pohj"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/ascii.gdshader" id="1_bp3vh"] +[ext_resource type="Texture2D" uid="uid://5rj5tlylm7bt" path="res://addons/post_processing/assets/ascii.png" id="2_qs7p5"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_ppj3i"] +shader = ExtResource("1_bp3vh") +shader_parameter/ascii_size = Vector2(5, 10) +shader_parameter/available_columns = 10 +shader_parameter/max_columns = 16 +shader_parameter/ascii_tex = ExtResource("2_qs7p5") + +[node name="Ascii" type="CanvasLayer"] +layer = 99 +visible = false + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_ppj3i") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/bloom.tscn b/addons/post_processing/node/children/bloom.tscn new file mode 100644 index 0000000..fe6ab3e --- /dev/null +++ b/addons/post_processing/node/children/bloom.tscn @@ -0,0 +1,38 @@ +[gd_scene load_steps=3 format=3 uid="uid://dvpfe511myfg5"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/bloom.gdshader" id="1_qyxdw"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_qv2yl"] +shader = ExtResource("1_qyxdw") +shader_parameter/BlurAmount = null +shader_parameter/FlareThreshold = null +shader_parameter/Flares = null +shader_parameter/FlareSpacing = null +shader_parameter/Intensity = null +shader_parameter/Saturation_ = null +shader_parameter/FalloffStart = null +shader_parameter/FalloffEnd = null + +[node name="Bloom" type="CanvasLayer"] + +[node name="SubViewportContainer" type="SubViewportContainer" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +stretch = true + +[node name="SubViewport" type="SubViewport" parent="SubViewportContainer"] +handle_input_locally = false +size = Vector2i(1152, 648) +render_target_update_mode = 4 + +[node name="TextureRect" type="ColorRect" parent="."] +z_index = 105 +material = SubResource("ShaderMaterial_qv2yl") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/addons/post_processing/node/children/blur.tscn b/addons/post_processing/node/children/blur.tscn new file mode 100644 index 0000000..6b434b2 --- /dev/null +++ b/addons/post_processing/node/children/blur.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://cxsuld87nxd0v"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/blur.gdshader" id="1_6v1pv"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_efbmf"] +shader = ExtResource("1_6v1pv") +shader_parameter/lod = 4.615 + +[node name="Blur" type="CanvasLayer"] +layer = 101 +visible = false + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_efbmf") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/circular_waves.tscn b/addons/post_processing/node/children/circular_waves.tscn new file mode 100644 index 0000000..989a8b8 --- /dev/null +++ b/addons/post_processing/node/children/circular_waves.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=5 format=3 uid="uid://b0770lwctcbti"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/circularwaves.gdshader" id="1_s8hqx"] + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_mq5id"] + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_bheeo"] +noise = SubResource("FastNoiseLite_mq5id") + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_6bcgb"] +shader = ExtResource("1_s8hqx") +shader_parameter/amplitude = 0.99 +shader_parameter/frequency = 15.0 +shader_parameter/rippleRate = 7.7 +shader_parameter/waveAmplitude = 0.1 +shader_parameter/waveFrequency = 4.39 +shader_parameter/blendingAmount = 0.6 +shader_parameter/noise = SubResource("NoiseTexture2D_bheeo") + +[node name="CircularWaves" type="CanvasLayer"] +visible = false + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_6bcgb") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/color_correction.tscn b/addons/post_processing/node/children/color_correction.tscn new file mode 100644 index 0000000..e978c23 --- /dev/null +++ b/addons/post_processing/node/children/color_correction.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://q8472v8awese"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/color_correction.gdshader" id="1_cf4sj"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_nmxm8"] +shader = ExtResource("1_cf4sj") +shader_parameter/tint = Color(1, 1, 1, 1) +shader_parameter/brightness = 0.0 +shader_parameter/saturation = 0.0 + +[node name="ColorCorrection" type="CanvasLayer"] +visible = false + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_nmxm8") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/addons/post_processing/node/children/fish_eye.tscn b/addons/post_processing/node/children/fish_eye.tscn new file mode 100644 index 0000000..bf97bd7 --- /dev/null +++ b/addons/post_processing/node/children/fish_eye.tscn @@ -0,0 +1,25 @@ +[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/aspect = 1.0 +shader_parameter/distortion = 1.0 +shader_parameter/radius = 1.0 +shader_parameter/alpha = 1.0 +shader_parameter/crop = 1.0 +shader_parameter/crop_color = Color(0, 0, 0, 1) + +[node name="FishEye" type="CanvasLayer"] +layer = 103 +visible = false + +[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 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/glitch.tscn b/addons/post_processing/node/children/glitch.tscn new file mode 100644 index 0000000..a4edafd --- /dev/null +++ b/addons/post_processing/node/children/glitch.tscn @@ -0,0 +1,24 @@ +[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.05 +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 +visible = false + +[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 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/grain.tscn b/addons/post_processing/node/children/grain.tscn new file mode 100644 index 0000000..670d9ea --- /dev/null +++ b/addons/post_processing/node/children/grain.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=3 format=3 uid="uid://b2fkqs44w2304"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/grain.gdshader" id="1_wos36"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_wb4vw"] +render_priority = 0 +shader = ExtResource("1_wos36") + +[node name="Grain" type="CanvasLayer"] +visible = false + +[node name="ColorRect" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_wb4vw") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/kaleidoscope.gdshader b/addons/post_processing/node/children/kaleidoscope.gdshader new file mode 100644 index 0000000..08328b9 --- /dev/null +++ b/addons/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/addons/post_processing/node/children/outline.gdshader b/addons/post_processing/node/children/outline.gdshader new file mode 100644 index 0000000..84f453e --- /dev/null +++ b/addons/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/addons/post_processing/node/children/outline.tscn b/addons/post_processing/node/children/outline.tscn new file mode 100644 index 0000000..41833d5 --- /dev/null +++ b/addons/post_processing/node/children/outline.tscn @@ -0,0 +1,21 @@ +[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"] +visible = false + +[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 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/palette.tscn b/addons/post_processing/node/children/palette.tscn new file mode 100644 index 0000000..0d096df --- /dev/null +++ b/addons/post_processing/node/children/palette.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=3 uid="uid://b31wqmjq3q7ad"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/palette_limiter.gdshader" id="1_e4qfa"] +[ext_resource type="Texture2D" uid="uid://nf2dcuadvrh7" path="res://addons/post_processing/assets/interesting_palette.png" id="2_y1cuq"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_x8ge8"] +shader = ExtResource("1_e4qfa") +shader_parameter/palette = ExtResource("2_y1cuq") + +[node name="Palette" type="CanvasLayer"] + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_x8ge8") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/addons/post_processing/node/children/pixelate.tscn b/addons/post_processing/node/children/pixelate.tscn new file mode 100644 index 0000000..6db2a24 --- /dev/null +++ b/addons/post_processing/node/children/pixelate.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=3 format=3 uid="uid://bs1yan5h4eao8"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/pixelate.gdshader" id="1_yebq2"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_gfycf"] +shader = ExtResource("1_yebq2") +shader_parameter/pixelSize = 7 + +[node name="Pixelate" type="CanvasLayer"] +visible = false + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_gfycf") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/screen_shake.tscn b/addons/post_processing/node/children/screen_shake.tscn new file mode 100644 index 0000000..d7a8f58 --- /dev/null +++ b/addons/post_processing/node/children/screen_shake.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=3 format=3 uid="uid://b7k7vdwyhgqpd"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/screen_shake.gdshader" id="1_62rht"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_4rxg5"] +shader = ExtResource("1_62rht") +shader_parameter/ShakeStrength = 0.1 +shader_parameter/FactorA = Vector2(100, 100) +shader_parameter/FactorB = Vector2(1, 1) +shader_parameter/magnitude = Vector2(0.01, 0.01) + +[node name="ScreenShake" type="CanvasLayer"] +visible = false + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_4rxg5") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/speed_lines.tscn b/addons/post_processing/node/children/speed_lines.tscn new file mode 100644 index 0000000..ed52456 --- /dev/null +++ b/addons/post_processing/node/children/speed_lines.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=5 format=3 uid="uid://whsu0j72038r"] + +[ext_resource type="Shader" path="res://addons/post_processing/shaders/speed_lines.gdshader" id="1_2cyj1"] + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_oyufo"] +noise_type = 3 +frequency = 0.212 + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_yebuf"] +width = 1080 +height = 1080 +seamless = true +noise = SubResource("FastNoiseLite_oyufo") + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_uouvn"] +shader = ExtResource("1_2cyj1") +shader_parameter/line_color = Color(1, 1, 1, 0.768627) +shader_parameter/line_count = 2.0 +shader_parameter/line_density = 0.056 +shader_parameter/line_faloff = 0.0 +shader_parameter/mask_size = 0.333 +shader_parameter/mask_edge = 0.372 +shader_parameter/animation_speed = 20.0 +shader_parameter/noise = SubResource("NoiseTexture2D_yebuf") + +[node name="SpeedLines" type="CanvasLayer"] +visible = false + +[node name="data" type="ColorRect" parent="."] +material = SubResource("ShaderMaterial_uouvn") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 diff --git a/addons/post_processing/node/children/vignette.tscn b/addons/post_processing/node/children/vignette.tscn new file mode 100644 index 0000000..a6259aa --- /dev/null +++ b/addons/post_processing/node/children/vignette.tscn @@ -0,0 +1,21 @@ +[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"] +visible = false + +[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 +mouse_filter = 2 diff --git a/addons/post_processing/node/post_process.gd b/addons/post_processing/node/post_process.gd new file mode 100644 index 0000000..05d97b3 --- /dev/null +++ b/addons/post_processing/node/post_process.gd @@ -0,0 +1,182 @@ +@tool +extends CanvasLayer + +@export_category("Post Process") +@export var configuration : PostProcessingConfiguration +@export var dynamically_update : bool = true + +func update_shaders() -> void: + if not configuration: + return + for child in get_children(): + var data : ColorRect = child.get_child(0) + if data: + _update_shader_parameters(child.name, data.material) + child.visible = _check_shader_visibility(child.name) + return + +func _update_shader_parameters( _name : String, _material : Material) -> void: + match _name: + "Palette": + _material.set_shader_parameter("palette", configuration.PalettePalette) + "Pixelate": + _material.set_shader_parameter("pixelSize", configuration.PixelatePixelSize) + "ColorCorrection": + _material.set_shader_parameter("tint", configuration.ColorCorrectionTint) + _material.set_shader_parameter("brightness", configuration.ColorCorrectionBrightness) + _material.set_shader_parameter("saturation", configuration.ColorCorrectionSaturation) + "ChromaticAberration": + _material.set_shader_parameter("offset", configuration.StrenghtCA) + "Blur": + _material.set_shader_parameter("lod", configuration.L_O_D) + "FishEye": + _material.set_shader_parameter("aspect", configuration.FishEyeAspect) + _material.set_shader_parameter("distortion", configuration.FishEyeDistortion) + _material.set_shader_parameter("radius", configuration.FishEyeRadius) + _material.set_shader_parameter("alpha", configuration.FishEyeAlpha) + _material.set_shader_parameter("crop", configuration.FishEyeCrop) + _material.set_shader_parameter("crop_color", configuration.FishEyeCropColor) + "Vignette": + _material.set_shader_parameter("vignette_intensity", configuration.VignetteIntensity) + _material.set_shader_parameter("vignette_opacity", configuration.VignetteOpacity) + _material.set_shader_parameter("vignette_rgb", configuration.VignetteR_G_B) + "Glitch": + _material.set_shader_parameter("range", configuration.GlitchRange) + _material.set_shader_parameter("noiseQuality", configuration.GlitchNoiseQuality) + _material.set_shader_parameter("noiseIntensity", configuration.GlitchIntenity) + _material.set_shader_parameter("offsetIntensity", configuration.GlitchOffset) + _material.set_shader_parameter("colorOffsetIntensity", configuration.GlitchColorOffset) + "Outline": + _material.set_shader_parameter("edge_color", configuration.OutlineColor) + _material.set_shader_parameter("threshold", configuration.OutlineThreshold) + _material.set_shader_parameter("blend", configuration.OutlineBlend) + "ScreenShake": + _material.set_shader_parameter("ShakeStrength", configuration.ScreenShakePower) + "AnalogMonitor": + _material.set_shader_parameter("res", configuration.AnalogMonitorResolution) + "Grain": + _material.set_shader_parameter("strength", configuration.GrainPower) + "CircularWaves": + _material.set_shader_parameter("amplitude", configuration.CircularWavesAmplitude) + _material.set_shader_parameter("frequency", configuration.CircularWavesFrequency) + _material.set_shader_parameter("rippleRate", configuration.CircularWavesRippleRate) + "SpeedLines": + _material.set_shader_parameter("line_color", configuration.SpeedLinesColor) + _material.set_shader_parameter("line_count", configuration.SpeedLinesCount) + _material.set_shader_parameter("line_density", configuration.SpeedLineDensity) + _material.set_shader_parameter("animation_speed", configuration.SpeedLineSpeed) + "Ascii": + _material.set_shader_parameter("ascii_size", configuration.ASCIISize) + "CRT": + _material.set_shader_parameter("overlay", configuration.overlay) + _material.set_shader_parameter("scanlines_opacity", configuration.scanlines_opacity) + _material.set_shader_parameter("scanlines_width", configuration.scanlines_width) + _material.set_shader_parameter("grille_opacity", configuration.grille_opacity) + _material.set_shader_parameter("pixelate", configuration.pixelate) + _material.set_shader_parameter("roll_size", configuration.roll_size) + _material.set_shader_parameter("roll_variation", configuration.roll_variation) + _material.set_shader_parameter("distort_intensity", configuration.distort_intensity) + _material.set_shader_parameter("noise_opacity", configuration.noise_opacity) + _material.set_shader_parameter("noise_speed", configuration.noise_speed) + _material.set_shader_parameter("static_noise_intensity", configuration.static_noise_intensity) + _material.set_shader_parameter("aberration", configuration.aberration) + _material.set_shader_parameter("brightness", configuration.brightness) + _material.set_shader_parameter("discolor", configuration.discolor) + _material.set_shader_parameter("warp_amount", configuration.warp_amount) + _material.set_shader_parameter("clip_warp", configuration.clip_warp) + _material.set_shader_parameter("vignette_intensity", configuration.vignette_intensity) + _material.set_shader_parameter("vignette_opacity", configuration.vignette_opacity) + + +func _check_shader_visibility(_name: String) -> bool: + if _name.begins_with("Palette"): + return true if configuration.Palette else false + if _name.begins_with("Pixelate"): + return true if configuration.Pixelate else false + if _name.begins_with("ColorCorrection"): + return true if configuration.ColorCorrection else false + if _name.begins_with("ChromaticAberration"): + return true if configuration.ChromaticAberration else false + + if _name.begins_with("Blur"): + return true if configuration.Blur else false + + if _name.begins_with("FishEye"): + return true if configuration.FishEye else false + + if _name.begins_with("Vignette"): + return true if configuration.Vignette else false + + if _name.begins_with("Glitch"): + return true if configuration.Glitch else false + + if _name.begins_with("Outline"): + return true if configuration.Outline else false + + if _name.begins_with("ScreenShake"): + return true if configuration.ScreenShake else false + + if _name.begins_with("AnalogMonitor"): + return true if configuration.AnalogMonitor else false + + if _name.begins_with("Grain"): + return true if configuration.Grain else false + + if _name.begins_with("CircularWaves"): + return true if configuration.CircularWaves else false + + if _name.begins_with("SpeedLines"): + return true if configuration.SpeedLines else false + + if _name.begins_with("Ascii"): + return true if configuration.ASCII else false + + if _name.begins_with("CRT"): + return true if configuration.CRT else false + # get_children() returning all _names leading Always to: + push_error("#Undefined type Post Processing addon - verify it has been properly integrated.") + return false # bad! + +func _enter_tree(): + + _add_canvas_layer_children("res://addons/post_processing/node/children/ChromaticAberration.tscn", "CA") + _add_canvas_layer_children("res://addons/post_processing/node/children/blur.tscn", "BL") + _add_canvas_layer_children("res://addons/post_processing/node/children/fish_eye.tscn", "FEYE") + _add_canvas_layer_children("res://addons/post_processing/node/children/vignette.tscn", "VIN") + _add_canvas_layer_children("res://addons/post_processing/node/children/glitch.tscn", "GLI") + _add_canvas_layer_children("res://addons/post_processing/node/children/outline.tscn", "OUT") + _add_canvas_layer_children("res://addons/post_processing/node/children/screen_shake.tscn", "SCR_SHK") + _add_canvas_layer_children("res://addons/post_processing/node/children/analog_monitor.tscn", "ANL_MON") + _add_canvas_layer_children("res://addons/post_processing/node/children/grain.tscn", "GRN") + _add_canvas_layer_children("res://addons/post_processing/node/children/circular_waves.tscn", "CIR_WAV") + _add_canvas_layer_children("res://addons/post_processing/node/children/speed_lines.tscn", "SDP_LIN") + _add_canvas_layer_children("res://addons/post_processing/node/children/ascii.tscn", "ASCII") + _add_canvas_layer_children("res://addons/post_processing/node/children/CRT.tscn", "CRT") + _add_canvas_layer_children("res://addons/post_processing/node/children/color_correction.tscn", "CC") + _add_canvas_layer_children("res://addons/post_processing/node/children/pixelate.tscn", "PXL") + _add_canvas_layer_children("res://addons/post_processing/node/children/palette.tscn", "PLT") + + update_shaders() + +func _add_canvas_layer_children(_path : String, _name: String) -> void: + var child_instance = load(_path).instantiate() + add_child(child_instance) + var material_instance = child_instance.get_children()[0].material.duplicate() + child_instance.get_children()[0].material = material_instance + print_debug("Successfully added child canvas-layer: " + _name + " to PostProcess addon node.") + +func _process(delta): + if not configuration: + return + if Engine.is_editor_hint(): + if dynamically_update: + update_shaders() + else: + if configuration.reload: + configuration.reload = false + update_shaders() + else: + update_shaders() + if configuration.reload: + configuration.reload = false + update_shaders() diff --git a/addons/post_processing/node/post_process.svg b/addons/post_processing/node/post_process.svg new file mode 100644 index 0000000..7d0b52c --- /dev/null +++ b/addons/post_processing/node/post_process.svg @@ -0,0 +1,9 @@ + + Projekt bez nazwy (2) + + + + + + \ No newline at end of file diff --git a/addons/post_processing/node/post_process.svg.import b/addons/post_processing/node/post_process.svg.import new file mode 100644 index 0000000..bb039eb --- /dev/null +++ b/addons/post_processing/node/post_process.svg.import @@ -0,0 +1,38 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c76ob2amhl0ln" +path="res://.godot/imported/post_process.svg-a28c497815b0e679908309d25a9b379d.ctex" +metadata={ +"has_editor_variant": true, +"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=true diff --git a/addons/post_processing/plugin.cfg b/addons/post_processing/plugin.cfg new file mode 100644 index 0000000..ad4350d --- /dev/null +++ b/addons/post_processing/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="PostProcessing" +description="Simple Post Processing Plugin" +author="Korin" +version="0.1.0" +script="plugin.gd" diff --git a/addons/post_processing/plugin.gd b/addons/post_processing/plugin.gd new file mode 100644 index 0000000..beda896 --- /dev/null +++ b/addons/post_processing/plugin.gd @@ -0,0 +1,10 @@ +@tool +extends EditorPlugin + + +func _enter_tree(): + 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(): + remove_custom_type("PostProcess") diff --git a/addons/post_processing/resource/fish_eye_example.tres b/addons/post_processing/resource/fish_eye_example.tres new file mode 100644 index 0000000..d70d980 --- /dev/null +++ b/addons/post_processing/resource/fish_eye_example.tres @@ -0,0 +1,49 @@ +[gd_resource type="Resource" script_class="PostProcessingConfiguration" load_steps=2 format=3 uid="uid://dg8amcb0jcyas"] + +[ext_resource type="Script" path="res://addons/post_processing/resource/post_processing_configuration.gd" id="1_3y12k"] + +[resource] +script = ExtResource("1_3y12k") +reload = false +ASCII = false +ASCIISize = Vector2(4, 9) +ChromaticAberration = false +StrenghtCA = 1.0 +Blur = false +L_O_D = 1.0 +FishEye = true +FishEyeAspect = 1.0 +FishEyeDistortion = 0.5 +FishEyeRadius = 1.0 +FishEyeAlpha = 1.0 +FishEyeCrop = 1.0 +FishEyeCropColor = Color(0, 0, 0, 1) +Vignette = false +VignetteIntensity = 0.4 +VignetteOpacity = 0.5 +VignetteR_G_B = Color(0, 0, 0, 1) +Glitch = false +GlitchRange = 0.05 +GlitchNoiseQuality = 250.0 +GlitchIntenity = 0.0088 +GlitchOffset = 0.03 +GlitchColorOffset = 1.3 +Outline = false +OutlineColor = Color(0, 0, 0, 1) +OutlineThreshold = 0.0 +OutlineBlend = 0.01 +ScreenShake = false +ScreenShakePower = 0.1 +AnalogMonitor = false +AnalogMonitorResolution = Vector2(256, 256) +Grain = false +GrainPower = 75 +CircularWaves = false +CircularWavesAmplitude = 2.0 +CircularWavesFrequency = 12.69 +CircularWavesRippleRate = 9.2 +SpeedLines = false +SpeedLinesColor = Color(1, 1, 1, 1) +SpeedLinesCount = 2 +SpeedLineDensity = 0.072 +SpeedLineSpeed = 20 diff --git a/addons/post_processing/resource/no_effects_example.tres b/addons/post_processing/resource/no_effects_example.tres new file mode 100644 index 0000000..3348330 --- /dev/null +++ b/addons/post_processing/resource/no_effects_example.tres @@ -0,0 +1,49 @@ +[gd_resource type="Resource" script_class="PostProcessingConfiguration" load_steps=2 format=3 uid="uid://c0dsfxhwb8bwe"] + +[ext_resource type="Script" path="res://addons/post_processing/resource/post_processing_configuration.gd" id="1_6y0uy"] + +[resource] +script = ExtResource("1_6y0uy") +reload = false +ASCII = false +ASCIISize = Vector2(4, 9) +ChromaticAberration = false +StrenghtCA = 1.0 +Blur = false +L_O_D = 1.0 +FishEye = false +FishEyeAspect = 1.0 +FishEyeDistortion = 1.0 +FishEyeRadius = 1.0 +FishEyeAlpha = 1.0 +FishEyeCrop = 1.0 +FishEyeCropColor = Color(0, 0, 0, 1) +Vignette = false +VignetteIntensity = 0.4 +VignetteOpacity = 0.5 +VignetteR_G_B = Color(0, 0, 0, 1) +Glitch = false +GlitchRange = 0.05 +GlitchNoiseQuality = 250.0 +GlitchIntenity = 0.0088 +GlitchOffset = 0.03 +GlitchColorOffset = 1.3 +Outline = false +OutlineColor = Color(0, 0, 0, 1) +OutlineThreshold = 0.0 +OutlineBlend = 0.01 +ScreenShake = false +ScreenShakePower = 0.1 +AnalogMonitor = false +AnalogMonitorResolution = Vector2(256, 256) +Grain = false +GrainPower = 75 +CircularWaves = false +CircularWavesAmplitude = 2.0 +CircularWavesFrequency = 12.69 +CircularWavesRippleRate = 9.2 +SpeedLines = false +SpeedLinesColor = Color(1, 1, 1, 1) +SpeedLinesCount = 2 +SpeedLineDensity = 0.072 +SpeedLineSpeed = 20 diff --git a/addons/post_processing/resource/post_processing_configuration.gd b/addons/post_processing/resource/post_processing_configuration.gd new file mode 100644 index 0000000..f961e51 --- /dev/null +++ b/addons/post_processing/resource/post_processing_configuration.gd @@ -0,0 +1,242 @@ +class_name PostProcessingConfiguration extends Resource + +# post-processing-config based system by loufe +@export_group("Settings") +@export var reload: bool +@export_group("Visual Effects") +@export_subgroup("ASCII (No Color)") +@export var ASCII: bool +@export var ASCIISize: Vector2 = Vector2(4,9): + set(value): + ASCIISize = value + reload = true +@export_subgroup("Chromatic Aberration") +@export var ChromaticAberration: bool +@export var StrenghtCA: float = 1: + set(value): + StrenghtCA = value + reload = true +@export_subgroup("Blur") +@export var Blur: bool +@export_range(0.0, 5) var L_O_D = 1.0: + set(value): + L_O_D = value + reload = true +@export_subgroup("Fish Eye") +@export var FishEye: bool +@export var FishEyeAspect = 1.0: + set(value): + FishEyeAspect = value + reload = true +@export var FishEyeDistortion = 1.0: + set(value): + FishEyeDistortion = value + reload = true +@export var FishEyeRadius = 1.0: + set(value): + FishEyeRadius = value + reload = true +@export var FishEyeAlpha = 1.0: + set(value): + FishEyeAlpha = value + reload = true +@export var FishEyeCrop = 1.0: + set(value): + FishEyeCrop = value + reload = true +@export var FishEyeCropColor = Color.BLACK: + set(value): + FishEyeCropColor = value + reload = true +@export_subgroup("Vignette") +@export var Vignette: bool +@export var VignetteIntensity = 0.4: + set(value): + VignetteIntensity = value + reload = true +@export_range(0.0, 1.0) var VignetteOpacity = 0.5: + set(value): + VignetteOpacity = value + reload = true +@export var VignetteR_G_B: Color = Color(0.0, 0.0, 0.0, 1.0): + set(value): + VignetteR_G_B = value + reload = true +@export_subgroup("Glitch") +@export var Glitch: bool +@export_range(0.0, 0.1, 0.005) var GlitchRange = 0.05: + set(value): + GlitchRange = value + reload = true +@export_range(0.0, 300, 0.1) var GlitchNoiseQuality = 250.0: + set(value): + GlitchNoiseQuality = value + reload = true +@export_range(-0.6, 0.6, 0.0010) var GlitchIntenity = 0.0088: + set(value): + GlitchIntenity = value + reload = true +@export_range(-0.1, 0.1, 0.001) var GlitchOffset = 0.03: + set(value): + GlitchOffset = value + reload = true +@export_range(0.0, 5.0, 0.001) var GlitchColorOffset = 1.3: + set(value): + GlitchColorOffset = value + reload = true +@export_subgroup("Outline") +@export var Outline: bool +@export var OutlineColor: Color = Color(0.0, 0.0, 0.0, 1.0): + set(value): + OutlineColor = value + reload = true +@export_range(0.0, 1.0) var OutlineThreshold = 0.0: + set(value): + OutlineThreshold = value + reload = true +@export_range(0.0, 1.0) var OutlineBlend = 0.01: + set(value): + OutlineBlend = value + reload = true +@export_subgroup("Grain") +@export var Grain: bool +@export_range(0, 150, 0.1) var GrainPower = 75: + set(value): + GrainPower = value + reload = true +@export_subgroup("Circular Waves") +@export var CircularWaves: bool +@export_range(0,2, 0.01) var CircularWavesAmplitude = 2.0: + set(value): + CircularWavesAmplitude = value + reload = true +@export_range(0, 15, 0.01) var CircularWavesFrequency = 12.69: + set(value): + CircularWavesFrequency = value + reload = true +@export_range(0.5, 150.0, 0.1) var CircularWavesRippleRate = 9.2: + set(value): + CircularWavesRippleRate = value + reload = true +@export_subgroup("Speed Lines") +@export var SpeedLines: bool +@export var SpeedLinesColor: Color = Color.WHITE: + set(value): + SpeedLinesColor = value + reload = true +@export_range(0,2, 0.05) var SpeedLinesCount = 2: + set(value): + SpeedLinesCount = value + reload = true +@export_range(0.0, 1.0) var SpeedLineDensity = 0.072: + set(value): + SpeedLineDensity = value + reload = true +@export_range(1.0, 40.0, 1.0) var SpeedLineSpeed = 20: + set(value): + SpeedLineSpeed = value + reload = true + +@export_group("Display") +@export_subgroup("Color Correction") +@export var ColorCorrection: bool +@export var ColorCorrectionTint : Color +@export_range(-1.0, 1.0) var ColorCorrectionBrightness : float = 0 +@export_range(-1.0, 1.0) var ColorCorrectionSaturation : float = 0 +@export_subgroup("Palette") +@export var Palette : bool +@export var PalettePalette : Texture2D +@export_subgroup("Pixelate") +@export var Pixelate : bool +@export_range(0, 64) var PixelatePixelSize = 8 +@export_subgroup("CRT") +@export var CRT: bool +@export var overlay : bool = false: + set(value): + overlay = value + reload = true +@export_range(0.0, 1.0) var scanlines_opacity : float = 0.4: + set(value): + scanlines_opacity = value + reload = true +@export_range(0.0, 0.5) var scanlines_width : float = 0.25: + set(value): + scanlines_width = value + reload = true +@export_range(0.0, 1.0) var grille_opacity : float = 0.3: + set(value): + grille_opacity = value + reload = true +@export var pixelate : bool = true: + set(value): + pixelate = value + reload = true +@export var roll_speed : float = 8.0: + set(value): + roll_speed = value + reload = true +@export_range(0.0, 100.0) var roll_size : float = 15.0: + set(value): + roll_size = value + reload = true +@export_range(0.1, 5.0) var roll_variation : float = 1.8: + set(value): + roll_variation = value + reload = true +@export_range(0.0, 0.2) var distort_intensity : float = 0.05: + set(value): + distort_intensity = value + reload = true +@export_range(0.0, 1.0) var noise_opacity : float = 0.4: + set(value): + noise_opacity = value + reload = true +@export var noise_speed : float = 5.0: + set(value): + noise_speed = value + reload = true +@export_range(0.0, 1.0) var static_noise_intensity : float = 0.06: + set(value): + static_noise_intensity = value + reload = true +@export_range(-1.0, 1.0) var aberration : float = 0.03: + set(value): + aberration = value + reload = true +@export var brightness : float = 1.4: + set(value): + brightness = value + reload = true +@export var discolor : bool = true: + set(value): + discolor = value + reload = true +@export_range(0.0, 5.0) var warp_amount : float = 1.0: + set(value): + warp_amount = value + reload = true +@export var clip_warp : bool = false: + set(value): + clip_warp = value + reload = true +@export var vignette_intensity : float = 0.4: + set(value): + vignette_intensity = value + reload = true +@export_range(0.0, 1.0) var vignette_opacity : float = 0.5: + set(value): + vignette_opacity = value + reload = true +@export_subgroup("Analog Monitor") +@export var AnalogMonitor: bool +@export var AnalogMonitorResolution = Vector2(256, 256): + set(value): + AnalogMonitorResolution = value + reload = true +@export_group("Other") +@export_subgroup("Screen Shake") +@export var ScreenShake: bool +@export var ScreenShakePower = 0.1: + set(value): + ScreenShakePower = value + reload = true diff --git a/addons/post_processing/shaders/CLREDIT.gdshaderinc b/addons/post_processing/shaders/CLREDIT.gdshaderinc new file mode 100644 index 0000000..e69de29 diff --git a/addons/post_processing/shaders/CRT.gdshader b/addons/post_processing/shaders/CRT.gdshader new file mode 100644 index 0000000..45f6061 --- /dev/null +++ b/addons/post_processing/shaders/CRT.gdshader @@ -0,0 +1,230 @@ +/* +Shader from Godot Shaders - the free shader library. +godotshaders.com/shader/VHS-and-CRT-monitor-effect + +This shader is under CC0 license. Feel free to use, improve and +change this shader according to your needs and consider sharing +the modified result to godotshaders.com. +*/ + +shader_type canvas_item; + +//*** IMPORTANT! ***/ +// - If you are using this shader to affect the node it is applied to set 'overlay' to false (unchecked in the instepctor). +// - If you are using this shader as an overlay, and want the shader to affect the nodes below in the Scene hierarchy, +// set 'overlay' to true (checked in the inspector). +// On Mac there is potentially a bug causing this to not work properly. If that is the case and you want to use the shader as an overlay +// change all "overlay ? SCREEN_TEXTURE : TEXTURE" to only "SCREEN_TEXTURE" on lines 129-140, and "vec2 uv = overlay ? warp(SCREEN_UV) : warp(UV);" +// to "vec2 uv = warp(SCREEN_UV);" on line 98. +uniform bool overlay = false; +uniform sampler2D SCREEN_TEXTURE : source_color, hint_screen_texture, filter_nearest; + +uniform float scanlines_opacity : hint_range(0.0, 1.0) = 0.4; +uniform float scanlines_width : hint_range(0.0, 0.5) = 0.25; +uniform float grille_opacity : hint_range(0.0, 1.0) = 0.3; +uniform vec2 resolution = vec2(640.0, 480.0); // Set the number of rows and columns the texture will be divided in. Scanlines and grille will make a square based on these values + +uniform bool pixelate = true; // Fill each square ("pixel") with a sampled color, creating a pixel look and a more accurate representation of how a CRT monitor would work. + +uniform bool roll = true; +uniform float roll_speed = 8.0; // Positive values are down, negative are up +uniform float roll_size : hint_range(0.0, 100.0) = 15.0; +uniform float roll_variation : hint_range(0.1, 5.0) = 1.8; // This valie is not an exact science. You have to play around with the value to find a look you like. How this works is explained in the code below. +uniform float distort_intensity : hint_range(0.0, 0.2) = 0.05; // The distortion created by the rolling effect. + +uniform float noise_opacity : hint_range(0.0, 1.0) = 0.4; +uniform float noise_speed = 5.0; // There is a movement in the noise pattern that can be hard to see first. This sets the speed of that movement. + +uniform float static_noise_intensity : hint_range(0.0, 1.0) = 0.06; + +uniform float aberration : hint_range(-1.0, 1.0) = 0.03; // Chromatic aberration, a distortion on each color channel. +uniform float brightness = 1.4; // When adding scanline gaps and grille the image can get very dark. Brightness tries to compensate for that. +uniform bool discolor = true; // Add a discolor effect simulating a VHS + +uniform float warp_amount :hint_range(0.0, 5.0) = 1.0; // Warp the texture edges simulating the curved glass of a CRT monitor or old TV. +uniform bool clip_warp = false; + +uniform float vignette_intensity = 0.4; // Size of the vignette, how far towards the middle it should go. +uniform float vignette_opacity : hint_range(0.0, 1.0) = 0.5; + +// Used by the noise functin to generate a pseudo random value between 0.0 and 1.0 +vec2 random(vec2 uv){ + uv = vec2( dot(uv, vec2(127.1,311.7) ), + dot(uv, vec2(269.5,183.3) ) ); + return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123); +} + +// Generate a Perlin noise used by the distortion effects +float noise(vec2 uv) { + vec2 uv_index = floor(uv); + vec2 uv_fract = fract(uv); + + vec2 blur = smoothstep(0.0, 1.0, uv_fract); + + return mix( mix( dot( random(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), + dot( random(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), + mix( dot( random(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), + dot( random(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) * 0.5 + 0.5; +} + +// Takes in the UV and warps the edges, creating the spherized effect +vec2 warp(vec2 uv){ + vec2 delta = uv - 0.5; + float delta2 = dot(delta.xy, delta.xy); + float delta4 = delta2 * delta2; + float delta_offset = delta4 * warp_amount; + + return uv + delta * delta_offset; +} + +// Adds a black border to hide stretched pixel created by the warp effect +float border (vec2 uv){ + float radius = min(warp_amount, 0.08); + radius = max(min(min(abs(radius * 2.0), abs(1.0)), abs(1.0)), 1e-5); + vec2 abs_uv = abs(uv * 2.0 - 1.0) - vec2(1.0, 1.0) + radius; + float dist = length(max(vec2(0.0), abs_uv)) / radius; + float square = smoothstep(0.96, 1.0, dist); + return clamp(1.0 - square, 0.0, 1.0); +} + +// Adds a vignette shadow to the edges of the image +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() +{ + vec2 uv = overlay ? warp(SCREEN_UV) : warp(UV); // Warp the uv. uv will be used in most cases instead of UV to keep the warping + vec2 text_uv = uv; + vec2 roll_uv = vec2(0.0); + float time = roll ? TIME : 0.0; + + + // Pixelate the texture based on the given resolution. + if (pixelate) + { + text_uv = ceil(uv * resolution) / resolution; + } + + // Create the rolling effect. We need roll_line a bit later to make the noise effect. + // That is why this runs if roll is true OR noise_opacity is over 0. + float roll_line = 0.0; + if (roll || noise_opacity > 0.0) + { + // Create the areas/lines where the texture will be distorted. + roll_line = smoothstep(0.3, 0.9, sin(uv.y * roll_size - (time * roll_speed) ) ); + // Create more lines of a different size and apply to the first set of lines. This creates a bit of variation. + roll_line *= roll_line * smoothstep(0.3, 0.9, sin(uv.y * roll_size * roll_variation - (time * roll_speed * roll_variation) ) ); + // Distort the UV where where the lines are + roll_uv = vec2(( roll_line * distort_intensity * (1.-UV.x)), 0.0); + } + + vec4 text; + if (roll) + { + // If roll is true distort the texture with roll_uv. The texture is split up into RGB to + // make some chromatic aberration. We apply the aberration to the red and green channels accorging to the aberration parameter + // and intensify it a bit in the roll distortion. + text.r = texture(SCREEN_TEXTURE, text_uv + roll_uv * 0.8 + vec2(aberration, 0.0) * .1).r; + text.g = texture(SCREEN_TEXTURE, text_uv + roll_uv * 1.2 - vec2(aberration, 0.0) * .1 ).g; + text.b = texture(SCREEN_TEXTURE, text_uv + roll_uv).b; + text.a = 1.0; + } + else + { + // If roll is false only apply the aberration without any distorion. The aberration values are very small so the .1 is only + // to make the slider in the Inspector less sensitive. + text.r = texture(SCREEN_TEXTURE, text_uv + vec2(aberration, 0.0) * .1).r; + text.g = texture(SCREEN_TEXTURE, text_uv - vec2(aberration, 0.0) * .1).g; + text.b = texture(SCREEN_TEXTURE, text_uv).b; + text.a = 1.0; + } + + float r = text.r; + float g = text.g; + float b = text.b; + + uv = warp(UV); + + // CRT monitors don't have pixels but groups of red, green and blue dots or lines, called grille. We isolate the texture's color channels + // and divide it up in 3 offsetted lines to show the red, green and blue colors next to each other, with a small black gap between. + if (grille_opacity > 0.0){ + + float g_r = smoothstep(0.85, 0.95, abs(sin(uv.x * (resolution.x * 3.14159265)))); + r = mix(r, r * g_r, grille_opacity); + + float g_g = smoothstep(0.85, 0.95, abs(sin(1.05 + uv.x * (resolution.x * 3.14159265)))); + g = mix(g, g * g_g, grille_opacity); + + float b_b = smoothstep(0.85, 0.95, abs(sin(2.1 + uv.x * (resolution.x * 3.14159265)))); + b = mix(b, b * b_b, grille_opacity); + + } + + // Apply the grille to the texture's color channels and apply Brightness. Since the grille and the scanlines (below) make the image very dark you + // can compensate by increasing the brightness. + text.r = clamp(r * brightness, 0.0, 1.0); + text.g = clamp(g * brightness, 0.0, 1.0); + text.b = clamp(b * brightness, 0.0, 1.0); + + // Scanlines are the horizontal lines that make up the image on a CRT monitor. + // Here we are actual setting the black gap between each line, which I guess is not the right definition of the word, but you get the idea + float scanlines = 0.5; + if (scanlines_opacity > 0.0) + { + // Same technique as above, create lines with sine and applying it to the texture. Smoothstep to allow setting the line size. + scanlines = smoothstep(scanlines_width, scanlines_width + 0.5, abs(sin(uv.y * (resolution.y * 3.14159265)))); + text.rgb = mix(text.rgb, text.rgb * vec3(scanlines), scanlines_opacity); + } + + // Apply the banded noise. + if (noise_opacity > 0.0) + { + // Generate a noise pattern that is very stretched horizontally, and animate it with noise_speed + float noise = smoothstep(0.4, 0.5, noise(uv * vec2(2.0, 200.0) + vec2(10.0, (TIME * (noise_speed))) ) ); + + // We use roll_line (set above) to define how big the noise should be vertically (multiplying cuts off all black parts). + // We also add in some basic noise with random() to break up the noise pattern above. The noise is sized according to + // the resolution value set in the inspector. If you don't like this look you can + // change "ceil(uv * resolution) / resolution" to only "uv" to make it less pixelated. Or multiply resolution with som value + // greater than 1.0 to make them smaller. + roll_line *= noise * scanlines * clamp(random((ceil(uv * resolution) / resolution) + vec2(TIME * 0.8, 0.0)).x + 0.8, 0.0, 1.0); + // Add it to the texture based on noise_opacity + text.rgb = clamp(mix(text.rgb, text.rgb + roll_line, noise_opacity), vec3(0.0), vec3(1.0)); + } + + // Apply static noise by generating it over the whole screen in the same way as above + if (static_noise_intensity > 0.0) + { + text.rgb += clamp(random((ceil(uv * resolution) / resolution) + fract(TIME)).x, 0.0, 1.0) * static_noise_intensity; + } + + // Apply a black border to hide imperfections caused by the warping. + // Also apply the vignette + text.rgb *= border(uv); + text.rgb *= vignette(uv); + // Hides the black border and make that area transparent. Good if you want to add the the texture on top an image of a TV or monitor. + if (clip_warp) + { + text.a = border(uv); + } + + // Apply discoloration to get a VHS look (lower saturation and higher contrast) + // You can play with the values below or expose them in the Inspector. + float saturation = 0.5; + float contrast = 1.2; + if (discolor) + { + // Saturation + vec3 greyscale = vec3(text.r + text.g + text.b) / 3.; + text.rgb = mix(text.rgb, greyscale, saturation); + + // Contrast + float midpoint = pow(0.5, 2.2); + text.rgb = (text.rgb - vec3(midpoint)) * contrast + midpoint; + } + + COLOR = text; +} \ No newline at end of file diff --git a/addons/post_processing/shaders/LensFlares.gdshader b/addons/post_processing/shaders/LensFlares.gdshader new file mode 100644 index 0000000..e908e46 --- /dev/null +++ b/addons/post_processing/shaders/LensFlares.gdshader @@ -0,0 +1,93 @@ +shader_type canvas_item; +render_mode blend_mix; + +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; + +uniform vec2 sun_position = vec2(0.0); +uniform vec3 tint = vec3(1.4,1.2,1.0); +uniform sampler2D noise_texture; + +float noise_float(float t, vec2 texResolution) +{ + return texture(noise_texture,vec2(t,0.0)/texResolution).x; +} +float noise_vec2(vec2 t, vec2 texResolution) +{ + return texture(noise_texture,t/texResolution).x; +} + +vec3 lensflare(vec2 uv,vec2 pos, vec2 texResolution) +{ + vec2 main = uv-pos; + vec2 uvd = uv*(length(uv)); + + float ang = atan(main.x,main.y); + float dist = length(main); + dist = pow(dist,0.1); + + float n = noise_vec2(vec2(ang*16.0,dist*32.0), texResolution); + + // Do not need an artificial sun + //float f0 = 1.0/(length(uv-pos)*16.0+1.0); + //f0 = f0 + f0*(sin(noise_float(sin(ang*2.+pos.x)*4.0 - cos(ang*3.+pos.y), texResolution)*16.)*.1 + dist*.1 + .8); + + float f1 = max(0.01-pow(length(uv+1.2*pos),1.9),.0)*7.0; + + float f2 = max(1.0/(1.0+32.0*pow(length(uvd+0.8*pos),2.0)),.0)*00.25; + float f22 = max(1.0/(1.0+32.0*pow(length(uvd+0.85*pos),2.0)),.0)*00.23; + float f23 = max(1.0/(1.0+32.0*pow(length(uvd+0.9*pos),2.0)),.0)*00.21; + + vec2 uvx = mix(uv,uvd,-0.5); + + float f4 = max(0.01-pow(length(uvx+0.4*pos),2.4),.0)*6.0; + float f42 = max(0.01-pow(length(uvx+0.45*pos),2.4),.0)*5.0; + float f43 = max(0.01-pow(length(uvx+0.5*pos),2.4),.0)*3.0; + + uvx = mix(uv,uvd,-.4); + + float f5 = max(0.01-pow(length(uvx+0.2*pos),5.5),.0)*2.0; + float f52 = max(0.01-pow(length(uvx+0.4*pos),5.5),.0)*2.0; + float f53 = max(0.01-pow(length(uvx+0.6*pos),5.5),.0)*2.0; + + uvx = mix(uv,uvd,-0.5); + + float f6 = max(0.01-pow(length(uvx-0.3*pos),1.6),.0)*6.0; + float f62 = max(0.01-pow(length(uvx-0.325*pos),1.6),.0)*3.0; + float f63 = max(0.01-pow(length(uvx-0.35*pos),1.6),.0)*5.0; + + vec3 c = vec3(.0); + + c.r+=f2+f4+f5+f6; c.g+=f22+f42+f52+f62; c.b+=f23+f43+f53+f63; + c = c*1.3 - vec3(length(uvd)*.05); + + // Do not need an artificial sun + //c+=vec3(f0); + + return c; +} + +vec3 cc(vec3 color, float factor,float factor2) // color modifier +{ + float w = color.x+color.y+color.z; + return mix(color,vec3(w)*factor,w*factor2); +} + +void fragment() +{ + vec2 texResolution = 1.0 / TEXTURE_PIXEL_SIZE; + vec2 resolution = 1.0 / SCREEN_PIXEL_SIZE; + + vec2 uv = FRAGCOORD.xy / resolution.xy - 0.5; + uv.x *= resolution.x/resolution.y; //fix aspect ratio + vec2 mouse = (sun_position.xy / resolution.xy) - vec2(0.5, 0.5); + mouse.x *= resolution.x / resolution.y; //fix aspect ratio + + vec4 previousColor = texture(SCREEN_TEXTURE, SCREEN_UV); + + vec3 color = previousColor.rgb; + + color += tint * lensflare(uv, mouse.xy, texResolution); + color -= noise_vec2(FRAGCOORD.xy, texResolution)*.015; + color = cc(color,.5,.1); + COLOR = vec4(color,1.0); +} \ No newline at end of file diff --git a/addons/post_processing/shaders/analog_monitor.gdshader b/addons/post_processing/shaders/analog_monitor.gdshader new file mode 100644 index 0000000..da32851 --- /dev/null +++ b/addons/post_processing/shaders/analog_monitor.gdshader @@ -0,0 +1,278 @@ +//SHADER ORIGINALY CREADED BY "TimothyLottes" FROM SHADERTOY +//PORTED AND MODIFYED TO GODOT BY AHOPNESS (@ahopness) +//LICENSE : CC0 +//COMATIBLE WITH : GLES2, GLES3, WEBGL +//SHADERTOY LINK : https://www.shadertoy.com/view/MsjXzh + +// PUBLIC DOMAIN CRT STYLED SCAN-LINE SHADER +// +// by Timothy Lottes +// +// This is more along the style of a really good CGA arcade monitor. +// With RGB inputs instead of NTSC. +// The shadow mask example has the mask rotated 90 degrees for less chromatic aberration. +// +// Left it unoptimized to show the theory behind the algorithm. +// +// It is an example what I personally would want as a display option for pixel art games. +// Please take and use, change, or whatever. + +shader_type canvas_item; + +// Emulated input resolution. +uniform vec2 res; + +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; + +// Mask type +// 0 = Very compressed TV style shadow mask +// 1 = Stretched VGA style shadow mask (same as prior shaders) +// 2 = VGA style shadow mask +uniform int mask_type :hint_range(0, 2) = 0; + +// Bloom Type +// 0 = Normalized exposure +// 1 = Aditive bloom +// 2 = No Bloom +uniform int bloom_type :hint_range(0, 2) = 0; + +// Hardness of scanline. +// -8.0 = soft +// -16.0 = medium +uniform float hardScan :hint_range(-12.0, -1.0) = -8.0; + +// Hardness of pixels in scanline. +// -2.0 = soft +// -4.0 = hard +uniform float hardPix :hint_range(-4.0, 0.0) = -2.0; + +// Hardness of short vertical bloom. +// -1.0 = wide to the point of clipping (bad) +// -1.5 = wide +// -4.0 = not very wide at all +uniform float hardBloomScan :hint_range(-4.0, 0.0) = -2.0; + +// Hardness of short horizontal bloom. +// -0.5 = wide to the point of clipping (bad) +// -1.0 = wide +// -2.0 = not very wide at all +uniform float hardBloomPix :hint_range(-2.0, 0.0) = -1.5; + +// Amount of small bloom effect. +// 1.0/1.0 = only bloom +// 1.0/16.0 = what I think is a good amount of small bloom +// 0.0 = no bloom +uniform float bloomAmount :hint_range(1.0, 16.0) = 16.0; + +// Display warp. +// 0.0 = none +// 1.0/8.0 = extreme +uniform vec2 warp = vec2(64.0, 24.0); + +// Amount of shadow mask. +uniform float maskDark :hint_range(0.0, 1.0) = 0.5; +uniform float maskLight :hint_range(1.0, 2.0) = 1.5; + +//------------------------------------------------------------------------ + +// sRGB to Linear. +// Assuing using sRGB typed textures this should not be needed. +float ToLinear1(float c){ return(c <= 0.04045) ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4); } +vec3 ToLinear(vec3 c){ return vec3(ToLinear1(c.r), ToLinear1(c.g), ToLinear1(c.b)); } + +// Linear to sRGB. +// Assuing using sRGB typed textures this should not be needed. +float ToSrgb1(float c){ return(c < 0.0031308?c * 12.92 : 1.055 * pow(c, 0.41666) - 0.055); } +vec3 ToSrgb(vec3 c){ return vec3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b)); } + +// Nearest emulated sample given floating point position and texel offset. +// Also zero's off screen. +vec3 Fetch(vec2 pos, vec2 off, sampler2D iChannel0){ + pos = floor(pos * res + off) / res; + + if(max(abs(pos.x - 0.5), abs(pos.y - 0.5)) > 0.5){ + return vec3(0.0, 0.0, 0.0); + } + + return ToLinear(texture(iChannel0 , pos.xy , -16.0).rgb); +} + +// Distance in emulated pixels to nearest texel. +vec2 Dist(vec2 pos){ + pos = pos * res; + return - ((pos - floor(pos)) - vec2(0.5)); +} + +// 1D Gaussian. +float Gaus(float pos, float scale){ return exp2(scale * pos * pos); } + +// 3-tap Gaussian filter along horz line. +vec3 Horz3(vec2 pos, float off, sampler2D iChannel0){ + vec3 b = Fetch(pos, vec2(-1.0, off), iChannel0); + vec3 c = Fetch(pos, vec2( 0.0, off), iChannel0); + vec3 d = Fetch(pos, vec2( 1.0, off), iChannel0); + float dst = Dist(pos).x; + + // Convert distance to weight. + float scale = hardPix; + float wb = Gaus(dst - 1.0, scale); + float wc = Gaus(dst + 0.0, scale); + float wd = Gaus(dst + 1.0, scale); + + // Return filtered sample. + return (b * wb + c * wc + d * wd) / (wb + wc + wd); +} +// 5-tap Gaussian filter along horz line. +vec3 Horz5(vec2 pos, float off, sampler2D iChannel0){ + vec3 a = Fetch(pos, vec2(-2.0, off), iChannel0); + vec3 b = Fetch(pos, vec2(-1.0, off), iChannel0); + vec3 c = Fetch(pos, vec2( 0.0, off), iChannel0); + vec3 d = Fetch(pos, vec2( 1.0, off), iChannel0); + vec3 e = Fetch(pos, vec2( 2.0, off), iChannel0); + float dst = Dist(pos).x; + + // Convert distance to weight. + float scale = hardPix; + float wa = Gaus(dst - 2.0, scale); + float wb = Gaus(dst - 1.0, scale); + float wc = Gaus(dst + 0.0, scale); + float wd = Gaus(dst + 1.0, scale); + float we = Gaus(dst + 2.0, scale); + + // Return filtered sample. + return (a * wa + b * wb + c * wc + d * wd + e * we) / (wa + wb + wc + wd + we); +} +// 7-tap Gaussian filter along horz line. +vec3 Horz7(vec2 pos, float off, sampler2D iChannel0){ + vec3 a = Fetch(pos, vec2(-3.0, off), iChannel0); + vec3 b = Fetch(pos, vec2(-2.0, off), iChannel0); + vec3 c = Fetch(pos, vec2( 1.0, off), iChannel0); + vec3 d = Fetch(pos, vec2( 0.0, off), iChannel0); + vec3 e = Fetch(pos, vec2( 1.0, off), iChannel0); + vec3 f = Fetch(pos, vec2( 2.0, off), iChannel0); + vec3 g = Fetch(pos, vec2( 3.0, off), iChannel0); + float dst = Dist(pos).x; + + // Convert distance to weight. + float scale = hardBloomPix; + float wa = Gaus(dst - 3.0, scale); + float wb = Gaus(dst - 2.0, scale); + float wc = Gaus(dst - 1.0, scale); + float wd = Gaus(dst + 0.0, scale); + float we = Gaus(dst + 1.0, scale); + float wf = Gaus(dst + 2.0, scale); + float wg = Gaus(dst + 3.0, scale); + + // Return filtered sample. + return (a * wa + b * wb + c * wc + d * wd + e * we + f * wf + g * wg) / (wa + wb + wc + wd + we + wf + wg); +} + +// Return scanline weight. +float Scan(vec2 pos, float off){ + float dst = Dist(pos).y; + + return Gaus(dst + off, hardScan); +} + +// Return scanline weight for bloom. +float BloomScan(vec2 pos, float off){ + float dst = Dist(pos).y; + + return Gaus(dst + off, hardBloomScan); +} + +// Allow nearest three lines to effect pixel. +vec3 Tri(vec2 pos, sampler2D iChannel0){ + vec3 a = Horz3(pos,-1.0, iChannel0); + vec3 b = Horz5(pos, 0.0, iChannel0); + vec3 c = Horz3(pos, 1.0, iChannel0); + + float wa = Scan(pos,-1.0); + float wb = Scan(pos, 0.0); + float wc = Scan(pos, 1.0); + + return a * wa + b * wb + c * wc; +} + +// Small bloom. +vec3 Bloom(vec2 pos, sampler2D iChannel0){ + vec3 a = Horz5(pos,-2.0, iChannel0); + vec3 b = Horz7(pos,-1.0, iChannel0); + vec3 c = Horz7(pos, 0.0, iChannel0); + vec3 d = Horz7(pos, 1.0, iChannel0); + vec3 e = Horz5(pos, 2.0, iChannel0); + + float wa = BloomScan(pos,-2.0); + float wb = BloomScan(pos,-1.0); + float wc = BloomScan(pos, 0.0); + float wd = BloomScan(pos, 1.0); + float we = BloomScan(pos, 2.0); + + return a * wa + b * wb + c * wc + d * wd + e * we; +} + +// Distortion of scanlines, and end of screen alpha. +vec2 Warp(vec2 pos){ + pos = pos * 2.0 - 1.0; + pos *= vec2(1.0 + (pos.y * pos.y) * 1.0 / warp.x, 1.0 + (pos.x * pos.x) * 1.0/ warp.y); + + return pos * 0.5+0.5; +} + +vec3 Mask(vec2 pos){ + if (mask_type == 0){ + float line = maskLight; + float odd = 0.0; + + if(fract(pos.x / 6.0) < 0.5) odd = 1.0; + if(fract((pos.y + odd) / 2.0) < 0.5) line = maskDark; + pos.x = fract(pos.x / 3.0); + + vec3 mask = vec3(maskDark, maskDark, maskDark); + if(pos.x < 0.333)mask.r = maskLight; + else if(pos.x < 0.666)mask.g = maskLight; + else mask.b = maskLight; + + mask *= line; + return mask; + }else if (mask_type == 1){ + pos.x += pos.y * 3.0; + + vec3 mask = vec3(maskDark, maskDark, maskDark); + pos.x = fract(pos.x / 6.0); + if(pos.x < 0.333)mask.r = maskLight; + else if(pos.x < 0.666)mask.g = maskLight; + else mask.b = maskLight; + + return mask; + }else if (mask_type == 2){ + pos.xy = floor(pos.xy * vec2(1.0, 0.5)); + pos.x += pos.y * 3.0; + + vec3 mask = vec3(maskDark, maskDark, maskDark); + pos.x = fract(pos.x / 6.0); + if(pos.x < 0.333)mask.r = maskLight; + else if(pos.x < 0.666)mask.g = maskLight; + else mask.b = maskLight; + + return mask; + } + } + +// Draw dividing bars. +float Bar(float pos, float bar){ pos -= bar; return pos * pos < 4.0 ? 0.0 : 1.0; } + +// Entry. +void fragment(){ + vec2 pos = Warp(FRAGCOORD.xy / (1.0 / SCREEN_PIXEL_SIZE).xy); + + COLOR.rgb = Tri(pos, SCREEN_TEXTURE) * Mask(FRAGCOORD.xy); + if (bloom_type == 0){ + COLOR.rgb = mix(COLOR.rgb,Bloom(pos, SCREEN_TEXTURE), 1.0 / bloomAmount); + }else if (bloom_type == 1){ + COLOR.rgb += Bloom(pos, SCREEN_TEXTURE) * 1.0 / bloomAmount; + } + + COLOR.a = 1.0; + COLOR.rgb = ToSrgb(COLOR.rgb); +} \ No newline at end of file diff --git a/addons/post_processing/shaders/ascii.gdshader b/addons/post_processing/shaders/ascii.gdshader new file mode 100644 index 0000000..ad2baa1 --- /dev/null +++ b/addons/post_processing/shaders/ascii.gdshader @@ -0,0 +1,37 @@ +/* + アスキー文字エフェクトシェーダー by あるる(きのもと 結衣) @arlez80 + Ascii Effect Shader by Yui Kinomoto @arlez80 + + MIT License +*/ + +shader_type canvas_item; +render_mode unshaded; + +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; + +const vec3 MONOCHROME_SCALE = vec3( 0.298912, 0.586611, 0.114478 ); + +uniform sampler2D ascii_tex : source_color; +uniform vec2 ascii_size = vec2( 8.0, 16.0 ); +uniform int available_columns = 10; +uniform int max_columns = 16; + +void fragment( ) +{ + vec2 screen_uv = floor( SCREEN_UV / SCREEN_PIXEL_SIZE / ascii_size ) * SCREEN_PIXEL_SIZE * ascii_size; + vec2 diff = ascii_size * SCREEN_PIXEL_SIZE; + vec4 color = ( + textureLod( SCREEN_TEXTURE, screen_uv, 0.0 ) + + textureLod( SCREEN_TEXTURE, screen_uv + vec2( 0.0, diff.y ), 0.0 ) + + textureLod( SCREEN_TEXTURE, screen_uv + vec2( diff.x, 0.0 ), 0.0 ) + + textureLod( SCREEN_TEXTURE, screen_uv + diff, 0.0 ) + ) / 4.0; + + vec2 ascii_uv = fract( SCREEN_UV / SCREEN_PIXEL_SIZE / ascii_size ); + ascii_uv.x = ( 1.0 - ascii_uv.x ) / float( max_columns ); + float col = floor( dot( color.rgb, MONOCHROME_SCALE ) * float( available_columns ) ) / float( available_columns ); + + COLOR = texture( ascii_tex, ascii_uv + vec2( col * ( float( available_columns ) / float( max_columns ) ), 0.0 ) ); +} + diff --git a/addons/post_processing/shaders/bloom.gdshader b/addons/post_processing/shaders/bloom.gdshader new file mode 100644 index 0000000..6139b44 --- /dev/null +++ b/addons/post_processing/shaders/bloom.gdshader @@ -0,0 +1,53 @@ +shader_type canvas_item; +render_mode blend_add; + +#include "CLREDIT.gdshaderinc" + +uniform lowp sampler2D Screen_Sample : hint_screen_texture, filter_linear_mipmap_anisotropic; +uniform lowp sampler2D FlareTex; // Texture for the lens flare + +uniform float BlurAmount; // Adjust blur intensity +uniform float FlareThreshold; // Threshold for brightness to consider flare +uniform int Flares; // Number of lens flares +uniform float FlareSpacing; // Separation between flares +uniform float Intensity; // Overall intensity of the effect +uniform float Saturation_; // Adjust color saturation (optional) +uniform float FalloffStart; // Controls falloff start distance from center (0-1) +uniform float FalloffEnd; // Controls falloff end distance from center (0-1) + +void fragment() { + //UV = SCREEN_UV; + + // Sample the scene color + vec3 SceneColor = texture(Screen_Sample, UV).rgb; + + // Calculate direction vector from screen center (static) + vec2 FlareDir = vec2(0.5) - UV; + + // Accumulate flare color with falloff + vec3 FinalFlare = vec3(0.0); + for (int i = 0; i < Flares; ++i) { + // Offset UV based on flare direction and index + vec2 SampleUV = fract(UV + FlareDir * (BlurAmount + vec2(float(i) * FlareSpacing))); + + // Sample the scene with blur in flare direction + vec3 BlurredScene = texture(Screen_Sample, SampleUV, BlurAmount).rgb; + + // Apply threshold to filter out dark areas + BlurredScene = ApplyThreshold(BlurredScene, FlareThreshold); // Adjust threshold as needed (optional) + + // Calculate distance from center for falloff + float Dist = distance(SampleUV, vec2(0.5)); + float Falloff = smoothstep(FalloffStart, FalloffEnd, Dist); + + // Apply weight and accumulate flare color + FinalFlare += BlurredScene * Falloff; + } + + // Apply lens flare texture + FinalFlare *= texture(FlareTex, UV).rgb; + + // Apply intensity and optional saturation adjustment + COLOR.rgb = FinalFlare * Intensity; + COLOR.rgb = Saturation(COLOR.rgb, Saturation_); // Adjust saturation as needed (optional) +} diff --git a/addons/post_processing/shaders/blur.gdshader b/addons/post_processing/shaders/blur.gdshader new file mode 100644 index 0000000..84b6f85 --- /dev/null +++ b/addons/post_processing/shaders/blur.gdshader @@ -0,0 +1,10 @@ +shader_type canvas_item; + +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; + +uniform float lod: hint_range(0.0, 5) = 0.0; + +void fragment(){ + vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV, lod); + COLOR = color; +} \ No newline at end of file diff --git a/addons/post_processing/shaders/chromatic.gdshader b/addons/post_processing/shaders/chromatic.gdshader new file mode 100644 index 0000000..147409a --- /dev/null +++ b/addons/post_processing/shaders/chromatic.gdshader @@ -0,0 +1,12 @@ +shader_type canvas_item; + +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture; + +uniform float offset = 1; + +void fragment(){ + vec4 green_channel = texture(SCREEN_TEXTURE, SCREEN_UV); + vec4 red_channel = texture(SCREEN_TEXTURE, vec2(SCREEN_UV.x + (offset * SCREEN_PIXEL_SIZE.x), SCREEN_UV.y)); + vec4 blue_channel = texture(SCREEN_TEXTURE, vec2(SCREEN_UV.x - (offset * SCREEN_PIXEL_SIZE.x), SCREEN_UV.y)); + COLOR = vec4(red_channel.r, green_channel.g, blue_channel.b, 1); +} \ No newline at end of file diff --git a/addons/post_processing/shaders/circularwaves.gdshader b/addons/post_processing/shaders/circularwaves.gdshader new file mode 100644 index 0000000..439f571 --- /dev/null +++ b/addons/post_processing/shaders/circularwaves.gdshader @@ -0,0 +1,50 @@ +shader_type canvas_item; + +// for circles +uniform float amplitude: hint_range(0, 2, 0.01) = 2.0; +uniform float frequency: hint_range(0, 15, 0.01) = 12.69; +uniform float rippleRate : hint_range(0.5, 150.0, 0.1) = 9.2; + + +// for wave +uniform float waveAmplitude = 0.1; +uniform float waveFrequency = 4.0; +uniform float blendingAmount = 0.6; + + +// other +uniform sampler2D noise; + + + +vec2 wave(vec2 uv, float time) { + return vec2( + uv.x + sin(uv.y * waveFrequency * 5.0 + time) * waveAmplitude, + uv.y + sin(uv.x * waveFrequency + time) * waveAmplitude + ); +} + +void fragment() { + vec2 wave_uv = wave(UV, TIME); + vec4 ns = texture(noise, wave_uv); + + vec2 motion = vec2(0.0, 1.0); + float pi = 3.14159265358979323846; + vec2 uv = UV * 2.0 - 1.0; + + float dist = length(uv); + ns *= 1.4142135; + dist += -0.1 * ns.x; + float ripple = sin(dist * -frequency * pi + rippleRate * TIME) * amplitude / (dist + 1.0); + + + vec4 color = vec4(1.0, 1.0, 1.0, 2.0 * ripple); + + float alphaScalar = (1.0 - min(dist, 1.0)) * ns.x * 2.5; + + + color.a *= 1.0 * alphaScalar * (ripple + ns.x * ns.y); + color.a = max(color.a - (ns.y * 0.45), 0.0); + + COLOR = color; +} \ No newline at end of file diff --git a/addons/post_processing/shaders/color_correction.gdshader b/addons/post_processing/shaders/color_correction.gdshader new file mode 100644 index 0000000..b289438 --- /dev/null +++ b/addons/post_processing/shaders/color_correction.gdshader @@ -0,0 +1,19 @@ +shader_type canvas_item; + +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear; +uniform vec4 tint : source_color = vec4(1, 1, 1, 1); +uniform float brightness : hint_range(-1.0, 1.0) = 0; +uniform float saturation : hint_range(-1.0, 1.0) = 0; + +void fragment(){ + vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV); + vec4 final_col = color * tint; + final_col.rgb = final_col.rgb + brightness; + + float avg_col = (final_col.r + final_col.g + final_col.b) / 3.0; + vec3 sat_color = mix(vec3(avg_col), final_col.rgb, 1.0 + saturation); + + final_col.rgb = clamp(sat_color, 0.0, 1.0); + + COLOR = final_col; +} \ No newline at end of file diff --git a/addons/post_processing/shaders/dither.gdshader b/addons/post_processing/shaders/dither.gdshader new file mode 100644 index 0000000..f93bc33 --- /dev/null +++ b/addons/post_processing/shaders/dither.gdshader @@ -0,0 +1,76 @@ +/* +This shader is under MIT license. Feel free to use, improve and +change this shader according to your needs and consider sharing +the modified result to godotshaders.com. +*/ + +shader_type canvas_item; + +uniform sampler2D u_dither_tex; +uniform sampler2D u_color_tex; + +uniform int u_bit_depth; +uniform float u_contrast; +uniform float u_offset; +uniform int u_dither_size; + +void fragment() +{ + // sample the screen texture at the desired output resolution (according to u_dither_size) + // this will effectively pixelate the resulting output + vec2 screen_size = vec2(textureSize(TEXTURE, 0)) / float(u_dither_size); + vec2 screen_sample_uv = floor(UV * screen_size) / screen_size; + vec3 screen_col = texture(TEXTURE, screen_sample_uv).rgb; + + // calculate pixel luminosity (https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color) + float lum = (screen_col.r * 0.299) + (screen_col.g * 0.587) + (screen_col.b * 0.114); + + // adjust with contrast and offset parameters + float contrast = u_contrast; + lum = (lum - 0.5 + u_offset) * contrast + 0.5; + lum = clamp(lum, 0.0, 1.0); + + // reduce luminosity bit depth to give a more banded visual if desired + float bits = float(u_bit_depth); + lum = floor(lum * bits) / bits; + + // to support multicolour palettes, we want to dither between the two colours on the palette + // which are adjacent to the current pixel luminosity. + // to do this, we need to determine which 'band' lum falls into, calculate the upper and lower + // bound of that band, then later we will use the dither texture to pick either the upper or + // lower colour. + + // get the palette texture size mapped so it is 1px high (so the x value however many colour bands there are) + ivec2 col_size = textureSize(u_color_tex, 0); + col_size /= col_size.y; + + float col_x = float(col_size.x) - 1.0; // colour boundaries is 1 less than the number of colour bands + float col_texel_size = 1.0 / col_x; // the size of one colour boundary + + lum = max(lum - 0.00001, 0.0); // makes sure our floor calculation below behaves when lum == 1.0 + float lum_lower = floor(lum * col_x) * col_texel_size; + float lum_upper = (floor(lum * col_x) + 1.0) * col_texel_size; + float lum_scaled = lum * col_x - floor(lum * col_x); // calculates where lum lies between the upper and lower bound + + // map the dither texture onto the screen. there are better ways of doing this that makes the dither pattern 'stick' + // with objects in the 3D world, instead of being mapped onto the screen. see lucas pope's details posts on how he + // achieved this in Obra Dinn: https://forums.tigsource.com/index.php?topic=40832.msg1363742#msg1363742 + ivec2 noise_size = textureSize(u_dither_tex, 0); + vec2 inv_noise_size = vec2(1.0 / float(noise_size.x), 1.0 / float(noise_size.y)); + vec2 noise_uv = UV * inv_noise_size * vec2(float(screen_size.x), float(screen_size.y)); + float threshold = texture(u_dither_tex, noise_uv).r; + + // adjust the dither slightly so min and max aren't quite at 0.0 and 1.0 + // otherwise we wouldn't get fullly dark and fully light dither patterns at lum 0.0 and 1.0 + threshold = threshold * 0.99 + 0.005; + + // the lower lum_scaled is, the fewer pixels will be below the dither threshold, and thus will use the lower bound colour, + // and vice-versa + float ramp_val = lum_scaled < threshold ? 0.0f : 1.0f; + // sample at the lower bound colour if ramp_val is 0.0, upper bound colour if 1.0 + float col_sample = mix(lum_lower, lum_upper, ramp_val); + vec3 final_col = texture(u_color_tex, vec2(col_sample, 0.5)).rgb; + + // return the final colour! + COLOR.rgb = final_col; +} \ No newline at end of file diff --git a/addons/post_processing/shaders/fish_eye.gdshader b/addons/post_processing/shaders/fish_eye.gdshader new file mode 100644 index 0000000..8ccfe15 --- /dev/null +++ b/addons/post_processing/shaders/fish_eye.gdshader @@ -0,0 +1,49 @@ +///////////////////////////////// +// 2D Radial Distortion Shader // +///////////////////////////////// + +// Screen space shader for Godot, based on: https://gist.github.com/aggregate1166877/a889083801d67917c26c12a98e7f57a7 + +shader_type canvas_item; + +uniform float aspect = 1.0; +uniform float distortion = 1.0; +uniform float radius = 1.0; +uniform float alpha = 1.0; +uniform float crop = 1.0; +uniform vec4 crop_color : source_color = vec4(0,0,0,1); +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; + +vec2 distort(vec2 p) +{ + float d = length(p); + float z = sqrt(distortion + d * d * -distortion); + float r = atan(d, z) / 3.1415926535; + float phi = atan(p.y, p.x); + return vec2(r * cos(phi) * (1.0 / aspect) + 0.5, r * sin(phi) + 0.5); +} + +void fragment() +{ + vec2 xy = (SCREEN_UV * 2.0 - 1.0); // move origin of UV coordinates to center of screen + + xy = vec2(xy.x * aspect, xy.y); // adjust aspect ratio + + float d = length(xy); // distance from center + + vec4 tex; + + if (d < radius) + { + xy = distort(xy); + tex = texture(SCREEN_TEXTURE, xy); + COLOR = tex; + COLOR.a = alpha; + } + + // radial crop + if (d > crop) + { + COLOR = crop_color; + } +} \ No newline at end of file diff --git a/addons/post_processing/shaders/glitch.gdshader b/addons/post_processing/shaders/glitch.gdshader new file mode 100644 index 0000000..3a453fd --- /dev/null +++ b/addons/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/addons/post_processing/shaders/grain.gdshader b/addons/post_processing/shaders/grain.gdshader new file mode 100644 index 0000000..9b1f43b --- /dev/null +++ b/addons/post_processing/shaders/grain.gdshader @@ -0,0 +1,20 @@ +shader_type canvas_item; +// set max strength to your liking here=20.0, step_size=0.1 +uniform float strength:hint_range(0, 159.0, 0.1)=75; + +void fragment() { + + // Screen Color + vec4 screen = texture(TEXTURE, SCREEN_UV); + vec2 iResolution = 1.0 / SCREEN_PIXEL_SIZE; + vec2 uv = FRAGCOORD.xy / iResolution.xy; + + // Random noise + float x = (uv.x + 4.0 ) * (uv.y + 4.0 ) * (TIME * 10.0); + // Add grain to Screen + screen = screen+vec4(mod((mod(x, 13.0) ) * (mod(x, 123.0) ), 0.01)-0.005) * strength; + + screen = 1.0 - screen; + COLOR = screen; + +} \ No newline at end of file diff --git a/addons/post_processing/shaders/painted.gdshader b/addons/post_processing/shaders/painted.gdshader new file mode 100644 index 0000000..844cf46 --- /dev/null +++ b/addons/post_processing/shaders/painted.gdshader @@ -0,0 +1,20 @@ +shader_type canvas_item; + +uniform sampler2D flowMap; //Displacement map +uniform float strength; //Force of the effect +uniform float speed; //Speed of the effect +uniform int frames : hint_range(1, 10); //Frames of the effect +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear; + +//Returns a value between 0 and 1 depending of the frames -> exemple: frames = 4, frame 1 = 0.25 +float clock(float time){ + float fframes = float(frames); + return floor(mod(time * speed, fframes)) / fframes; +} + +void fragment(){ + float c = clock(TIME); //Get clock frame + vec4 offset = texture(flowMap, vec2(SCREEN_UV.x + c, SCREEN_UV.y + c)) * strength; //Get offset + //COLOR = texture(TEXTURE, vec2(UV.x,UV.y) + normal.xy); //Apply offset + COLOR = texture(SCREEN_TEXTURE, vec2(SCREEN_UV.x,SCREEN_UV.y) + offset.xy - vec2(0.5,0.5)*strength); //We need to remove the displacement +} \ No newline at end of file diff --git a/addons/post_processing/shaders/palette_limiter.gdshader b/addons/post_processing/shaders/palette_limiter.gdshader new file mode 100644 index 0000000..b9e5795 --- /dev/null +++ b/addons/post_processing/shaders/palette_limiter.gdshader @@ -0,0 +1,33 @@ +// Godot 4 Adapt To Palette Shader +shader_type canvas_item; + +uniform sampler2D palette: filter_nearest; +uniform sampler2D screen_texture: hint_screen_texture, filter_nearest; + +void fragment() { + float best_diff = 4.00; + ivec2 pal_size = textureSize(palette, 0); + + // Palette row scan + for (int y = 0; y < pal_size.y; y += 1) + { + // Palette column scan + for (int x = 0; x < pal_size.x; x += 1) + { + vec3 scr_pix = texture(screen_texture, SCREEN_UV).rgb; + vec3 pal_pix = texelFetch(palette, ivec2(x, y), 0).rgb; + + // Slightly faster than distance() + float this_diff = ( + abs(scr_pix.r - pal_pix.r) + + abs(scr_pix.g - pal_pix.g) + + abs(scr_pix.b - pal_pix.b)); + + if (this_diff < best_diff) + { + best_diff = this_diff; + COLOR.rgb = pal_pix.rgb; + } + } + } +} \ No newline at end of file diff --git a/addons/post_processing/shaders/pixelate.gdshader b/addons/post_processing/shaders/pixelate.gdshader new file mode 100644 index 0000000..2590b3a --- /dev/null +++ b/addons/post_processing/shaders/pixelate.gdshader @@ -0,0 +1,23 @@ +shader_type canvas_item; + +uniform int pixelSize = 4; +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear; + +void fragment() +{ + + ivec2 size = textureSize(SCREEN_TEXTURE, 0); + + int xRes = size.x; + int yRes = size.y; + + float xFactor = float(xRes) / float(pixelSize); + float yFactor = float(yRes) / float(pixelSize); + + float grid_uv_x = round(SCREEN_UV.x * xFactor) / xFactor; + float grid_uv_y = round(SCREEN_UV.y * yFactor) / yFactor; + + vec4 text = texture(SCREEN_TEXTURE, vec2(grid_uv_x, grid_uv_y)); + + COLOR = text; +} \ No newline at end of file diff --git a/addons/post_processing/shaders/post_process.svg b/addons/post_processing/shaders/post_process.svg new file mode 100644 index 0000000..7d0b52c --- /dev/null +++ b/addons/post_processing/shaders/post_process.svg @@ -0,0 +1,9 @@ + + Projekt bez nazwy (2) + + + + + + \ No newline at end of file diff --git a/addons/post_processing/shaders/post_process.svg.import b/addons/post_processing/shaders/post_process.svg.import new file mode 100644 index 0000000..f90fda1 --- /dev/null +++ b/addons/post_processing/shaders/post_process.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b6ml16b2jkbl2" +path="res://.godot/imported/post_process.svg-b065ed97f6998946e1ca98a22c2e2b81.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/post_processing/shaders/post_process.svg" +dest_files=["res://.godot/imported/post_process.svg-b065ed97f6998946e1ca98a22c2e2b81.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/addons/post_processing/shaders/screen_shake.gdshader b/addons/post_processing/shaders/screen_shake.gdshader new file mode 100644 index 0000000..e3241da --- /dev/null +++ b/addons/post_processing/shaders/screen_shake.gdshader @@ -0,0 +1,24 @@ +/* + Camera Shake Effect Shader by @Near + + MIT License +*/ + +shader_type canvas_item; +uniform float ShakeStrength = 0; +uniform vec2 FactorA = vec2(100.0,100.0); +uniform vec2 FactorB = vec2(1.0,1.0); +uniform vec2 magnitude = vec2(0.01,0.01); +uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; + +void fragment() { + vec2 uv = SCREEN_UV; + uv -= 0.5; + uv *= 1.0 - 2.0 * magnitude.x; + uv += 0.5; + vec2 dt = vec2(0.0, 0.0); + dt.x = sin(TIME * FactorA.x+FactorB.x) * magnitude.x; + dt.y = cos(TIME *FactorA.y+ FactorB.y) * magnitude.y; + COLOR = texture(SCREEN_TEXTURE,uv + (dt*ShakeStrength)); +} + diff --git a/addons/post_processing/shaders/speed_lines.gdshader b/addons/post_processing/shaders/speed_lines.gdshader new file mode 100644 index 0000000..6367c9c --- /dev/null +++ b/addons/post_processing/shaders/speed_lines.gdshader @@ -0,0 +1,59 @@ +shader_type canvas_item; + + +uniform sampler2D noise: repeat_enable; +uniform vec4 line_color: source_color; +uniform float line_count: hint_range(0.0, 2.0, 0.05) = 2; +uniform float line_density: hint_range(0.0, 1.0) = 0.56; +uniform float line_faloff: hint_range(0.0, 1.0) = 0; +uniform float mask_size: hint_range(0.0, 1.0) = 0.333; +uniform float mask_edge: hint_range(0.0, 1.0) = 0.372; +uniform float animation_speed: hint_range(1.0, 20.0) = 20; + + + + +float inv_lerp(float from, float to, float value){ + return (value - from) / (to - from); +} + + + + +vec2 polar_coordinates(vec2 uv, vec2 center, float zoom, float repeat) +{ + vec2 dir = uv - center; + float radius = length(dir) * 2.0; + float angle = atan(dir.y, dir.x) * 1.0/(PI * 2.0); + return mod(vec2(radius * zoom, angle * repeat), 1.0); +} + + + + +vec2 rotate_uv(vec2 uv, vec2 pivot, float rotation) { + float cosa = cos(rotation); + float sina = sin(rotation); + uv -= pivot; + return vec2( + cosa * uv.x - sina * uv.y, + cosa * uv.y + sina * uv.x + ) + pivot; +} + + + + +void fragment(){ + vec2 polar_uv = polar_coordinates(rotate_uv(UV, vec2(0.5), floor(fract(TIME) * animation_speed) ) , vec2(0.5), 0.01, line_count); + vec3 lines = texture(noise, polar_uv).rgb; + + float mask_value = length(UV - vec2(0.5)); + float mask = inv_lerp(mask_size, mask_edge, mask_value); + float result = 1.0 - (mask * line_density); + + result = smoothstep(result, result + line_faloff, lines.r); + + COLOR.rgb = vec3(line_color.rgb); + COLOR.a = min(line_color.a, result); +} \ No newline at end of file diff --git a/addons/post_processing/shaders/vignette.gdshader b/addons/post_processing/shaders/vignette.gdshader new file mode 100644 index 0000000..44eb30d --- /dev/null +++ b/addons/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 diff --git a/addons/post_processing/shaders/water.gdshader b/addons/post_processing/shaders/water.gdshader new file mode 100644 index 0000000..6c4a921 --- /dev/null +++ b/addons/post_processing/shaders/water.gdshader @@ -0,0 +1,48 @@ +shader_type canvas_item; + +uniform float first_stage : hint_range(0.0, 1.0) = 0.5; +uniform float first_smooth : hint_range(0.0, 1.0) = 0.0; // Lengthens the color transition +uniform float second_stage : hint_range(0.0, 1.0) = 0.0; // If left at 0, only level 1 is used. +uniform float second_smooth : hint_range(0.0, 1.0) = 0.0; +uniform float min_light : hint_range(0.0, 1.0) = 0.0; +uniform float mid_light : hint_range(0.0, 1.0) = 0.0; +uniform float max_light : hint_range(0.0, 1.0) = 1.0; +uniform float obj_light_add : hint_range(0.0, 1.0) = 0.0; + +float light_calc(float light_strength, float would_be_strength) { + float target_strength = light_strength + would_be_strength * obj_light_add; + if (target_strength == 0.0) {target_strength = 0.000001;} + if (would_be_strength == 0.0) {would_be_strength = 1.0;} + return(target_strength / would_be_strength); +} + +void light() { + float level_1 = first_stage; + float level_1_smooth = first_smooth; + float level_2 = second_stage; + float level_2_smooth = second_smooth; + + float mid_range_light = mid_light; + if (mid_light == 0.0) { mid_range_light = max_light * 0.5; } + vec3 light_normal = normalize(vec3(LIGHT_VEC, -LIGHT_HEIGHT)); + float would_be_strength = max(dot(-light_normal, NORMAL), 0.0); + if (would_be_strength > level_1 && level_2 == 0.0 ) { + float diff = smoothstep(level_1, (level_1 + level_1_smooth), would_be_strength) + min_light; + if (diff >= max_light) {diff = max_light;} + LIGHT *= light_calc(diff, would_be_strength); + } else if (would_be_strength > level_1 && would_be_strength < level_2 && level_2 != 0.0 ) { + float diff = smoothstep(level_1, (level_1 + level_1_smooth), would_be_strength) + min_light; + if (diff >= mid_range_light ) {diff = mid_range_light;} + LIGHT *= light_calc(diff, would_be_strength); + } else if (would_be_strength >= level_2 && level_2 != 0.0 ) { + float diff = smoothstep(level_2, (level_2 + level_2_smooth), would_be_strength) + mid_range_light; + if (diff < mid_range_light ) {diff = mid_range_light;} + if (diff >= max_light) {diff = max_light;} + LIGHT *= light_calc(diff, would_be_strength); + } else { + if (min_light != 0.0) { + LIGHT_VEC = -NORMAL.xy*length(LIGHT_VEC); + } + LIGHT *= min_light; + } +} \ No newline at end of file