Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Emara <mail@OmarEmara.dev>2022-03-30 22:01:44 +0300
committerOmar Emara <mail@OmarEmara.dev>2022-03-30 22:01:44 +0300
commit2f6991cbeb9da1ab3cbb1f6ef79eef23aebc8d86 (patch)
tree97fc33e581f7290b1d2cf5d6ba98a2b73c014378
parent6f9f534149a7b1352115cb2f507ccce109447845 (diff)
Viewport Compositor: Share conversion shaders
-rw-r--r--source/blender/gpu/CMakeLists.txt12
-rw-r--r--source/blender/gpu/shaders/compositor/compositor_convert.glsl8
-rw-r--r--source/blender/gpu/shaders/compositor/compositor_convert_color_to_float.glsl9
-rw-r--r--source/blender/gpu/shaders/compositor/compositor_convert_float_to_color.glsl7
-rw-r--r--source/blender/gpu/shaders/compositor/compositor_convert_vector_to_color.glsl8
-rw-r--r--source/blender/gpu/shaders/compositor/compositor_image.glsl7
-rw-r--r--source/blender/gpu/shaders/compositor/compositor_image_alpha.glsl7
-rw-r--r--source/blender/gpu/shaders/compositor/infos/compositor_convert_color_to_float_info.hh27
-rw-r--r--source/blender/gpu/shaders/compositor/infos/compositor_convert_float_to_color_info.hh27
-rw-r--r--source/blender/gpu/shaders/compositor/infos/compositor_convert_info.hh56
-rw-r--r--source/blender/gpu/shaders/compositor/infos/compositor_convert_vector_to_color_info.hh27
-rw-r--r--source/blender/gpu/shaders/compositor/infos/compositor_image_alpha_info.hh27
-rw-r--r--source/blender/gpu/shaders/compositor/infos/compositor_image_info.hh27
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_image.cc4
14 files changed, 68 insertions, 185 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 1cdd60b65cf..60b8b2adc0f 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -308,11 +308,7 @@ set(GLSL_SRC
shaders/compositor/material/gpu_shader_compositor_store_output.glsl
shaders/compositor/material/gpu_shader_compositor_type_conversion.glsl
- shaders/compositor/compositor_convert_color_to_float.glsl
- shaders/compositor/compositor_convert_float_to_color.glsl
- shaders/compositor/compositor_convert_vector_to_color.glsl
- shaders/compositor/compositor_image.glsl
- shaders/compositor/compositor_image_alpha.glsl
+ shaders/compositor/compositor_convert.glsl
shaders/compositor/compositor_realize_on_domain.glsl
shaders/material/gpu_shader_material_add_shader.glsl
@@ -496,11 +492,7 @@ set(SHADER_CREATE_INFOS
shaders/infos/gpu_shader_text_info.hh
shaders/infos/gpu_srgb_to_framebuffer_space_info.hh
- shaders/compositor/infos/compositor_convert_color_to_float_info.hh
- shaders/compositor/infos/compositor_convert_float_to_color_info.hh
- shaders/compositor/infos/compositor_convert_vector_to_color_info.hh
- shaders/compositor/infos/compositor_image_info.hh
- shaders/compositor/infos/compositor_image_alpha_info.hh
+ shaders/compositor/infos/compositor_convert_info.hh
shaders/compositor/infos/compositor_realize_on_domain_info.hh
)
diff --git a/source/blender/gpu/shaders/compositor/compositor_convert.glsl b/source/blender/gpu/shaders/compositor/compositor_convert.glsl
new file mode 100644
index 00000000000..02ae9b91745
--- /dev/null
+++ b/source/blender/gpu/shaders/compositor/compositor_convert.glsl
@@ -0,0 +1,8 @@
+/* The shader create info instance should define a CONVERT_EXPRESSION as well as an output_image
+ * given the sampled texel. */
+void main()
+{
+ ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
+ vec4 texel = texelFetch(input_sampler, xy, 0);
+ imageStore(output_image, xy, CONVERT_EXPRESSION);
+}
diff --git a/source/blender/gpu/shaders/compositor/compositor_convert_color_to_float.glsl b/source/blender/gpu/shaders/compositor/compositor_convert_color_to_float.glsl
deleted file mode 100644
index 27b0b9a231c..00000000000
--- a/source/blender/gpu/shaders/compositor/compositor_convert_color_to_float.glsl
+++ /dev/null
@@ -1,9 +0,0 @@
-/* Store the average of the input's three color channels in the output, the alpha channel is
- * ignored. */
-
-void main()
-{
- ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
- vec4 color = texelFetch(input_sampler, xy, 0);
- imageStore(output_image, xy, vec4((color.r + color.g + color.b) / 3.0));
-}
diff --git a/source/blender/gpu/shaders/compositor/compositor_convert_float_to_color.glsl b/source/blender/gpu/shaders/compositor/compositor_convert_float_to_color.glsl
deleted file mode 100644
index 2983a8abadd..00000000000
--- a/source/blender/gpu/shaders/compositor/compositor_convert_float_to_color.glsl
+++ /dev/null
@@ -1,7 +0,0 @@
-/* Fill all three color channels of the output with the input and set the alpha channel to 1. */
-
-void main()
-{
- ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
- imageStore(output_image, xy, vec4(texelFetch(input_sampler, xy, 0).xxx, 1.0));
-}
diff --git a/source/blender/gpu/shaders/compositor/compositor_convert_vector_to_color.glsl b/source/blender/gpu/shaders/compositor/compositor_convert_vector_to_color.glsl
deleted file mode 100644
index bcfad9f3e67..00000000000
--- a/source/blender/gpu/shaders/compositor/compositor_convert_vector_to_color.glsl
+++ /dev/null
@@ -1,8 +0,0 @@
-/* Copy the three vector components of the input to the three color channels of the output and set
- * the alpha channel to 1. */
-
-void main()
-{
- ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
- imageStore(output_image, xy, vec4(texelFetch(input_sampler, xy, 0).xyz, 1.0));
-}
diff --git a/source/blender/gpu/shaders/compositor/compositor_image.glsl b/source/blender/gpu/shaders/compositor/compositor_image.glsl
deleted file mode 100644
index 1982b1819d8..00000000000
--- a/source/blender/gpu/shaders/compositor/compositor_image.glsl
+++ /dev/null
@@ -1,7 +0,0 @@
-/* Copy the input float 2D sampler to the output RGBA16F 2D image. */
-
-void main()
-{
- ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
- imageStore(output_image, xy, texelFetch(input_sampler, xy, 0));
-}
diff --git a/source/blender/gpu/shaders/compositor/compositor_image_alpha.glsl b/source/blender/gpu/shaders/compositor/compositor_image_alpha.glsl
deleted file mode 100644
index a4bce4a1d21..00000000000
--- a/source/blender/gpu/shaders/compositor/compositor_image_alpha.glsl
+++ /dev/null
@@ -1,7 +0,0 @@
-/* Copy the alpha of the input float 2D sampler to the output R16F 2D image. */
-
-void main()
-{
- ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
- imageStore(output_image, xy, texelFetch(input_sampler, xy, 0).aaaa);
-}
diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_convert_color_to_float_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_convert_color_to_float_info.hh
deleted file mode 100644
index 89c921896bb..00000000000
--- a/source/blender/gpu/shaders/compositor/infos/compositor_convert_color_to_float_info.hh
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2022 Blender Foundation.
- * All rights reserved.
- */
-
-#include "gpu_shader_create_info.hh"
-
-GPU_SHADER_CREATE_INFO(compositor_convert_color_to_float)
- .local_group_size(16, 16)
- .sampler(0, ImageType::FLOAT_2D, "input_sampler")
- .image(0, GPU_R16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
- .compute_source("compositor_convert_color_to_float.glsl")
- .do_static_compilation(true);
diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_convert_float_to_color_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_convert_float_to_color_info.hh
deleted file mode 100644
index 62bf2be1493..00000000000
--- a/source/blender/gpu/shaders/compositor/infos/compositor_convert_float_to_color_info.hh
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2022 Blender Foundation.
- * All rights reserved.
- */
-
-#include "gpu_shader_create_info.hh"
-
-GPU_SHADER_CREATE_INFO(compositor_convert_float_to_color)
- .local_group_size(16, 16)
- .sampler(0, ImageType::FLOAT_2D, "input_sampler")
- .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
- .compute_source("compositor_convert_float_to_color.glsl")
- .do_static_compilation(true);
diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_convert_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_convert_info.hh
new file mode 100644
index 00000000000..3e37bb4273f
--- /dev/null
+++ b/source/blender/gpu/shaders/compositor/infos/compositor_convert_info.hh
@@ -0,0 +1,56 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2022 Blender Foundation.
+ * All rights reserved.
+ */
+
+#include "gpu_shader_create_info.hh"
+
+GPU_SHADER_CREATE_INFO(compositor_convert_shared)
+ .local_group_size(16, 16)
+ .sampler(0, ImageType::FLOAT_2D, "input_sampler")
+ .typedef_source("gpu_shader_compositor_type_conversion.glsl")
+ .compute_source("compositor_convert.glsl");
+
+GPU_SHADER_CREATE_INFO(compositor_convert_color_to_float)
+ .additional_info("compositor_convert_shared")
+ .image(0, GPU_R16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
+ .define("CONVERT_EXPRESSION", "vec4(float_from_vec4(texel))")
+ .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(compositor_convert_float_to_color)
+ .additional_info("compositor_convert_shared")
+ .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
+ .define("CONVERT_EXPRESSION", "vec4_from_float(texel.x)")
+ .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(compositor_convert_vector_to_color)
+ .additional_info("compositor_convert_shared")
+ .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
+ .define("CONVERT_EXPRESSION", "vec4_from_vec3(texel.xyz)")
+ .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(compositor_convert_color_to_half_color)
+ .additional_info("compositor_convert_shared")
+ .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
+ .define("CONVERT_EXPRESSION", "texel")
+ .do_static_compilation(true);
+
+GPU_SHADER_CREATE_INFO(compositor_convert_color_to_alpha)
+ .additional_info("compositor_convert_shared")
+ .image(0, GPU_R16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
+ .define("CONVERT_EXPRESSION", "texel.aaaa")
+ .do_static_compilation(true);
diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_convert_vector_to_color_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_convert_vector_to_color_info.hh
deleted file mode 100644
index 25b53b4cc64..00000000000
--- a/source/blender/gpu/shaders/compositor/infos/compositor_convert_vector_to_color_info.hh
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2022 Blender Foundation.
- * All rights reserved.
- */
-
-#include "gpu_shader_create_info.hh"
-
-GPU_SHADER_CREATE_INFO(compositor_convert_vector_to_color)
- .local_group_size(16, 16)
- .sampler(0, ImageType::FLOAT_2D, "input_sampler")
- .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
- .compute_source("compositor_convert_vector_to_color.glsl")
- .do_static_compilation(true);
diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_image_alpha_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_image_alpha_info.hh
deleted file mode 100644
index aee521e01cf..00000000000
--- a/source/blender/gpu/shaders/compositor/infos/compositor_image_alpha_info.hh
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2022 Blender Foundation.
- * All rights reserved.
- */
-
-#include "gpu_shader_create_info.hh"
-
-GPU_SHADER_CREATE_INFO(compositor_image_alpha)
- .local_group_size(16, 16)
- .sampler(0, ImageType::FLOAT_2D, "input_sampler")
- .image(0, GPU_R16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
- .compute_source("compositor_image_alpha.glsl")
- .do_static_compilation(true);
diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_image_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_image_info.hh
deleted file mode 100644
index 9797065efb4..00000000000
--- a/source/blender/gpu/shaders/compositor/infos/compositor_image_info.hh
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2022 Blender Foundation.
- * All rights reserved.
- */
-
-#include "gpu_shader_create_info.hh"
-
-GPU_SHADER_CREATE_INFO(compositor_image)
- .local_group_size(16, 16)
- .sampler(0, ImageType::FLOAT_2D, "input_sampler")
- .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
- .compute_source("compositor_image.glsl")
- .do_static_compilation(true);
diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc
index f58f807bc0c..4bd8bd0902d 100644
--- a/source/blender/nodes/composite/nodes/node_composite_image.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_image.cc
@@ -465,8 +465,8 @@ class ImageOperation : public NodeOperation {
void execute() override
{
- compute_output("Image", "compositor_image");
- compute_output("Alpha", "compositor_image_alpha");
+ compute_output("Image", "compositor_convert_color_to_half_color");
+ compute_output("Alpha", "compositor_convert_color_to_alpha");
}
void compute_output(StringRef identifier, const char *shader_name)