forked from gdquest-demos/godot-4-3d-third-person-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct blur shader not working anymore in Godot 4.X
- Loading branch information
1 parent
423a6ba
commit e1fe8d3
Showing
2 changed files
with
33 additions
and
19 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 |
---|---|---|
@@ -1,26 +1,40 @@ | ||
shader_type canvas_item; | ||
|
||
uniform vec2 blur_scale = vec2(1, 0); | ||
uniform vec4 color_modulate: source_color; | ||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; | ||
|
||
const int SAMPLES = 8; | ||
const float WEIGHTS[70] = {0.000008, 0.000014, 0.000022, 0.000035, 0.000054, 0.000084, 0.000127, 0.000189, 0.000279, 0.000405, 0.00058, 0.00082, 0.001141, 0.001567, 0.002121, 0.002831, 0.003726, 0.004835, 0.006186, 0.007804, 0.009708, 0.011908, 0.014402, 0.017174, 0.020194, 0.023412, 0.026764, 0.030168, 0.033529, 0.036743, 0.039703, 0.042301, 0.044438, 0.046031, 0.047013, 0.047346, 0.047013, 0.046031, 0.044438, 0.042301, 0.039703, 0.036743, 0.033529, 0.030168, 0.026764, 0.023412, 0.020194, 0.017174, 0.014402, 0.011908, 0.009708, 0.007804, 0.006186, 0.004835, 0.003726, 0.002831, 0.002121, 0.001567, 0.001141, 0.00082, 0.00058, 0.000405, 0.000279, 0.000189, 0.000127, 0.000084, 0.000054, 0.000035, 0.000022, 0.000014}; | ||
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest; | ||
uniform float blur_size = 1.0; | ||
uniform vec3 color_modulate: source_color = vec3(1.0); | ||
|
||
void fragment() { | ||
vec2 scale = SCREEN_PIXEL_SIZE * blur_scale; | ||
const int SAMPLES = 9; | ||
const int SAMPLES_HALF = SAMPLES / 2; | ||
const float TOTAL_WEIGHT = 1.627038; | ||
const float WEIGHTS[8] = { | ||
0.05467, | ||
0.080657, | ||
0.106483, | ||
0.125794, | ||
0.132981, | ||
0.125794, | ||
0.106483, | ||
0.080657 | ||
}; | ||
|
||
vec2 scale = SCREEN_PIXEL_SIZE * blur_size; | ||
|
||
COLOR = vec4(0.0); | ||
|
||
float total_weight = 0.0; | ||
vec4 color = vec4(0.0); | ||
vec2 blur_direction_1 = TEXTURE_PIXEL_SIZE * vec2(blur_size); | ||
vec2 blur_direction_2 = TEXTURE_PIXEL_SIZE * vec2(blur_size, -blur_size); | ||
|
||
for (int i = -SAMPLES / 2; i < SAMPLES / 2; ++i) { | ||
for (int j = -SAMPLES / 2; j < SAMPLES / 2; ++j) { | ||
int weight_index = ((i + SAMPLES/2) * SAMPLES) + j; | ||
float weight = WEIGHTS[weight_index]; | ||
color.rgb += texture(SCREEN_TEXTURE, UV + scale * vec2(float(i), float(j))).rgb * weight; | ||
total_weight += weight; | ||
} | ||
for(int i = -SAMPLES_HALF; i < SAMPLES_HALF; ++i) { | ||
int w = i + SAMPLES_HALF; | ||
COLOR += texture(screen_texture, SCREEN_UV + blur_direction_1 * float(i) * scale) * WEIGHTS[w]; | ||
} | ||
for(int i = -SAMPLES_HALF; i < SAMPLES_HALF; ++i) { | ||
int w = i + SAMPLES_HALF; | ||
COLOR += texture(screen_texture, SCREEN_UV + blur_direction_2 * float(i) * scale) * WEIGHTS[w]; | ||
} | ||
|
||
COLOR.rgb = (color.rgb / total_weight) * color_modulate.rgb; | ||
COLOR /= TOTAL_WEIGHT; | ||
COLOR.rgb *= color_modulate; | ||
} |
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