Commit: 2f6991cbeb9da1ab3cbb1f6ef79eef23aebc8d86
Author: Omar Emara
Date:   Wed Mar 30 21:01:44 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rB2f6991cbeb9da1ab3cbb1f6ef79eef23aebc8d86

Viewport Compositor: Share conversion shaders

===================================================================

M       source/blender/gpu/CMakeLists.txt
A       source/blender/gpu/shaders/compositor/compositor_convert.glsl
D       
source/blender/gpu/shaders/compositor/compositor_convert_color_to_float.glsl
D       
source/blender/gpu/shaders/compositor/compositor_convert_float_to_color.glsl
D       
source/blender/gpu/shaders/compositor/compositor_convert_vector_to_color.glsl
D       source/blender/gpu/shaders/compositor/compositor_image.glsl
D       source/blender/gpu/shaders/compositor/compositor_image_alpha.glsl
D       
source/blender/gpu/shaders/compositor/infos/compositor_convert_color_to_float_info.hh
D       
source/blender/gpu/shaders/compositor/infos/compositor_convert_float_to_color_info.hh
A       source/blender/gpu/shaders/compositor/infos/compositor_convert_info.hh
D       
source/blender/gpu/shaders/compositor/infos/compositor_convert_vector_to_color_info.hh
D       
source/blender/gpu/shaders/compositor/infos/compositor_image_alpha_info.hh
D       source/blender/gpu/shaders/compositor/infos/compositor_image_info.hh
M       source/blender/nodes/composite/nodes/node_composite_image.cc

===================================================================

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(

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to