[Bf-blender-cvs] [a8a7b846596] temp-vulkan-shader: Converted world_clip_planes macros to functions.

Jeroen Bakker noreply at git.blender.org
Tue Dec 6 10:09:35 CET 2022


Commit: a8a7b8465960a95a98018cf59fd76fe73d37a4dc
Author: Jeroen Bakker
Date:   Tue Dec 6 08:38:13 2022 +0100
Branches: temp-vulkan-shader
https://developer.blender.org/rBa8a7b8465960a95a98018cf59fd76fe73d37a4dc

Converted world_clip_planes macros to functions.

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

M	source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl

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

diff --git a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
index 4b15bb3851d..68835cb1d0f 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
@@ -13,8 +13,6 @@ void main()
   gl_Position = ModelViewProjectionMatrix * pos_4d;
   stipple_start = stipple_pos = viewport_size * 0.5 * (gl_Position.xy / gl_Position.w);
 #ifdef USE_WORLD_CLIP_PLANES
-  /* Spir-V GLSL pre-processors chokes when passed directly. */
-  vec3 wpos = (ModelMatrix * pos_4d).xyz;
-  world_clip_planes_calc_clip_distance(wpos);
+  world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
 #endif
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl b/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
index 3edf0e31799..110bfe4148e 100644
--- a/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
@@ -1,40 +1,26 @@
 #ifdef USE_WORLD_CLIP_PLANES
 #  if defined(GPU_VERTEX_SHADER) || defined(GPU_GEOMETRY_SHADER)
 
-#    ifndef USE_GPU_SHADER_CREATE_INFO
-uniform vec4 WorldClipPlanes[6];
-#    endif
-
-#    define _world_clip_planes_calc_clip_distance(wpos, _clipplanes) \
-      { \
-        vec4 _pos = vec4(wpos, 1.0); \
-        gl_ClipDistance[0] = dot(_clipplanes[0], _pos); \
-        gl_ClipDistance[1] = dot(_clipplanes[1], _pos); \
-        gl_ClipDistance[2] = dot(_clipplanes[2], _pos); \
-        gl_ClipDistance[3] = dot(_clipplanes[3], _pos); \
-        gl_ClipDistance[4] = dot(_clipplanes[4], _pos); \
-        gl_ClipDistance[5] = dot(_clipplanes[5], _pos); \
-      }
-
 /* When all shaders are builtin shaders are migrated this could be applied directly. */
 #    ifdef USE_GPU_SHADER_CREATE_INFO
 #      define WorldClipPlanes clipPlanes.world
+#    else
+uniform vec4 WorldClipPlanes[6];
 #    endif
-/* HACK Dirty hack to be able to override the definition in common_view_lib.glsl.
- * Not doing this would require changing the include order in every shaders. */
-#    define world_clip_planes_calc_clip_distance(wpos) \
-      _world_clip_planes_calc_clip_distance(wpos, WorldClipPlanes)
 
-#  endif
+void world_clip_planes_calc_clip_distance(vec3 wpos)
+{
+  vec4 clip_planes[6] = WorldClipPlanes;
+  vec4 pos = vec4(wpos, 1.0);
 
-#  define world_clip_planes_set_clip_distance(c) \
-    { \
-      gl_ClipDistance[0] = (c)[0]; \
-      gl_ClipDistance[1] = (c)[1]; \
-      gl_ClipDistance[2] = (c)[2]; \
-      gl_ClipDistance[3] = (c)[3]; \
-      gl_ClipDistance[4] = (c)[4]; \
-      gl_ClipDistance[5] = (c)[5]; \
-    }
+  gl_ClipDistance[0] = dot(clip_planes[0], pos);
+  gl_ClipDistance[1] = dot(clip_planes[1], pos);
+  gl_ClipDistance[2] = dot(clip_planes[2], pos);
+  gl_ClipDistance[3] = dot(clip_planes[3], pos);
+  gl_ClipDistance[4] = dot(clip_planes[4], pos);
+  gl_ClipDistance[5] = dot(clip_planes[5], pos);
+}
+
+#  endif
 
 #endif



More information about the Bf-blender-cvs mailing list