From 23dd10b4207be33b46e9a61c46d840890fc354d5 Mon Sep 17 00:00:00 2001 From: Korin <92170697+ItsKorin@users.noreply.github.com> Date: Wed, 8 May 2024 23:15:07 +0200 Subject: [PATCH] Add files via upload --- addons/post_processing/AboutShaders.txt | 1 + .../node/children/color_correction.tscn | 20 +++++ .../node/children/pixelate.tscn | 18 +++++ addons/post_processing/node/post_process.gd | 24 ++++-- .../node/post_process.svg.import | 3 +- addons/post_processing/plugin.cfg | 2 +- .../resource/post_processing_configuration.gd | 67 ++++++++-------- .../shaders/color_correction.gdshader | 19 +++++ .../post_processing/shaders/dither.gdshader | 76 +++++++++++++++++++ .../post_processing/shaders/painted.gdshader | 20 +++++ .../post_processing/shaders/pixelate.gdshader | 23 ++++++ .../post_processing/shaders/post_process.svg | 9 +++ .../shaders/post_process.svg.import | 37 +++++++++ 13 files changed, 281 insertions(+), 38 deletions(-) create mode 100644 addons/post_processing/AboutShaders.txt create mode 100644 addons/post_processing/node/children/color_correction.tscn create mode 100644 addons/post_processing/node/children/pixelate.tscn create mode 100644 addons/post_processing/shaders/color_correction.gdshader create mode 100644 addons/post_processing/shaders/dither.gdshader create mode 100644 addons/post_processing/shaders/painted.gdshader create mode 100644 addons/post_processing/shaders/pixelate.gdshader create mode 100644 addons/post_processing/shaders/post_process.svg create mode 100644 addons/post_processing/shaders/post_process.svg.import 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/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/pixelate.tscn b/addons/post_processing/node/children/pixelate.tscn new file mode 100644 index 0000000..7d80af0 --- /dev/null +++ b/addons/post_processing/node/children/pixelate.tscn @@ -0,0 +1,18 @@ +[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 diff --git a/addons/post_processing/node/post_process.gd b/addons/post_processing/node/post_process.gd index 45e160f..601de5c 100644 --- a/addons/post_processing/node/post_process.gd +++ b/addons/post_processing/node/post_process.gd @@ -17,6 +17,12 @@ func update_shaders() -> void: func _update_shader_parameters( _name : String, _material : Material) -> void: match _name: + "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": @@ -81,7 +87,10 @@ func _update_shader_parameters( _name : String, _material : Material) -> void: func _check_shader_visibility(_name: String) -> bool: - + 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 @@ -139,6 +148,8 @@ func _enter_tree(): _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") update_shaders() @@ -153,11 +164,14 @@ func _process(delta): if not configuration: return if Engine.is_editor_hint(): - return - if not dynamically_update: - return + if dynamically_update: + update_shaders() + else: + if configuration.reload: + configuration.reload = false + update_shaders() else: update_shaders() if configuration.reload: - update_shaders() configuration.reload = false + update_shaders() diff --git a/addons/post_processing/node/post_process.svg.import b/addons/post_processing/node/post_process.svg.import index e5d5a75..bb039eb 100644 --- a/addons/post_processing/node/post_process.svg.import +++ b/addons/post_processing/node/post_process.svg.import @@ -5,6 +5,7 @@ type="CompressedTexture2D" uid="uid://c76ob2amhl0ln" path="res://.godot/imported/post_process.svg-a28c497815b0e679908309d25a9b379d.ctex" metadata={ +"has_editor_variant": true, "vram_texture": false } @@ -34,4 +35,4 @@ 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 +editor/convert_colors_with_editor_theme=true diff --git a/addons/post_processing/plugin.cfg b/addons/post_processing/plugin.cfg index e799a72..8091abd 100644 --- a/addons/post_processing/plugin.cfg +++ b/addons/post_processing/plugin.cfg @@ -3,5 +3,5 @@ name="PostProcessing" description="Simple Post Processing Plugin" author="Korin" -version="" +version="0.0.9" script="plugin.gd" diff --git a/addons/post_processing/resource/post_processing_configuration.gd b/addons/post_processing/resource/post_processing_configuration.gd index 8bb282d..f68dec9 100644 --- a/addons/post_processing/resource/post_processing_configuration.gd +++ b/addons/post_processing/resource/post_processing_configuration.gd @@ -1,27 +1,28 @@ class_name PostProcessingConfiguration extends Resource # post-processing-config based system by loufe -@export_group("Post Processing") +@export_group("Settings") @export var reload: bool -@export_group("ASCII (No Color)") +@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_group("Chromatic Aberration") +@export_subgroup("Chromatic Aberration") @export var ChromaticAberration: bool @export var StrenghtCA: float = 1: set(value): StrenghtCA = value reload = true -@export_group("Blur") +@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_group("Fish Eye") +@export_subgroup("Fish Eye") @export var FishEye: bool @export var FishEyeAspect = 1.0: set(value): @@ -47,7 +48,7 @@ class_name PostProcessingConfiguration extends Resource set(value): FishEyeCropColor = value reload = true -@export_group("Vignette") +@export_subgroup("Vignette") @export var Vignette: bool @export var VignetteIntensity = 0.4: set(value): @@ -61,7 +62,7 @@ class_name PostProcessingConfiguration extends Resource set(value): VignetteR_G_B = value reload = true -@export_group("Glitch") +@export_subgroup("Glitch") @export var Glitch: bool @export_range(0.0, 0.1, 0.005) var GlitchRange = 0.05: set(value): @@ -83,7 +84,7 @@ class_name PostProcessingConfiguration extends Resource set(value): GlitchColorOffset = value reload = true -@export_group("Outline") +@export_subgroup("Outline") @export var Outline: bool @export var OutlineColor: Color = Color(0.0, 0.0, 0.0, 1.0): set(value): @@ -97,25 +98,13 @@ class_name PostProcessingConfiguration extends Resource set(value): OutlineBlend = value reload = true -@export_group("Screen Shake") -@export var ScreenShake: bool -@export var ScreenShakePower = 0.1: - set(value): - ScreenShakePower = value - reload = true -@export_group("Analog Monitor") -@export var AnalogMonitor: bool -@export var AnalogMonitorResolution = Vector2(256, 256): - set(value): - AnalogMonitorResolution = value - reload = true -@export_group("Grain") +@export_subgroup("Grain") @export var Grain: bool @export_range(0, 150, 0.1) var GrainPower = 75: set(value): GrainPower = value reload = true -@export_group("Circular Waves") +@export_subgroup("Circular Waves") @export var CircularWaves: bool @export_range(0,2, 0.01) var CircularWavesAmplitude = 2.0: set(value): @@ -129,7 +118,7 @@ class_name PostProcessingConfiguration extends Resource set(value): CircularWavesRippleRate = value reload = true -@export_group("Speed Lines") +@export_subgroup("Speed Lines") @export var SpeedLines: bool @export var SpeedLinesColor: Color = Color.WHITE: set(value): @@ -147,7 +136,17 @@ class_name PostProcessingConfiguration extends Resource set(value): SpeedLineSpeed = value reload = true -@export_group("CRT") + +@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("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): @@ -225,10 +224,16 @@ class_name PostProcessingConfiguration extends Resource set(value): vignette_opacity = value reload = true - - -#@export_category("Bloom") -var Bloom: bool = false -var BloomDirection = Vector2(0,0) -var BloomRadius = 0.0 -var BloomIntensity = 0.0 +@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/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/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/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