[Bf-blender-cvs] [bf13e5458db] tmp-gpu-shader-descriptor-2: gpu_shader_3d_flat_color.
Jeroen Bakker
noreply at git.blender.org
Wed Jan 12 11:28:25 CET 2022
Commit: bf13e5458db141fb8a4af391b276dac16e691864
Author: Jeroen Bakker
Date: Wed Jan 12 09:21:53 2022 +0100
Branches: tmp-gpu-shader-descriptor-2
https://developer.blender.org/rBbf13e5458db141fb8a4af391b276dac16e691864
gpu_shader_3d_flat_color.
===================================================================
M source/blender/draw/intern/draw_manager.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/intern/gpu_shader_shared_utils.h
M source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
M source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
M source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh
===================================================================
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 7365ebf59c2..b372fddfeb0 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -70,6 +70,7 @@
#include "GPU_framebuffer.h"
#include "GPU_immediate.h"
#include "GPU_matrix.h"
+#include "GPU_shader_shared.h"
#include "GPU_state.h"
#include "GPU_uniform_buffer.h"
#include "GPU_viewport.h"
@@ -2756,11 +2757,15 @@ void DRW_draw_depth_object(
GPU_framebuffer_clear_depth(depth_fb, 1.0f);
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
- const float(*world_clip_planes)[4] = NULL;
- if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
+ struct GPUClipPlanes planes;
+ const bool use_clipping_planes = RV3D_CLIPPING_ENABLED(v3d, rv3d);
+ if (use_clipping_planes) {
GPU_clip_distances(6);
ED_view3d_clipping_local(rv3d, object->obmat);
- world_clip_planes = rv3d->clip_local;
+ for (int i = 0; i < 6; i++) {
+ copy_v4_v4(planes.world[i], rv3d->clip_local[i]);
+ }
+ copy_m4_m4(planes.ModelMatrix, object->obmat);
}
drw_batch_cache_validate(object);
@@ -2782,14 +2787,20 @@ void DRW_draw_depth_object(
BLI_task_graph_work_and_wait(task_graph);
BLI_task_graph_free(task_graph);
- const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED :
- GPU_SHADER_CFG_DEFAULT;
+ const eGPUShaderConfig sh_cfg = use_clipping_planes ? GPU_SHADER_CFG_CLIPPED :
+ GPU_SHADER_CFG_DEFAULT;
GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_DEPTH_ONLY, sh_cfg);
- if (world_clip_planes != NULL) {
- GPU_batch_uniform_4fv_array(batch, "WorldClipPlanes", 6, world_clip_planes);
+
+ GPUUniformBuf *ubo = NULL;
+ if (use_clipping_planes) {
+ GPU_batch_uniform_4fv_array(batch, "WorldClipPlanes", 6, planes.world);
+ ubo = GPU_uniformbuf_create_ex(sizeof(struct GPUClipPlanes), &planes, __func__);
+ GPU_batch_uniformbuf_bind(batch, "clipPlanes", ubo);
}
GPU_batch_draw(batch);
+ GPU_uniformbuf_free(ubo);
+
} break;
case OB_CURVE:
case OB_SURF:
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 64878989923..dd5f0a0f441 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -424,7 +424,7 @@ shaders/infos/gpu_shader_2D_image_shuffle_color_info.hh
shaders/infos/gpu_shader_2D_image_rect_color_info.hh
shaders/infos/gpu_shader_text_info.hh
shaders/infos/gpu_shader_keyframe_shape_info.hh
-#shaders/infos/gpu_shader_3D_flat_color_info.hh !Disabled due to world_clipping
+shaders/infos/gpu_shader_3D_flat_color_info.hh
#shaders/infos/gpu_shader_3D_uniform_color_info.hh !Disabled due to world clipping
#shaders/infos/gpu_shader_3D_smooth_color_info.hh
#shaders/infos/gpu_shader_3D_depth_only_info.hh
diff --git a/source/blender/gpu/GPU_shader_shared.h b/source/blender/gpu/GPU_shader_shared.h
index 6e38e016979..c84a99df990 100644
--- a/source/blender/gpu/GPU_shader_shared.h
+++ b/source/blender/gpu/GPU_shader_shared.h
@@ -3,6 +3,12 @@
# include "intern/gpu_shader_shared_utils.h"
#endif
+#ifdef __cplusplus
+using blender::float2;
+using blender::float4;
+using blender::float4x4;
+#endif
+
struct NodeLinkData {
float4 colors[3];
float2 bezierPts[4];
@@ -35,3 +41,8 @@ struct GPencilStrokeData {
bool1 fill_stroke;
float2 pad;
};
+
+struct GPUClipPlanes {
+ float4x4 ModelMatrix;
+ float4 world[6];
+};
\ No newline at end of file
diff --git a/source/blender/gpu/intern/gpu_shader_builtin.c b/source/blender/gpu/intern/gpu_shader_builtin.c
index b6d272838bd..cabde86aa36 100644
--- a/source/blender/gpu/intern/gpu_shader_builtin.c
+++ b/source/blender/gpu/intern/gpu_shader_builtin.c
@@ -150,6 +150,7 @@ typedef struct {
const char *defs;
const char *create_info;
+ const char *clipped_create_info;
} GPUShaderStages;
static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
@@ -227,12 +228,9 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
.vert = datatoc_gpu_shader_3D_vert_glsl,
.frag = datatoc_gpu_shader_uniform_color_frag_glsl,
},
- [GPU_SHADER_3D_FLAT_COLOR] =
- {
- .name = "GPU_SHADER_3D_FLAT_COLOR",
- .vert = datatoc_gpu_shader_3D_flat_color_vert_glsl,
- .frag = datatoc_gpu_shader_flat_color_frag_glsl,
- },
+ [GPU_SHADER_3D_FLAT_COLOR] = {.name = "GPU_SHADER_3D_FLAT_COLOR",
+ .create_info = "gpu_shader_3d_flat_color",
+ .clipped_create_info = "gpu_shader_3d_flat_color_clipped"},
[GPU_SHADER_3D_SMOOTH_COLOR] =
{
.name = "GPU_SHADER_3D_SMOOTH_COLOR",
@@ -406,13 +404,14 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
GPU_SHADER_3D_FLAT_COLOR,
GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR));
- const char *world_clip_lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl;
- const char *world_clip_def = "#define USE_WORLD_CLIP_PLANES\n";
/* In rare cases geometry shaders calculate clipping themselves. */
- if (stages->create_info != NULL) {
- *sh_p = GPU_shader_create_from_info(gpu_shader_create_info_get(stages->create_info));
+ if (stages->clipped_create_info != NULL) {
+ *sh_p = GPU_shader_create_from_info(
+ gpu_shader_create_info_get(stages->clipped_create_info));
}
else {
+ const char *world_clip_lib = datatoc_gpu_shader_cfg_world_clip_lib_glsl;
+ const char *world_clip_def = "#define USE_WORLD_CLIP_PLANES\n";
*sh_p = GPU_shader_create_from_arrays_named(
stages->name,
{
diff --git a/source/blender/gpu/intern/gpu_shader_shared_utils.h b/source/blender/gpu/intern/gpu_shader_shared_utils.h
index 8c79073419c..7e5d2240851 100644
--- a/source/blender/gpu/intern/gpu_shader_shared_utils.h
+++ b/source/blender/gpu/intern/gpu_shader_shared_utils.h
@@ -84,9 +84,6 @@
# include "BLI_float3.hh"
# include "BLI_float4.hh"
# include "BLI_float4x4.hh"
-
-using blender::float2;
-using blender::float4;
/* TODO */
// # include "BLI_int2.hh"
// # include "BLI_int3.hh"
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
index ad8f22381a1..b6132113bc9 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
@@ -1,3 +1,5 @@
+#pragma BLENDER_REQUIRE(gpu_shader_cfg_world_clip_lib.glsl)
+
#ifndef USE_GPU_SHADER_CREATE_INFO
uniform mat4 ModelViewProjectionMatrix;
# ifdef USE_WORLD_CLIP_PLANES
@@ -17,6 +19,6 @@ void main()
finalColor = color;
#ifdef USE_WORLD_CLIP_PLANES
- world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
+ world_clip_planes_calc_clip_distance((clipPlanes.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 b79061dbbc3..cdc716db7a4 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,5 +1,6 @@
#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
@@ -15,6 +16,10 @@ uniform vec4 WorldClipPlanes[6];
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
+# 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) \
diff --git a/source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh b/source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh
index 14f5655c55d..d628a3bfb68 100644
--- a/source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh
+++ b/source/blender/gpu/shaders/infos/gpu_clip_planes_info.hh
@@ -3,4 +3,5 @@
GPU_SHADER_CREATE_INFO(gpu_clip_planes)
.uniform_buf(1, "GPUClipPlanes", "clipPlanes", Frequency::PASS)
+ .typedef_source("GPU_shader_shared.h")
.define("USE_WORLD_CLIP_PLANES");
More information about the Bf-blender-cvs
mailing list