Commit: 2697fa9fec597ba42cb9a85506cb4ad8ab96f238 Author: Jeroen Bakker Date: Thu Apr 26 16:53:22 2018 +0200 Branches: blender2.8-workbench https://developer.blender.org/rB2697fa9fec597ba42cb9a85506cb4ad8ab96f238
Workbench: Shadows pipeline =================================================================== M release/scripts/startup/bl_ui/properties_render.py M release/scripts/startup/bl_ui/space_view3d.py M source/blender/draw/CMakeLists.txt M source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl A source/blender/draw/engines/workbench/shaders/workbench_shadow_geom.glsl A source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl M source/blender/draw/engines/workbench/solid_mode.c M source/blender/draw/engines/workbench/workbench_engine.c M source/blender/draw/engines/workbench/workbench_materials.c M source/blender/draw/engines/workbench/workbench_private.h M source/blender/makesdna/DNA_view3d_types.h M source/blender/makesrna/intern/rna_layer.c M source/blender/makesrna/intern/rna_space.c =================================================================== diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py index 300cb208e05..a7e63b3f7a5 100644 --- a/release/scripts/startup/bl_ui/properties_render.py +++ b/release/scripts/startup/bl_ui/properties_render.py @@ -788,6 +788,8 @@ class RENDER_PT_workbench_environment_light(RenderButtonsPanel, Panel): col.prop(props, "diffuse_light_z_pos", text="Front/Back") col.prop(props, "diffuse_light_z_neg", text="") + layout.prop(props, "light_direction", text="") + classes = ( RENDER_MT_presets, diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 678974c3b4e..6eafd689294 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -3537,6 +3537,7 @@ class VIEW3D_PT_view3d_display(Panel): if view.viewport_shade == "SOLID": col.prop(view, "show_random_object_colors") col.prop(view, "show_object_overlap") + col.prop(view, "show_shadows") if context.mode in {'PAINT_WEIGHT', 'PAINT_VERTEX', 'PAINT_TEXTURE'}: col.prop(view, "show_mode_shade_override") diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 6ee2acecbb4..e6c06c3243a 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -211,6 +211,8 @@ data_to_c_simple(engines/eevee/shaders/volumetric_integration_frag.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_prepass_vert.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_prepass_frag.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_composite_frag.glsl SRC) +data_to_c_simple(engines/workbench/shaders/workbench_shadow_vert.glsl SRC) +data_to_c_simple(engines/workbench/shaders/workbench_shadow_geom.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_background_lib.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_common_lib.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_data_lib.glsl SRC) diff --git a/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl index 0337662955e..1475e1a43e2 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl @@ -6,8 +6,8 @@ uniform sampler2D colorBuffer; uniform sampler2D normalBuffer; /* normalBuffer contains viewport normals */ uniform vec2 invertedViewportSize; - uniform vec3 objectOverlapColor = vec3(0.0); +uniform float lightMultiplier; layout(std140) uniform world_block { WorldData world_data; @@ -52,11 +52,11 @@ void main() vec3 normal_viewport = texelFetch(normalBuffer, texel, 0).rgb; #endif /* WORKBENCH_ENCODE_NORMALS */ vec3 diffuse_light = get_world_diffuse_light(world_data, normal_viewport); - vec3 shaded_color = diffuse_light * diffuse_color.rgb; + vec3 shaded_color = diffuse_light * diffuse_color.rgb * lightMultiplier; #else /* V3D_LIGHTING_STUDIO */ vec3 diffuse_color = texelFetch(colorBuffer, texel, 0).rgb; - vec3 shaded_color = diffuse_color; + vec3 shaded_color = diffuse_color * lightMultiplier; #endif /* V3D_LIGHTING_STUDIO */ diff --git a/source/blender/draw/engines/workbench/shaders/workbench_shadow_geom.glsl b/source/blender/draw/engines/workbench/shaders/workbench_shadow_geom.glsl new file mode 100644 index 00000000000..ac207aed4a3 --- /dev/null +++ b/source/blender/draw/engines/workbench/shaders/workbench_shadow_geom.glsl @@ -0,0 +1,16 @@ +layout(triangles) in; +layout(triangle_strip, max_vertices=3) out; + +uniform vec4 direction = vec4(0.57, 0.57, 0.0, 0.0); + +void main() +{ + for(int i = 0; i < gl_in.length(); i++) + { + vec4 new_pos = gl_in[i].gl_Position; + + new_pos += direction; + gl_Position = new_pos; + EmitVertex(); + } +} \ No newline at end of file diff --git a/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl new file mode 100644 index 00000000000..97639f03734 --- /dev/null +++ b/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl @@ -0,0 +1,8 @@ +uniform mat4 ModelViewProjectionMatrix; + +in vec3 pos; + +void main() +{ + gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); +} diff --git a/source/blender/draw/engines/workbench/solid_mode.c b/source/blender/draw/engines/workbench/solid_mode.c index 7b5900cab39..09d7e9c88a2 100644 --- a/source/blender/draw/engines/workbench/solid_mode.c +++ b/source/blender/draw/engines/workbench/solid_mode.c @@ -59,8 +59,10 @@ static void workbench_solid_cache_finish(void *vedata) workbench_materials_cache_finish(data); } -static void workbench_solid_draw_background(void *UNUSED(vedata)) +static void workbench_solid_draw_background(void *vedata) { + WORKBENCH_Data * data = (WORKBENCH_Data *)vedata; + workbench_materials_draw_background(data); } static void workbench_solid_draw_scene(void *vedata) diff --git a/source/blender/draw/engines/workbench/workbench_engine.c b/source/blender/draw/engines/workbench/workbench_engine.c index d4d14125116..32c8479393e 100644 --- a/source/blender/draw/engines/workbench/workbench_engine.c +++ b/source/blender/draw/engines/workbench/workbench_engine.c @@ -72,6 +72,9 @@ static void workbench_view_layer_settings_create(RenderEngine *UNUSED(engine), I BKE_collection_engine_property_add_float_array(props, "diffuse_light_y_neg", diffuse_y_neg, 3); BKE_collection_engine_property_add_float_array(props, "diffuse_light_z_pos", diffuse_z_pos, 3); BKE_collection_engine_property_add_float_array(props, "diffuse_light_z_neg", diffuse_z_neg, 3); + + const float light_direction[3] = {0.577350269, 0.577350269, 0.577350269}; + BKE_collection_engine_property_add_float_array(props, "light_direction", light_direction, 3); } /* Note: currently unused, we may want to register so we can see this when debugging the view. */ diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c index 1b6927ed3ed..dd44c393da3 100644 --- a/source/blender/draw/engines/workbench/workbench_materials.c +++ b/source/blender/draw/engines/workbench/workbench_materials.c @@ -40,12 +40,15 @@ static struct { struct GPUShader *prepass_sh_cache[MAX_SHADERS]; struct GPUShader *composite_sh_cache[MAX_SHADERS]; + struct GPUShader *shadow_sh; struct GPUTexture *object_id_tx; /* ref only, not alloced */ struct GPUTexture *color_buffer_tx; /* ref only, not alloced */ struct GPUTexture *normal_buffer_tx; /* ref only, not alloced */ int next_object_id; + float light_multiplier; + float shadow_multiplier; } e_data = {NULL}; /* Shaders */ @@ -53,6 +56,9 @@ extern char datatoc_workbench_prepass_vert_glsl[]; extern char datatoc_workbench_prepass_frag_glsl[]; extern char datatoc_workbench_composite_frag_glsl[]; +extern char datatoc_workbench_shadow_vert_glsl[]; +extern char datatoc_workbench_shadow_geom_glsl[]; + extern char datatoc_workbench_background_lib_glsl[]; extern char datatoc_workbench_common_lib_glsl[]; extern char datatoc_workbench_data_lib_glsl[]; @@ -63,6 +69,7 @@ extern DrawEngineType draw_engine_workbench_solid; #define OBJECT_ID_PASS_ENABLED(wpd) (wpd->drawtype_options & V3D_DRAWOPTION_OBJECT_OVERLAP) #define NORMAL_VIEWPORT_PASS_ENABLED(wpd) (wpd->drawtype_lighting & V3D_LIGHTING_STUDIO) +#define SHADOW_ENABLED(wpd) (wpd->drawtype_options & V3D_DRAWOPTION_SHADOW) static char *workbench_build_defines(WORKBENCH_PrivateData *wpd) { @@ -126,7 +133,8 @@ static char *workbench_build_prepass_frag(void) static int get_shader_index(WORKBENCH_PrivateData *wpd) { - return (wpd->drawtype_options << 2) + wpd->drawtype_lighting; + const int DRAWOPTIONS_MASK = V3D_DRAWOPTION_OBJECT_OVERLAP; + return ((wpd->drawtype_options & DRAWOPTIONS_MASK) << 2) + wpd->drawtype_lighting; } static void select_deferred_shaders(WORKBENCH_PrivateData *wpd) @@ -195,6 +203,9 @@ void workbench_materials_engine_init(WORKBENCH_Data *vedata) memset(e_data.prepass_sh_cache, 0x00, sizeof(struct GPUShader *) * MAX_SHADERS); memset(e_data.composite_sh_cache, 0x00, sizeof(struct GPUShader *) * MAX_SHADERS); e_data.next_object_id = 1; + e_data.light_multiplier = 1.0; + e_data.shadow_multiplier = 0.8; + e_data.shadow_sh = DRW_shader_create(datatoc_workbench_shadow_vert_glsl, datatoc_workbench_shadow_geom_glsl, NULL, NULL); } if (!stl->g_data) { @@ -225,6 +236,7 @@ void workbench_materials_engine_init(WORKBENCH_Data *vedata) { int state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS; psl->prepass_pass = DRW_pass_create("Prepass", state); + } } @@ -234,6 +246,22 @@ void workbench_materials_engine_free() DRW_SHADER_FREE_SAFE(e_data.prepass_sh_cache[index]); DRW_SHADER_FREE_SAFE(e_data.composite_sh_cache[index]); } + DRW_SHADER_FREE_SAFE(e_data.shadow_sh); +} + +static void workbench_composite_uniforms(WORKBENCH_PrivateData *wpd, DRWShadingGroup *grp) +{ + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); + DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &e_data.color_buffer_tx); + if (OBJECT_ID_PASS_ENABLED(wpd)) { + DRW_shgroup_uniform_texture_ref(grp, "objectId", &e_data.object_id_tx); + } + if (NORMAL_VIEWPORT_PASS_ENABLED(wpd)) { + DRW_shgroup_uniform_texture_ref(grp, "normalBuffer", &e_data.normal_buffer_tx); + } + DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo); + DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1); } void workbench_materials_cache_init(WORKBENCH_Data *vedata) @@ -241,7 +269,6 @@ void workbench_materials_cache_init(WORKBENCH_Data *vedata) WORKBENCH_StorageList *stl = vedata->stl; WORKBENCH_PassList *psl = vedata->psl; WORKBENCH_PrivateData *wpd = stl->g_data; - DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); DRWShadingGroup *grp; const DRWContextS @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs