Commit: 7f5219caa4037e831943d44a4c355fdab11cf898
Author: Jeroen Bakker
Date:   Wed Jan 19 14:46:24 2022 +0100
Branches: tmp-gpu-polyline-shaders
https://developer.blender.org/rB7f5219caa4037e831943d44a4c355fdab11cf898

Migrating polyline shaders to create info.

GPU_SHADER_3D_POLYLINE_(FLAT/SMOOTH/UNIFORM/CLIPPED_UNIFORM)_COLOR

TODO:
* GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR
* Check all usages of clipped uniform shaders.

{T95016}

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

M       source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
M       source/blender/gpu/CMakeLists.txt
M       source/blender/gpu/GPU_shader_shared.h
M       source/blender/gpu/intern/gpu_shader_builtin.c
M       source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl
M       source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl
M       source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl
M       source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh

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

diff --git a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c 
b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
index d4d4c889209..49b8c805017 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
@@ -42,6 +42,7 @@
 #include "GPU_immediate_util.h"
 #include "GPU_matrix.h"
 #include "GPU_select.h"
+#include "GPU_shader_shared.h"
 #include "GPU_state.h"
 
 #include "RNA_access.h"
@@ -114,11 +115,18 @@ static void dial_geom_draw(const float color[4],
   GPUVertFormat *format = immVertexFormat();
   uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, 
GPU_FETCH_FLOAT);
 
+  struct ClippingData clipping_data;
+  GPUUniformBuf *ubo = NULL;
+
   if (clip_plane) {
     immBindBuiltinProgram(filled ? GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR :
                                    
GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR);
-    immUniform4fv("ClipPlane", clip_plane);
-    immUniformMatrix4fv("ModelMatrix", axis_modal_mat);
+    copy_v4_v4(clipping_data.clip_plane, clip_plane);
+    copy_m4_m4(clipping_data.ModelMatrix, axis_modal_mat);
+    ubo = GPU_uniformbuf_create_ex(sizeof(struct ClippingData), 
&clipping_data, __func__);
+    immBindUniformBuf("clipping_data", ubo);
+
+    GPU_uniformbuf_bind(ubo, GPU_shader_uniformbuf_block())
   }
   else {
     immBindBuiltinProgram(filled ? GPU_SHADER_3D_UNIFORM_COLOR :
@@ -175,6 +183,11 @@ static void dial_geom_draw(const float color[4],
 
   immUnbindProgram();
 
+  if (ubo != NULL) {
+    GPU_uniformbuf_free(ubo);
+    ubo = NULL;
+  }
+
   UNUSED_VARS(select);
 #endif
 }
diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index bb7e9e8b26f..9b64c09b782 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -428,6 +428,7 @@ shaders/infos/gpu_shader_3D_flat_color_info.hh
 shaders/infos/gpu_shader_3D_uniform_color_info.hh
 shaders/infos/gpu_shader_3D_smooth_color_info.hh
 shaders/infos/gpu_shader_3D_depth_only_info.hh
+shaders/infos/gpu_shader_3D_polyline_info.hh
 shaders/infos/gpu_shader_2D_point_varying_size_varying_color_info.hh
 shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_aa_info.hh
 shaders/infos/gpu_shader_2D_point_uniform_size_uniform_color_outline_aa_info.hh
diff --git a/source/blender/gpu/GPU_shader_shared.h 
b/source/blender/gpu/GPU_shader_shared.h
index 334b974acd8..50de23de9f5 100644
--- a/source/blender/gpu/GPU_shader_shared.h
+++ b/source/blender/gpu/GPU_shader_shared.h
@@ -89,3 +89,9 @@ struct MultiRectCallData {
   float4 calls_data[MAX_CALLS * 3];
 };
 BLI_STATIC_ASSERT_ALIGN(struct MultiRectCallData, 16)
+
+struct ClippingData {
+  float4x4 ModelMatrix;
+  float4 clip_plane;
+};
+BLI_STATIC_ASSERT_ALIGN(struct ClippingData, 16)
diff --git a/source/blender/gpu/intern/gpu_shader_builtin.c 
b/source/blender/gpu/intern/gpu_shader_builtin.c
index 13f1774df03..0775c53f518 100644
--- a/source/blender/gpu/intern/gpu_shader_builtin.c
+++ b/source/blender/gpu/intern/gpu_shader_builtin.c
@@ -236,39 +236,16 @@ static const GPUShaderStages 
builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
             .frag = datatoc_gpu_shader_uniform_color_frag_glsl,
         },
 
-    [GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR] =
-        {
-            .name = "GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR",
-            .vert = datatoc_gpu_shader_3D_polyline_vert_glsl,
-            .geom = datatoc_gpu_shader_3D_polyline_geom_glsl,
-            .frag = datatoc_gpu_shader_3D_polyline_frag_glsl,
-            .defs = "#define UNIFORM\n",
-        },
+    [GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR] = {.name = 
"GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR",
+                                              .create_info =
+                                                  
"gpu_shader_3D_polyline_uniform_color"},
     [GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR] =
-        {
-            .name = "GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR",
-            .vert = datatoc_gpu_shader_3D_polyline_vert_glsl,
-            .geom = datatoc_gpu_shader_3D_polyline_geom_glsl,
-            .frag = datatoc_gpu_shader_3D_polyline_frag_glsl,
-            .defs = "#define UNIFORM\n"
-                    "#define CLIP\n",
-        },
-    [GPU_SHADER_3D_POLYLINE_FLAT_COLOR] =
-        {
-            .name = "GPU_SHADER_3D_POLYLINE_FLAT_COLOR",
-            .vert = datatoc_gpu_shader_3D_polyline_vert_glsl,
-            .geom = datatoc_gpu_shader_3D_polyline_geom_glsl,
-            .frag = datatoc_gpu_shader_3D_polyline_frag_glsl,
-            .defs = "#define FLAT\n",
-        },
-    [GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR] =
-        {
-            .name = "GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR",
-            .vert = datatoc_gpu_shader_3D_polyline_vert_glsl,
-            .geom = datatoc_gpu_shader_3D_polyline_geom_glsl,
-            .frag = datatoc_gpu_shader_3D_polyline_frag_glsl,
-            .defs = "#define SMOOTH\n",
-        },
+        {.name = "GPU_SHADER_3D_POLYLINE_CLIPPED_UNIFORM_COLOR",
+         .create_info = "gpu_shader_3D_polyline_clipped_uniform_color"},
+    [GPU_SHADER_3D_POLYLINE_FLAT_COLOR] = {.name = 
"GPU_SHADER_3D_POLYLINE_FLAT_COLOR",
+                                           .create_info = 
"gpu_shader_3D_polyline_flat_color"},
+    [GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR] = {.name = 
"GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR",
+                                             .create_info = 
"gpu_shader_3D_polyline_smooth_color"},
 
     [GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR] =
         {
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl 
b/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl
index 8687763f4c1..648351e1059 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_frag.glsl
@@ -16,13 +16,13 @@ out vec4 fragColor;
 void main()
 {
 #ifdef CLIP
-  if (clip < 0.0) {
+  if (geom_out.clip < 0.0) {
     discard;
   }
 #endif
-  fragColor = finalColor;
+  fragColor = geom_out.finalColor;
   if (lineSmooth) {
-    fragColor.a *= clamp((lineWidth + SMOOTH_WIDTH) * 0.5 - abs(smoothline), 
0.0, 1.0);
+    fragColor.a *= clamp((lineWidth + SMOOTH_WIDTH) * 0.5 - 
abs(geom_out.smoothline), 0.0, 1.0);
   }
   fragColor = blender_srgb_to_framebuffer_space(fragColor);
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl 
b/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl
index 627e91af4d6..9cdaae7c114 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_geom.glsl
@@ -41,26 +41,26 @@ vec4 clip_line_point_homogeneous_space(vec4 p, vec4 q)
 void do_vertex(const int i, vec4 pos, vec2 ofs)
 {
 #if defined(UNIFORM)
-  finalColor = color;
+  geom_out.finalColor = color;
 
 #elif defined(FLAT)
   /* WATCH: Assuming last provoking vertex. */
-  finalColor = finalColor_g[1];
+  geom_out.finalColor = geom_in[1].finalColor_g;
 
 #elif defined(SMOOTH)
-  finalColor = finalColor_g[i];
+  geom_out.finalColor = geom_in[i].finalColor_g;
 #endif
 
 #ifdef CLIP
-  clip = clip_g[i];
+  geom_out.clip = geom_in[i].clip_g;
 #endif
 
-  smoothline = (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
+  geom_out.smoothline = (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
   gl_Position = pos;
   gl_Position.xy += ofs * pos.w;
   EmitVertex();
 
-  smoothline = -(lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
+  geom_out.smoothline = -(lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
   gl_Position = pos;
   gl_Position.xy -= ofs * pos.w;
   EmitVertex();
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl 
b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl
index 5c673494870..2eb673ce799 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_polyline_vert.glsl
@@ -20,10 +20,10 @@ void main()
 {
   gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
 #if !defined(UNIFORM)
-  finalColor_g = color;
+  geom_in.finalColor_g = color;
 #endif
 
 #ifdef CLIP
-  clip_g = dot(ModelMatrix * vec4(pos, 1.0), ClipPlane);
+  geom_in.clip_g = dot(clipping_data.ModelMatrix * vec4(pos, 1.0), 
clipping_data.clip_plane);
 #endif
 }
diff --git a/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh 
b/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh
index 1e195e7ff23..5b7f023b4b7 100644
--- a/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh
+++ b/source/blender/gpu/shaders/infos/gpu_shader_3D_polyline_info.hh
@@ -21,13 +21,71 @@
  * \ingroup gpu
  */
 
-
 #include "gpu_interface_info.hh"
 #include "gpu_shader_create_info.hh"
 
-/* TODO(jbakker): Skipped as it needs a uniform/storage buffer. */
-GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline_uniform_color)
+/* Interfaces between vertex stage and geometry stage. */
+GPU_SHADER_INTERFACE_INFO(polyline_color_iface, "geom_in").smooth(Type::VEC4, 
"finalColor_g");
+GPU_SHADER_INTERFACE_INFO(polyline_color_clipped_iface, "geom_in")
+    .smooth(Type::VEC4, "finalColor_g")
+    .smooth(Type::FLOAT, "clip_g");
+GPU_SHADER_INTERFACE_INFO(polyline_uniform_color_clipped_iface, "geom_in")
+    .smooth(Type::FLOAT, "clip_g");
+
+/* Interfaces between geometry stage and fragment stage. */
+GPU_SHADER_INTERFACE_INFO(polyline_clipped_iface, "geom_out")
+    .smooth(Type::VEC4, "finalColor")
+    .no_perspective(Type::FLOAT, "smoothline")
+    .smooth(Type::FLOAT, "clip");
+GPU_SHADER_INTERFACE_INFO(polyline_unclipped_iface, "geom_out")
+    .smooth(Type::VEC4, "finalColor")
+    .no_perspective(Type::FLOAT, "smoothline");
+
+/* Abstract create info for polyline shaders. */
+GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline)
+    .vertex_in(0, Type::VEC3, "pos")
+    .geometry_layout(PrimitiveIn::LINES, PrimitiveOut::TRIANGLE_STRIP, 4)
+    .fragment_out(0, Type::VEC4, "fragColor")
+    .push_constant(0, Type::MAT4, "ModelViewProjectionMatrix")
+    /* Reserved space for Vec4 (16-19) to store uniform color. */
+    .push_constant(20, Type::VEC2, "viewportSize")
+    .push_constant(24, Type::FLOAT, "lineWidt

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to