Commit: f52a7a0a4c118967c09b4a034911a9d9816935b9 Author: Lukas Tönne Date: Fri Jun 29 11:13:11 2018 +0100 Branches: hair_guides_grooming https://developer.blender.org/rBf52a7a0a4c118967c09b4a034911a9d9816935b9
Enable groom drawing in forward shading of the workbench engine. =================================================================== M source/blender/draw/engines/eevee/eevee_materials.c M source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl M source/blender/draw/engines/workbench/workbench_deferred.c M source/blender/draw/engines/workbench/workbench_forward.c M source/blender/draw/intern/draw_hair_fibers.c =================================================================== diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index c455669d117..e76b2636a18 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -1549,10 +1549,16 @@ static void material_hair( } { - /*DRWShadingGroup *shgrp =*/ DRW_shgroup_hair_fibers_create(scene, ob, hsys, scalp, draw_set, psl->depth_pass, e_data.default_prepass_hair_fiber_sh); + /*DRWShadingGroup *shgrp =*/ DRW_shgroup_hair_fibers_create( + scene, ob, hsys, scalp, draw_set, + psl->depth_pass, + e_data.default_prepass_hair_fiber_sh); } { - DRWShadingGroup *shgrp = DRW_shgroup_hair_fibers_create(scene, ob, hsys, scalp, draw_set, psl->depth_pass_clip, e_data.default_prepass_hair_fiber_clip_sh); + DRWShadingGroup *shgrp = DRW_shgroup_hair_fibers_create( + scene, ob, hsys, scalp, draw_set, + psl->depth_pass_clip, + e_data.default_prepass_hair_fiber_clip_sh); DRW_shgroup_uniform_block(shgrp, "clip_block", sldata->clip_ubo); } @@ -1575,9 +1581,9 @@ static void material_hair( case GPU_MAT_SUCCESS: { shgrp = DRW_shgroup_material_hair_fibers_create( - scene, ob, hsys, scalp, - draw_set, psl->material_pass, - gpumat); + scene, ob, hsys, scalp, draw_set, + psl->material_pass, + gpumat); add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, false); break; } 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 fbcdfd66572..03efa4507d2 100644 --- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl @@ -49,6 +49,7 @@ void main() bool is_persp = (ProjectionMatrix[3][3] == 0.0); # ifdef HAIR_SHADER_FIBERS + hairStrandID = fiber_index; vec3 pos, tang, binor; hair_fiber_get_vertex( fiber_index, curve_param, @@ -60,7 +61,7 @@ void main() gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz; worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz; - hairTangent = (ModelMatrix * vec4(tang, 0.0)).xyz; + hairTangent = normalize((ModelMatrix * vec4(tang, 0.0)).xyz); worldNormal = (ModelMatrix * vec4(nor, 0.0)).xyz; viewNormal = normalize(mat3(ViewMatrix) * worldNormal); # else diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c index 39c7d963bf2..e26a58a7040 100644 --- a/source/blender/draw/engines/workbench/workbench_deferred.c +++ b/source/blender/draw/engines/workbench/workbench_deferred.c @@ -668,6 +668,7 @@ static void workbench_cache_populate_groom(WORKBENCH_Data *vedata, Object *ob) WORKBENCH_PassList *psl = vedata->psl; WORKBENCH_PrivateData *wpd = stl->g_data; const DRWContextState *draw_ctx = DRW_context_state_get(); + struct Mesh *scalp = BKE_groom_get_scalp(draw_ctx->depsgraph, groom); Image *image = NULL; Material *mat = give_current_material(ob, groom->material_index); @@ -678,14 +679,10 @@ static void workbench_cache_populate_groom(WORKBENCH_Data *vedata, Object *ob) struct GPUShader *shader = (color_type != V3D_SHADING_TEXTURE_COLOR) ? wpd->prepass_solid_hair_fibers_sh : wpd->prepass_texture_hair_fibers_sh; - - struct Mesh *scalp = BKE_groom_get_scalp(draw_ctx->depsgraph, groom); - DRWShadingGroup *shgrp = DRW_shgroup_hair_fibers_create( - draw_ctx->scene, ob, groom->hair_system, scalp, - draw_set, psl->prepass_hair_pass, + draw_ctx->scene, ob, groom->hair_system, scalp, draw_set, + psl->prepass_hair_pass, shader); - DRW_shgroup_stencil_mask(shgrp, 0xFF); DRW_shgroup_uniform_int(shgrp, "object_id", &material->object_id, 1); DRW_shgroup_uniform_block(shgrp, "material_block", material->material_ubo); diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c index 776086989df..a743f697277 100644 --- a/source/blender/draw/engines/workbench/workbench_forward.c +++ b/source/blender/draw/engines/workbench/workbench_forward.c @@ -478,6 +478,7 @@ static void workbench_forward_cache_populate_groom(WORKBENCH_Data *vedata, Objec WORKBENCH_PassList *psl = vedata->psl; WORKBENCH_PrivateData *wpd = stl->g_data; const DRWContextState *draw_ctx = DRW_context_state_get(); + struct Mesh *scalp = BKE_groom_get_scalp(draw_ctx->depsgraph, groom); Image *image = NULL; Material *mat = give_current_material(ob, groom->material_index); @@ -486,34 +487,35 @@ static void workbench_forward_cache_populate_groom(WORKBENCH_Data *vedata, Objec WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, ob, mat, image, color_type); struct GPUShader *shader = (color_type != V3D_SHADING_TEXTURE_COLOR) - ? wpd->transparent_accum_hair_fibers_sh - : wpd->transparent_accum_texture_hair_fibers_sh; - - struct Mesh *scalp = BKE_groom_get_scalp(draw_ctx->depsgraph, groom); - + ? wpd->transparent_accum_hair_fibers_sh + : wpd->transparent_accum_texture_hair_fibers_sh; DRWShadingGroup *shgrp = DRW_shgroup_hair_fibers_create( - draw_ctx->scene, ob, groom->hair_system, scalp, - draw_set, psl->transparent_accum_pass, + draw_ctx->scene, ob, groom->hair_system, scalp, draw_set, + psl->transparent_accum_pass, shader); workbench_material_set_normal_world_matrix(shgrp, wpd, e_data.normal_world_matrix); DRW_shgroup_uniform_block(shgrp, "world_block", wpd->world_ubo); DRW_shgroup_uniform_block(shgrp, "material_block", material->material_ubo); - DRW_shgroup_uniform_float(shgrp, "alpha", &wpd->shading.xray_alpha, 1); + DRW_shgroup_uniform_vec4(shgrp, "viewvecs[0]", (float *)wpd->viewvecs, 3); + /* Hairs have lots of layer and can rapidly become the most prominent surface. + * So lower their alpha artificially. */ + float hair_alpha = wpd->shading.xray_alpha * 0.33f; + DRW_shgroup_uniform_float_copy(shgrp, "alpha", hair_alpha); if (image) { GPUTexture *tex = GPU_texture_from_blender(image, NULL, GL_TEXTURE_2D, false, 0.0f); DRW_shgroup_uniform_texture(shgrp, "image", tex); } -#ifdef WORKBENCH_REVEALAGE_ENABLED - shgrp = DRW_shgroup_hair_fibers_create( - draw_ctx->scene, ob, groom->hair_system, scalp, - draw_set, psl->transparent_revealage_pass, - e_data.transparent_revealage_hair_sh); - DRW_shgroup_uniform_float(shgrp, "alpha", &wpd->shading.xray_alpha, 1); -#endif + if (STUDIOLIGHT_ORIENTATION_VIEWNORMAL_ENABLED(wpd)) { + BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE); + DRW_shgroup_uniform_texture(shgrp, "matcapImage", wpd->studio_light->equirectangular_radiance_gputexture); + } + if (SPECULAR_HIGHLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) { + DRW_shgroup_uniform_vec2(shgrp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1); + } shgrp = DRW_shgroup_hair_fibers_create( draw_ctx->scene, ob, groom->hair_system, scalp, draw_set, vedata->psl->object_outline_pass, - e_data.object_outline_hair_sh); + e_data.object_outline_hair_fibers_sh); DRW_shgroup_uniform_int(shgrp, "object_id", &material->object_id, 1); } @@ -537,7 +539,7 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob) } WORKBENCH_MaterialData *material; - if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) { + if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_GROOM)) { const DRWContextState *draw_ctx = DRW_context_state_get(); const bool is_active = (ob == draw_ctx->obact); const bool is_sculpt_mode = is_active && (draw_ctx->object_mode & OB_MODE_SCULPT) != 0; diff --git a/source/blender/draw/intern/draw_hair_fibers.c b/source/blender/draw/intern/draw_hair_fibers.c index 622a791ead9..eccd65cd507 100644 --- a/source/blender/draw/intern/draw_hair_fibers.c +++ b/source/blender/draw/intern/draw_hair_fibers.c @@ -48,12 +48,13 @@ const char* DRW_hair_shader_defines(void) } static DRWShadingGroup *drw_shgroup_create_hair_fibers_ex( - Scene *UNUSED(scene), Object *object, HairSystem *hsys, struct Mesh *scalp, + Scene *scene, Object *object, HairSystem *hsys, struct Mesh *scalp, const HairDrawSettings *draw_set, DRWPass *hair_pass, struct GPUMaterial *gpu_mat, GPUShader *gpu_shader) { /* TODO */ const int subdiv = 0; + int thickness_res = (scene->r.hair_type == SCE_HAIR_SHAPE_STRAND) ? 1 : 2; HairExportCache *hair_export = BKE_hair_export_cache_new(); BKE_hair_export_cache_update(hair_export, hsys, subdiv, scalp, HAIR_EXPORT_ALL); @@ -85,6 +86,7 @@ static DRWShadingGroup *drw_shgroup_create_hair_fibers_ex( DRW_shgroup_uniform_int(shgrp, "strand_vertex_start", &fiber_buffer->strand_vertex_start, 1); DRW_shgroup_uniform_int(shgrp, "fiber_start", &fiber_buffer->fiber_start, 1); + DRW_shgroup_uniform_int_copy(shgrp, "hairThicknessRes", thickness_res); DRW_shgroup_uniform_float(shgrp, "hairRadShape", &draw_set->shape, 1); DRW_shgroup_uniform_float_copy(shgrp, "hairRadRoot", draw_set->root_radius * draw_set->radius_scale* 0.5f); DRW_shgroup_uniform_float_copy(shgrp, "hairRadTip", draw_set->tip_radius * draw_set->radius_scale * 0.5f); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs