1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-28 16:07:14 +00:00

Merge pull request #68487 from clayjohn/RD-mobile-raster

Use raster versions of copy effects for 2D operations when using the mobile renderer
This commit is contained in:
Rémi Verschelde
2022-11-15 10:27:43 +01:00
6 changed files with 156 additions and 42 deletions

View File

@@ -53,30 +53,31 @@ void main() {
#ifdef MODE_GAUSSIAN_BLUR
// Simpler blur uses SIGMA2 for the gaussian kernel for a stronger effect
// For Gaussian Blur we use 13 taps in a single pass instead of 12 taps over 2 passes.
// This minimizes the number of times we change framebuffers which is very important for mobile.
// Source: http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare
vec4 A = texture(source_color, uv_interp + blur.pixel_size * vec2(-1.0, -1.0));
vec4 B = texture(source_color, uv_interp + blur.pixel_size * vec2(0.0, -1.0));
vec4 C = texture(source_color, uv_interp + blur.pixel_size * vec2(1.0, -1.0));
vec4 D = texture(source_color, uv_interp + blur.pixel_size * vec2(-0.5, -0.5));
vec4 E = texture(source_color, uv_interp + blur.pixel_size * vec2(0.5, -0.5));
vec4 F = texture(source_color, uv_interp + blur.pixel_size * vec2(-1.0, 0.0));
vec4 G = texture(source_color, uv_interp);
vec4 H = texture(source_color, uv_interp + blur.pixel_size * vec2(1.0, 0.0));
vec4 I = texture(source_color, uv_interp + blur.pixel_size * vec2(-0.5, 0.5));
vec4 J = texture(source_color, uv_interp + blur.pixel_size * vec2(0.5, 0.5));
vec4 K = texture(source_color, uv_interp + blur.pixel_size * vec2(-1.0, 1.0));
vec4 L = texture(source_color, uv_interp + blur.pixel_size * vec2(0.0, 1.0));
vec4 M = texture(source_color, uv_interp + blur.pixel_size * vec2(1.0, 1.0));
// note, for blur blur.luminance_multiplier is irrelavant, we would be multiplying and then dividing by this amount.
float base_weight = 0.5 / 4.0;
float lesser_weight = 0.125 / 4.0;
if (bool(blur.flags & FLAG_HORIZONTAL)) {
vec2 pix_size = blur.pixel_size;
pix_size *= 0.5; //reading from larger buffer, so use more samples
vec4 color = texture(source_color, uv_interp + vec2(0.0, 0.0) * pix_size) * 0.214607;
color += texture(source_color, uv_interp + vec2(1.0, 0.0) * pix_size) * 0.189879;
color += texture(source_color, uv_interp + vec2(2.0, 0.0) * pix_size) * 0.131514;
color += texture(source_color, uv_interp + vec2(3.0, 0.0) * pix_size) * 0.071303;
color += texture(source_color, uv_interp + vec2(-1.0, 0.0) * pix_size) * 0.189879;
color += texture(source_color, uv_interp + vec2(-2.0, 0.0) * pix_size) * 0.131514;
color += texture(source_color, uv_interp + vec2(-3.0, 0.0) * pix_size) * 0.071303;
frag_color = color;
} else {
vec2 pix_size = blur.pixel_size;
vec4 color = texture(source_color, uv_interp + vec2(0.0, 0.0) * pix_size) * 0.38774;
color += texture(source_color, uv_interp + vec2(0.0, 1.0) * pix_size) * 0.24477;
color += texture(source_color, uv_interp + vec2(0.0, 2.0) * pix_size) * 0.06136;
color += texture(source_color, uv_interp + vec2(0.0, -1.0) * pix_size) * 0.24477;
color += texture(source_color, uv_interp + vec2(0.0, -2.0) * pix_size) * 0.06136;
frag_color = color;
}
frag_color = (D + E + I + J) * base_weight;
frag_color += (A + B + G + F) * lesser_weight;
frag_color += (B + C + H + G) * lesser_weight;
frag_color += (F + G + L + K) * lesser_weight;
frag_color += (G + H + M + L) * lesser_weight;
#endif
#ifdef MODE_GAUSSIAN_GLOW

View File

@@ -194,10 +194,10 @@ void main() {
color = min(color * feedback, vec4(params.glow_luminance_cap));
}
#endif
#endif // MODE_GLOW
imageStore(dest_buffer, pos + params.target, color);
#endif
#endif // MODE_GAUSSIAN_BLUR
#ifdef MODE_SIMPLE_COPY
@@ -227,7 +227,7 @@ void main() {
imageStore(dest_buffer, pos + params.target, color);
#endif
#endif // MODE_SIMPLE_COPY
#ifdef MODE_SIMPLE_COPY_DEPTH
@@ -239,7 +239,7 @@ void main() {
imageStore(dest_buffer, pos + params.target, vec4(color.r));
#endif
#endif // MODE_SIMPLE_COPY_DEPTH
#ifdef MODE_LINEARIZE_DEPTH_COPY
@@ -253,7 +253,7 @@ void main() {
}
imageStore(dest_buffer, pos + params.target, color);
#endif
#endif // MODE_LINEARIZE_DEPTH_COPY
#if defined(MODE_CUBEMAP_TO_PANORAMA) || defined(MODE_CUBEMAP_ARRAY_TO_PANORAMA)
@@ -276,7 +276,7 @@ void main() {
vec4 color = textureLod(source_color, vec4(normal, params.camera_z_far), 0.0); //the biggest the lod the least the acne
#endif
imageStore(dest_buffer, pos + params.target, color);
#endif
#endif // defined(MODE_CUBEMAP_TO_PANORAMA) || defined(MODE_CUBEMAP_ARRAY_TO_PANORAMA)
#ifdef MODE_SET_COLOR
imageStore(dest_buffer, pos + params.target, params.set_color);

View File

@@ -26,7 +26,11 @@ layout(push_constant, std430) uniform Params {
bool use_section;
bool force_luminance;
uint pad[3];
bool alpha_to_zero;
bool srgb;
bool alpha_to_one;
vec4 color;
}
params;
@@ -72,7 +76,9 @@ layout(push_constant, std430) uniform Params {
bool force_luminance;
bool alpha_to_zero;
bool srgb;
uint pad;
bool alpha_to_one;
vec4 color;
}
params;
@@ -105,6 +111,10 @@ vec3 linear_to_srgb(vec3 color) {
}
void main() {
#ifdef MODE_SET_COLOR
frag_color = params.color;
#else
#ifdef MULTIVIEW
vec3 uv = uv_interp;
#else
@@ -164,6 +174,10 @@ void main() {
if (params.srgb) {
color.rgb = linear_to_srgb(color.rgb);
}
if (params.alpha_to_one) {
color.a = 1.0;
}
frag_color = color;
#endif // MODE_SET_COLOR
}