[Bf-blender-cvs] [e4c6746c31c] greasepencil-object: WIP: More work on shaders and framebuffers for DOF
Antonio Vazquez
noreply at git.blender.org
Thu Mar 29 17:58:22 CEST 2018
Commit: e4c6746c31c885b8c7fa3040651944eeb49fe7b6
Author: Antonio Vazquez
Date: Wed Mar 28 19:59:08 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBe4c6746c31c885b8c7fa3040651944eeb49fe7b6
WIP: More work on shaders and framebuffers for DOF
Still there are problems with the alpha factor and all the scene is empty because alpha is always 0.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_depth_of_field.c
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl
M source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_depth_of_field.c b/source/blender/draw/engines/gpencil/gpencil_depth_of_field.c
index 1093d34adce..7f42e697679 100644
--- a/source/blender/draw/engines/gpencil/gpencil_depth_of_field.c
+++ b/source/blender/draw/engines/gpencil/gpencil_depth_of_field.c
@@ -81,9 +81,9 @@ int GPENCIL_depth_of_field_init(DrawEngineType *draw_engine_gpencil_type, GPENCI
/* Setup buffers */
e_data->gpencil_dof_down_near = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGB_11_11_10,
draw_engine_gpencil_type);
- e_data->gpencil_dof_down_far = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGB_11_11_10,
+ e_data->gpencil_dof_down_far = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGB_11_11_10,
draw_engine_gpencil_type);
- e_data->gpencil_dof_coc = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RG_16,
+ e_data->gpencil_dof_coc = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RG_16,
draw_engine_gpencil_type);
e_data->gpencil_dof_alpha = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_R_16,
draw_engine_gpencil_type);
@@ -195,13 +195,14 @@ void GPENCIL_depth_of_field_cache_init(GPENCIL_e_data *e_data, GPENCIL_Data *ved
DRW_shgroup_uniform_vec2(grp, "layerSelection", stl->storage->dof_layer_select, 1);
DRW_shgroup_uniform_vec4(grp, "bokehParams", stl->storage->dof_bokeh, 1);
- psl->dof_resolve = DRW_pass_create("DoF Resolve", DRW_STATE_WRITE_COLOR);
+ psl->dof_resolve = DRW_pass_create("DoF Resolve", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
grp = DRW_shgroup_create(e_data->gpencil_dof_resolve_sh, psl->dof_resolve);
DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &e_data->input_color_tx);
DRW_shgroup_uniform_texture_ref(grp, "nearBuffer", &e_data->gpencil_dof_near_blur);
DRW_shgroup_uniform_texture_ref(grp, "farBuffer", &e_data->gpencil_dof_far_blur);
DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &e_data->input_depth_tx);
+ DRW_shgroup_uniform_texture_ref(grp, "alphaBuffer", &e_data->gpencil_dof_alpha);
DRW_shgroup_uniform_vec2(grp, "nearFar", stl->storage->dof_near_far, 1);
DRW_shgroup_uniform_vec3(grp, "dofParams", stl->storage->dof_params, 1);
DRW_shgroup_call_add(grp, quad, NULL);
@@ -239,13 +240,9 @@ void GPENCIL_depth_of_field_draw(GPENCIL_e_data *e_data, GPENCIL_Data *vedata)
GPU_framebuffer_clear_color(fbl->dof_scatter_near_fb, clear_col);
DRW_draw_pass(psl->dof_scatter);
- /* Resolve to default pass */
- if ((!is_render) || (fbl->main == NULL)) {
- GPU_framebuffer_bind(dfbl->default_fb);
- }
- else {
- GPU_framebuffer_bind(fbl->main);
- }
+ /* Resolve to temp texture pass */
+ GPU_framebuffer_bind(fbl->vfx_fb_b);
+ GPU_framebuffer_clear_color_depth(fbl->vfx_fb_b, clear_col, 1.0f);
DRW_draw_pass(psl->dof_resolve);
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index f1192b240a7..32e94eed055 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -830,9 +830,15 @@ static void GPENCIL_draw_scene(void *vedata)
e_data.input_color_tx = e_data.temp_color_tx;
}
- /* depth of field */
+ /* depth of field effect
+ * send always to tx_b because other textures can be in use. Remap input
+ * textures too.
+ */
if ((GP_IS_CAMERAVIEW) || (is_render)) {
GPENCIL_depth_of_field_draw(&e_data, vedata);
+
+ e_data.input_depth_tx = e_data.vfx_depth_tx_b;
+ e_data.input_color_tx = e_data.vfx_color_tx_b;
}
/* Combine with scene buffer */
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl
index 7c8c6e2e053..ed5b3db3455 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_dof_frag.glsl
@@ -138,6 +138,7 @@ void step_downsample(void)
float max_far_coc = max(max4(coc_far), 0.0);
fragData2 = vec4(max_near_coc, max_far_coc, 0.0, 1.0);
+ fragData3 = weight;
}
/* coordinate used for calculating radius et al set in geometry shader */
@@ -170,12 +171,14 @@ void step_scatter(void)
}
fragData0 = color;
+ fragData3 = weight;
}
#define MERGE_THRESHOLD 4.0
uniform sampler2D farBuffer;
uniform sampler2D nearBuffer;
+uniform sampler2D alphaBuffer;
vec4 upsample_filter_high(sampler2D tex, vec2 uv, vec2 texelSize)
{
@@ -217,6 +220,8 @@ void step_resolve(void)
{
/* Recompute Near / Far CoC */
float depth = textureLod(depthBuffer, uvcoord, 0.0).r;
+ float alpha = textureLod(alphaBuffer, uvcoord, 0.0).r;
+
float zdepth = linear_depth(depth);
float coc_signed = calculate_coc(zdepth);
float coc_far = max(-coc_signed, 0.0);
@@ -251,7 +256,10 @@ void step_resolve(void)
fragData0 = mix(finalcolor, nearcolor, nearweight / totalweight);
}
- fragData3 = weight;
+ /* apply alpha TODO */
+ fragData0.a = alpha;
+
+ gl_FragDepth = depth;
}
void main()
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl
index 4eac0d33b17..656f937815c 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_dof_vert.glsl
@@ -48,7 +48,7 @@ void step_scatter()
}
else {
color = vec4(0.0);
- weight = 0;
+ weight = texelFetch(colorBuffer, texelco, 0).a;
}
/* Generate Triangle : less memory fetches from a VBO */
More information about the Bf-blender-cvs
mailing list