diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-03-16 00:17:07 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-03-16 00:33:02 +0300 |
commit | 66225e84cfeb6d05ae25cc60c6c467b29afb190b (patch) | |
tree | d08b8d1ac97f01e7cbafe535d571882e6b7e8e5e /source/blender/draw/engines | |
parent | fe40e184a697c1235a696356b24e8c45dc06185a (diff) |
Eevee: DOF: Optimization: Move some operations out of the shader
Diffstat (limited to 'source/blender/draw/engines')
3 files changed, 11 insertions, 11 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_depth_of_field.c b/source/blender/draw/engines/eevee/eevee_depth_of_field.c index 597cb830afb..7f754a5a466 100644 --- a/source/blender/draw/engines/eevee/eevee_depth_of_field.c +++ b/source/blender/draw/engines/eevee/eevee_depth_of_field.c @@ -153,9 +153,10 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *v sensor_scaled *= rv3d->viewcamtexcofac[0]; } - effects->dof_params[0] = aperture * fabsf(focal_len_scaled / (focus_dist - focal_len_scaled)); - effects->dof_params[1] = -focus_dist; - effects->dof_params[2] = viewport_size[0] / sensor_scaled; + effects->dof_params[1] = aperture * fabsf(focal_len_scaled / (focus_dist - focal_len_scaled)); + effects->dof_params[1] *= viewport_size[0] / sensor_scaled; + effects->dof_params[0] = -focus_dist * effects->dof_params[1]; + effects->dof_bokeh[0] = rotation; effects->dof_bokeh[1] = ratio; effects->dof_bokeh[2] = scene_eval->eevee.bokeh_max_size; @@ -204,7 +205,7 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_ DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->source_buffer); DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); DRW_shgroup_uniform_vec2(grp, "nearFar", effects->dof_near_far, 1); - DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1); + DRW_shgroup_uniform_vec2(grp, "dofParams", effects->dof_params, 1); DRW_shgroup_call_add(grp, quad, NULL); psl->dof_scatter = DRW_pass_create("DoF Scatter", DRW_STATE_WRITE_COLOR | DRW_STATE_ADDITIVE_FULL); @@ -226,7 +227,7 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_ DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->source_buffer); DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); DRW_shgroup_uniform_vec2(grp, "nearFar", effects->dof_near_far, 1); - DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1); + DRW_shgroup_uniform_vec2(grp, "dofParams", effects->dof_params, 1); DRW_shgroup_call_add(grp, quad, NULL); if (use_alpha) { diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 7ffe7f46811..e0ee689f5df 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -574,7 +574,7 @@ typedef struct EEVEE_EffectsInfo { struct GPUTexture *velocity_tx; /* Texture from pool */ /* Depth Of Field */ float dof_near_far[2]; - float dof_params[3]; + float dof_params[2]; float dof_bokeh[4]; float dof_bokeh_sides[4]; int dof_target_size[2]; diff --git a/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl index 6aa771bcbd5..91a4ca99f7e 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl @@ -4,11 +4,10 @@ uniform mat4 ProjectionMatrix; uniform sampler2D colorBuffer; uniform sampler2D depthBuffer; -uniform vec3 dofParams; +uniform vec2 dofParams; -#define dof_aperturesize dofParams.x -#define dof_distance dofParams.y -#define dof_invsensorsize dofParams.z +#define dof_mul dofParams.x /* distance * aperturesize * invsensorsize */ +#define dof_bias dofParams.y /* aperturesize * invsensorsize */ uniform vec4 bokehParams[2]; @@ -25,7 +24,7 @@ uniform vec2 nearFar; /* Near & far view depths values */ /* -------------- Utils ------------- */ /* divide by sensor size to get the normalized size */ -#define calculate_coc(zdepth) (dof_aperturesize * (dof_distance / zdepth - 1.0) * dof_invsensorsize) +#define calculate_coc(zdepth) (dof_mul / zdepth - dof_bias) #define linear_depth(z) ((ProjectionMatrix[3][3] == 0.0) \ ? (nearFar.x * nearFar.y) / (z * (nearFar.x - nearFar.y) + nearFar.y) \ |