diff options
Diffstat (limited to 'source/blender/draw/engines')
6 files changed, 20 insertions, 24 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl index e821581298d..66372f82b89 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl @@ -6,11 +6,6 @@ uniform mat4 ViewProjectionMatrix; uniform mat4 ViewMatrixInverse; uniform mat3 NormalMatrix; -#ifdef USE_WORLD_CLIP_PLANES -uniform vec4 WorldClipPlanes[6]; -uniform int WorldClipPlanesLen; -#endif - #ifndef HAIR_SHADER in vec3 pos; in vec3 nor; @@ -76,12 +71,7 @@ void main() #endif #ifdef USE_WORLD_CLIP_PLANES - { - vec3 worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - for (int i = 0; i < WorldClipPlanesLen; i++) { - gl_ClipDistance[i] = dot(WorldClipPlanes[i].xyz, worldPosition) + WorldClipPlanes[i].w; - } - } + world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); #endif } diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c index 60bcae3eee3..38787210036 100644 --- a/source/blender/draw/engines/workbench/workbench_data.c +++ b/source/blender/draw/engines/workbench/workbench_data.c @@ -91,12 +91,11 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd) { RegionView3D *rv3d = draw_ctx->rv3d; if (rv3d->rflag & RV3D_CLIPPING) { - wpd->world_clip_planes_len = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6; - memcpy(wpd->world_clip_planes, rv3d->clip, sizeof(float[4]) * wpd->world_clip_planes_len); - DRW_state_clip_planes_len_set(wpd->world_clip_planes_len); + wpd->world_clip_planes = rv3d->clip; + DRW_state_clip_planes_set_from_rv3d(rv3d); } else { - wpd->world_clip_planes_len = 0; + wpd->world_clip_planes = NULL; } } diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c index 3f537f6c6d0..dce30a7056b 100644 --- a/source/blender/draw/engines/workbench/workbench_deferred.c +++ b/source/blender/draw/engines/workbench/workbench_deferred.c @@ -90,6 +90,7 @@ static struct { /* Shaders */ extern char datatoc_common_hair_lib_glsl[]; +extern char datatoc_common_world_clip_lib_glsl[]; extern char datatoc_workbench_prepass_vert_glsl[]; extern char datatoc_workbench_prepass_frag_glsl[]; @@ -159,12 +160,15 @@ static char *workbench_build_prepass_vert(bool is_hair) { char *str = NULL; if (!is_hair) { - return BLI_strdup(datatoc_workbench_prepass_vert_glsl); + return BLI_string_joinN( + datatoc_common_world_clip_lib_glsl, + datatoc_workbench_prepass_vert_glsl); } DynStr *ds = BLI_dynstr_new(); BLI_dynstr_append(ds, datatoc_common_hair_lib_glsl); + BLI_dynstr_append(ds, datatoc_common_world_clip_lib_glsl); BLI_dynstr_append(ds, datatoc_workbench_prepass_vert_glsl); str = BLI_dynstr_get_cstring(ds); diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c index 94cbb20ef5f..485348f65f3 100644 --- a/source/blender/draw/engines/workbench/workbench_forward.c +++ b/source/blender/draw/engines/workbench/workbench_forward.c @@ -29,6 +29,7 @@ #include "BLI_alloca.h" #include "BLI_dynstr.h" +#include "BLI_string_utils.h" #include "BLI_utildefines.h" #include "BKE_node.h" @@ -66,6 +67,7 @@ static struct { } e_data = {{NULL}}; /* Shaders */ +extern char datatoc_common_world_clip_lib_glsl[]; extern char datatoc_common_hair_lib_glsl[]; extern char datatoc_workbench_forward_composite_frag_glsl[]; @@ -85,12 +87,15 @@ static char *workbench_build_forward_vert(bool is_hair) { char *str = NULL; if (!is_hair) { - return BLI_strdup(datatoc_workbench_prepass_vert_glsl); + return BLI_string_joinN( + datatoc_common_world_clip_lib_glsl, + datatoc_workbench_prepass_vert_glsl); } DynStr *ds = BLI_dynstr_new(); BLI_dynstr_append(ds, datatoc_common_hair_lib_glsl); + BLI_dynstr_append(ds, datatoc_common_world_clip_lib_glsl); BLI_dynstr_append(ds, datatoc_workbench_prepass_vert_glsl); str = BLI_dynstr_get_cstring(ds); diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c index ce71189f344..d19f9293af9 100644 --- a/source/blender/draw/engines/workbench/workbench_materials.c +++ b/source/blender/draw/engines/workbench/workbench_materials.c @@ -110,7 +110,7 @@ char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, bool use_text if (is_hair) { BLI_dynstr_appendf(ds, "#define HAIR_SHADER\n"); } - if (wpd->world_clip_planes_len) { + if (wpd->world_clip_planes != NULL) { BLI_dynstr_appendf(ds, "#define USE_WORLD_CLIP_PLANES\n"); } @@ -171,7 +171,7 @@ int workbench_material_get_prepass_shader_index( SET_FLAG_FROM_TEST(index, NORMAL_VIEWPORT_PASS_ENABLED(wpd), 1 << 3); SET_FLAG_FROM_TEST(index, MATCAP_ENABLED(wpd), 1 << 4); SET_FLAG_FROM_TEST(index, use_textures, 1 << 5); - SET_FLAG_FROM_TEST(index, wpd->world_clip_planes_len != 0, 1 << 6); + SET_FLAG_FROM_TEST(index, wpd->world_clip_planes != NULL, 1 << 6); return index; } @@ -241,9 +241,8 @@ void workbench_material_shgroup_uniform( DRW_shgroup_uniform_float(grp, "materialRoughness", &material->roughness, 1); } - if (wpd->world_clip_planes_len) { - DRW_shgroup_uniform_vec4(grp, "WorldClipPlanes", wpd->world_clip_planes[0], wpd->world_clip_planes_len); - DRW_shgroup_uniform_int(grp, "WorldClipPlanesLen", &wpd->world_clip_planes_len, 1); + if (wpd->world_clip_planes != NULL) { + DRW_shgroup_uniform_vec4(grp, "WorldClipPlanes", wpd->world_clip_planes[0], 6); DRW_shgroup_state_enable(grp, DRW_STATE_CLIP_PLANES); } } diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h index a4cfd297516..82d84fef67a 100644 --- a/source/blender/draw/engines/workbench/workbench_private.h +++ b/source/blender/draw/engines/workbench/workbench_private.h @@ -200,8 +200,7 @@ typedef struct WORKBENCH_PrivateData { bool shadow_changed; bool is_playback; - float world_clip_planes[6][4]; - int world_clip_planes_len; + float (*world_clip_planes)[4]; /* Volumes */ bool volumes_do; |