Realtime Compositor: Implement filter node
This patch implements the filter node for the realtime compositor. Differential Revision: https://developer.blender.org/D15661 Reviewed By: Clement Foucault
This commit is contained in:
@@ -318,7 +318,9 @@ set(GLSL_SRC
|
||||
shaders/compositor/compositor_bokeh_image.glsl
|
||||
shaders/compositor/compositor_box_mask.glsl
|
||||
shaders/compositor/compositor_convert.glsl
|
||||
shaders/compositor/compositor_edge_filter.glsl
|
||||
shaders/compositor/compositor_ellipse_mask.glsl
|
||||
shaders/compositor/compositor_filter.glsl
|
||||
shaders/compositor/compositor_flip.glsl
|
||||
shaders/compositor/compositor_image_crop.glsl
|
||||
shaders/compositor/compositor_projector_lens_distortion.glsl
|
||||
@@ -565,7 +567,9 @@ set(SRC_SHADER_CREATE_INFOS
|
||||
shaders/compositor/infos/compositor_bokeh_image_info.hh
|
||||
shaders/compositor/infos/compositor_box_mask_info.hh
|
||||
shaders/compositor/infos/compositor_convert_info.hh
|
||||
shaders/compositor/infos/compositor_edge_filter_info.hh
|
||||
shaders/compositor/infos/compositor_ellipse_mask_info.hh
|
||||
shaders/compositor/infos/compositor_filter_info.hh
|
||||
shaders/compositor/infos/compositor_flip_info.hh
|
||||
shaders/compositor/infos/compositor_image_crop_info.hh
|
||||
shaders/compositor/infos/compositor_projector_lens_distortion_info.hh
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utilities.glsl)
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
/* Compute the dot product between the 3x3 window around the pixel and the edge detection kernel
|
||||
* in the X direction and Y direction. The Y direction kernel is computed by transposing the
|
||||
* given X direction kernel. */
|
||||
vec3 color_x = vec3(0);
|
||||
vec3 color_y = vec3(0);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
vec3 color = texture_load(input_tx, texel + ivec2(i - 1, j - 1)).rgb;
|
||||
color_x += color * kernel[j][i];
|
||||
color_y += color * kernel[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the channel-wise magnitude of the 2D vector composed from the X and Y edge detection
|
||||
* filter results. */
|
||||
vec3 magnitude = sqrt(color_x * color_x + color_y * color_y);
|
||||
|
||||
/* Mix the channel-wise magnitude with the original color at the center of the kernel using the
|
||||
* input factor. */
|
||||
vec4 color = texture_load(input_tx, texel);
|
||||
magnitude = mix(color.rgb, magnitude, texture_load(factor_tx, texel).x);
|
||||
|
||||
/* Store the channel-wise magnitude with the original alpha of the input. */
|
||||
imageStore(output_img, texel, vec4(magnitude, color.a));
|
||||
}
|
||||
20
source/blender/gpu/shaders/compositor/compositor_filter.glsl
Normal file
20
source/blender/gpu/shaders/compositor/compositor_filter.glsl
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utilities.glsl)
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
/* Compute the dot product between the 3x3 window around the pixel and the filter kernel. */
|
||||
vec4 color = vec4(0);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
color += texture_load(input_tx, texel + ivec2(i - 1, j - 1)) * kernel[j][i];
|
||||
}
|
||||
}
|
||||
|
||||
/* Mix with the original color at the center of the kernel using the input factor. */
|
||||
color = mix(texture_load(input_tx, texel), color, texture_load(factor_tx, texel).x);
|
||||
|
||||
/* Store the color making sure it is not negative. */
|
||||
imageStore(output_img, texel, max(color, 0.0));
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "gpu_shader_create_info.hh"
|
||||
|
||||
GPU_SHADER_CREATE_INFO(compositor_edge_filter)
|
||||
.local_group_size(16, 16)
|
||||
.push_constant(Type::MAT4, "kernel")
|
||||
.sampler(0, ImageType::FLOAT_2D, "input_tx")
|
||||
.sampler(1, ImageType::FLOAT_2D, "factor_tx")
|
||||
.image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_img")
|
||||
.compute_source("compositor_edge_filter.glsl")
|
||||
.do_static_compilation(true);
|
||||
@@ -0,0 +1,12 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "gpu_shader_create_info.hh"
|
||||
|
||||
GPU_SHADER_CREATE_INFO(compositor_filter)
|
||||
.local_group_size(16, 16)
|
||||
.push_constant(Type::MAT4, "kernel")
|
||||
.sampler(0, ImageType::FLOAT_2D, "input_tx")
|
||||
.sampler(1, ImageType::FLOAT_2D, "factor_tx")
|
||||
.image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_img")
|
||||
.compute_source("compositor_filter.glsl")
|
||||
.do_static_compilation(true);
|
||||
Reference in New Issue
Block a user