-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
281 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
addons/post_processing/node/children/color_correction.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.