Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsKorin authored May 8, 2024
1 parent 20e94f3 commit 23dd10b
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 38 deletions.
1 change: 1 addition & 0 deletions addons/post_processing/AboutShaders.txt
Original file line number Diff line number Diff line change
@@ -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!
20 changes: 20 additions & 0 deletions addons/post_processing/node/children/color_correction.tscn
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions addons/post_processing/node/children/pixelate.tscn
Original file line number Diff line number Diff line change
@@ -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
24 changes: 19 additions & 5 deletions addons/post_processing/node/post_process.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand All @@ -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()
3 changes: 2 additions & 1 deletion addons/post_processing/node/post_process.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion addons/post_processing/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="PostProcessing"
description="Simple Post Processing Plugin"
author="Korin"
version=""
version="0.0.9"
script="plugin.gd"
67 changes: 36 additions & 31 deletions addons/post_processing/resource/post_processing_configuration.gd
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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
19 changes: 19 additions & 0 deletions addons/post_processing/shaders/color_correction.gdshader
Original file line number Diff line number Diff line change
@@ -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;
}
76 changes: 76 additions & 0 deletions addons/post_processing/shaders/dither.gdshader
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 20 additions & 0 deletions addons/post_processing/shaders/painted.gdshader
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 23dd10b

Please sign in to comment.