diff options
Diffstat (limited to 'source/blender/draw')
8 files changed, 36 insertions, 6 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_data.c b/source/blender/draw/engines/eevee/eevee_data.c index 449668d8590..0b6ab905e32 100644 --- a/source/blender/draw/engines/eevee/eevee_data.c +++ b/source/blender/draw/engines/eevee/eevee_data.c @@ -56,6 +56,7 @@ static void eevee_view_layer_data_free(void *storage) DRW_UBO_FREE_SAFE(sldata->grid_ubo); DRW_UBO_FREE_SAFE(sldata->planar_ubo); DRW_UBO_FREE_SAFE(sldata->common_ubo); + DRW_UBO_FREE_SAFE(sldata->clip_ubo); DRW_FRAMEBUFFER_FREE_SAFE(sldata->probe_fb); DRW_FRAMEBUFFER_FREE_SAFE(sldata->probe_filter_fb); DRW_TEXTURE_FREE_SAFE(sldata->probe_rt); diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c index 9cdde37596b..fca936adb12 100644 --- a/source/blender/draw/engines/eevee/eevee_engine.c +++ b/source/blender/draw/engines/eevee/eevee_engine.c @@ -78,6 +78,9 @@ static void eevee_engine_init(void *ved) if (sldata->common_ubo == NULL) { sldata->common_ubo = DRW_uniformbuffer_create(sizeof(sldata->common_data), &sldata->common_data); } + if (sldata->clip_ubo == NULL) { + sldata->clip_ubo = DRW_uniformbuffer_create(sizeof(sldata->clip_data), &sldata->clip_data); + } /* EEVEE_effects_init needs to go first for TAA */ EEVEE_effects_init(sldata, vedata, camera); diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c index b8e4e52befe..d489462f5d7 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobes.c +++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c @@ -1317,7 +1317,9 @@ static void render_scene_to_planar( /* Since we are rendering with an inverted view matrix, we need * to invert the facing for backface culling to be the same. */ DRW_state_invert_facing(); - + /* Set clipping plan */ + copy_v4_v4(sldata->clip_data.clip_planes[0], ped->planer_eq_offset); + DRW_uniformbuffer_update(sldata->clip_ubo, &sldata->clip_data); DRW_state_clip_planes_count_set(1); /* Attach depth here since it's a DRW_TEX_TEMP */ diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index 6c76a86d491..22ca6ec460e 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -365,6 +365,7 @@ static void add_standard_uniforms( DRW_shgroup_uniform_block(shgrp, "light_block", sldata->light_ubo); DRW_shgroup_uniform_block(shgrp, "shadow_block", sldata->shadow_ubo); DRW_shgroup_uniform_block(shgrp, "common_block", sldata->common_ubo); + DRW_shgroup_uniform_block(shgrp, "clip_block", sldata->clip_ubo); /* TODO if glossy or diffuse bsdf */ if (true) { @@ -934,10 +935,12 @@ void EEVEE_materials_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE; psl->depth_pass_clip = DRW_pass_create("Depth Pass Clip", state); stl->g_data->depth_shgrp_clip = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->depth_pass_clip); + DRW_shgroup_uniform_block(stl->g_data->depth_shgrp_clip, "clip_block", sldata->clip_ubo); state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_CULL_BACK; psl->depth_pass_clip_cull = DRW_pass_create("Depth Pass Cull Clip", state); stl->g_data->depth_shgrp_clip_cull = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->depth_pass_clip_cull); + DRW_shgroup_uniform_block(stl->g_data->depth_shgrp_clip_cull, "clip_block", sldata->clip_ubo); } { @@ -957,10 +960,12 @@ void EEVEE_materials_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE; psl->refract_depth_pass_clip = DRW_pass_create("Refract Depth Pass Clip", state); stl->g_data->refract_depth_shgrp_clip = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->refract_depth_pass_clip); + DRW_shgroup_uniform_block(stl->g_data->refract_depth_shgrp_clip, "clip_block", sldata->clip_ubo); state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_CULL_BACK; psl->refract_depth_pass_clip_cull = DRW_pass_create("Refract Depth Pass Cull Clip", state); stl->g_data->refract_depth_shgrp_clip_cull = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->refract_depth_pass_clip_cull); + DRW_shgroup_uniform_block(stl->g_data->refract_depth_shgrp_clip_cull, "clip_block", sldata->clip_ubo); } { @@ -1083,6 +1088,7 @@ static void material_opaque( if (*shgrp_depth != NULL) { add_standard_uniforms(*shgrp_depth, sldata, vedata, NULL, NULL, false, false); + add_standard_uniforms(*shgrp_depth_clip, sldata, vedata, NULL, NULL, false, false); if (ma->blend_method == MA_BM_CLIP) { DRW_shgroup_uniform_float(*shgrp_depth, "alphaThreshold", &ma->alpha_threshold, 1); @@ -1272,6 +1278,7 @@ static void material_transparent( /* Depth prepass */ if (use_prepass) { *shgrp_depth = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->transparent_pass); + DRW_shgroup_uniform_block(*shgrp_depth, "clip_block", sldata->clip_ubo); cur_state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS; cur_state |= (do_cull) ? DRW_STATE_CULL_BACK : 0; diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 684b5e29266..88fb55cfbdf 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -604,6 +604,12 @@ typedef struct EEVEE_CommonUniformBuffer { float prb_lod_planar_max; /* float */ } EEVEE_CommonUniformBuffer; +/* ***************** CLIP PLANES DATA **************** */ + +typedef struct EEVEE_ClipPlanesUniformBuffer { + float clip_planes[1][4]; /* must be less than MAX_CLIP_PLANES */ +} EEVEE_ClipPlanesUniformBuffer; + /* ************** SCENE LAYER DATA ************** */ typedef struct EEVEE_ViewLayerData { /* Lamps */ @@ -644,6 +650,9 @@ typedef struct EEVEE_ViewLayerData { /* Common Uniform Buffer */ struct EEVEE_CommonUniformBuffer common_data; struct GPUUniformBuffer *common_ubo; + + struct EEVEE_ClipPlanesUniformBuffer clip_data; + struct GPUUniformBuffer *clip_ubo; } EEVEE_ViewLayerData; /* ************ OBJECT DATA ************ */ diff --git a/source/blender/draw/engines/eevee/eevee_render.c b/source/blender/draw/engines/eevee/eevee_render.c index 07a9708342a..7165ed8d7ae 100644 --- a/source/blender/draw/engines/eevee/eevee_render.c +++ b/source/blender/draw/engines/eevee/eevee_render.c @@ -84,6 +84,9 @@ void EEVEE_render_init(EEVEE_Data *ved, RenderEngine *engine, struct Depsgraph * if (sldata->common_ubo == NULL) { sldata->common_ubo = DRW_uniformbuffer_create(sizeof(sldata->common_data), &sldata->common_data); } + if (sldata->clip_ubo == NULL) { + sldata->clip_ubo = DRW_uniformbuffer_create(sizeof(sldata->clip_data), &sldata->clip_data); + } /* Set the pers & view matrix. */ struct Object *camera = RE_GetCamera(engine->re); diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl index 998ccfa453a..d25c49098a6 100644 --- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl @@ -14,7 +14,10 @@ out vec3 worldPosition; out vec3 viewPosition; /* Used for planar reflections */ -uniform vec4 ClipPlanes[1]; +/* keep in sync with EEVEE_ClipPlanesUniformBuffer */ +layout(std140) uniform clip_block { + vec4 ClipPlanes[1]; +}; #ifdef USE_FLAT_NORMAL flat out vec3 worldNormal; diff --git a/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl b/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl index 6f26a815736..c756e061d70 100644 --- a/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl @@ -1,9 +1,11 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelMatrix; -#ifdef CLIP_PLANES -uniform vec4 ClipPlanes[1]; -#endif + +/* keep in sync with DRWManager.view_data */ +layout(std140) uniform clip_block { + vec4 ClipPlanes[1]; +}; in vec3 pos; @@ -12,7 +14,7 @@ void main() gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); #ifdef CLIP_PLANES vec4 worldPosition = (ModelMatrix * vec4(pos, 1.0)); - gl_ClipDistance[0] = dot(worldPosition, ClipPlanes[0]); + gl_ClipDistance[0] = dot(vec4(worldPosition.xyz, 1.0), ClipPlanes[0]); #endif /* TODO motion vectors */ } |