Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_deferred.c
| Show First 20 Lines • Show All 209 Lines • ▼ Show 20 Lines | if (*sh == NULL) { | ||||
| MEM_freeN(cavity_frag); | MEM_freeN(cavity_frag); | ||||
| } | } | ||||
| return *sh; | return *sh; | ||||
| } | } | ||||
| static GPUShader *ensure_deferred_prepass_shader(WORKBENCH_PrivateData *wpd, | static GPUShader *ensure_deferred_prepass_shader(WORKBENCH_PrivateData *wpd, | ||||
| bool is_uniform_color, | bool is_uniform_color, | ||||
| bool is_hair, | bool is_hair, | ||||
| bool is_texture_painting, | |||||
| eGPUShaderConfig sh_cfg) | eGPUShaderConfig sh_cfg) | ||||
| { | { | ||||
| WORKBENCH_DEFERRED_Shaders *sh_data = &e_data.sh_data[sh_cfg]; | WORKBENCH_DEFERRED_Shaders *sh_data = &e_data.sh_data[sh_cfg]; | ||||
| int index = workbench_material_get_prepass_shader_index(wpd, is_uniform_color, is_hair); | int index = workbench_material_get_prepass_shader_index( | ||||
| wpd, is_uniform_color, is_hair, is_texture_painting); | |||||
| if (sh_data->prepass_sh_cache[index] == NULL) { | if (sh_data->prepass_sh_cache[index] == NULL) { | ||||
| const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; | const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; | ||||
| char *defines = workbench_material_build_defines(wpd, is_uniform_color, is_hair); | char *defines = workbench_material_build_defines( | ||||
| wpd, is_uniform_color, is_hair, is_texture_painting); | |||||
| char *prepass_vert = workbench_build_prepass_vert(is_hair); | char *prepass_vert = workbench_build_prepass_vert(is_hair); | ||||
| char *prepass_frag = workbench_build_prepass_frag(); | char *prepass_frag = workbench_build_prepass_frag(); | ||||
| sh_data->prepass_sh_cache[index] = GPU_shader_create_from_arrays({ | sh_data->prepass_sh_cache[index] = GPU_shader_create_from_arrays({ | ||||
| .vert = (const char *[]){sh_cfg_data->lib, prepass_vert, NULL}, | .vert = (const char *[]){sh_cfg_data->lib, prepass_vert, NULL}, | ||||
| .frag = (const char *[]){prepass_frag, NULL}, | .frag = (const char *[]){prepass_frag, NULL}, | ||||
| .defs = (const char *[]){sh_cfg_data->def, defines, NULL}, | .defs = (const char *[]){sh_cfg_data->def, defines, NULL}, | ||||
| }); | }); | ||||
| MEM_freeN(prepass_vert); | MEM_freeN(prepass_vert); | ||||
| MEM_freeN(prepass_frag); | MEM_freeN(prepass_frag); | ||||
| MEM_freeN(defines); | MEM_freeN(defines); | ||||
| } | } | ||||
| return sh_data->prepass_sh_cache[index]; | return sh_data->prepass_sh_cache[index]; | ||||
| } | } | ||||
| static GPUShader *ensure_deferred_composite_shader(WORKBENCH_PrivateData *wpd) | static GPUShader *ensure_deferred_composite_shader(WORKBENCH_PrivateData *wpd) | ||||
| { | { | ||||
| int index = workbench_material_get_composite_shader_index(wpd); | int index = workbench_material_get_composite_shader_index(wpd); | ||||
| if (e_data.composite_sh_cache[index] == NULL) { | if (e_data.composite_sh_cache[index] == NULL) { | ||||
| char *defines = workbench_material_build_defines(wpd, false, false); | char *defines = workbench_material_build_defines(wpd, false, false, false); | ||||
| char *composite_frag = workbench_build_composite_frag(wpd); | char *composite_frag = workbench_build_composite_frag(wpd); | ||||
| e_data.composite_sh_cache[index] = DRW_shader_create_fullscreen(composite_frag, defines); | e_data.composite_sh_cache[index] = DRW_shader_create_fullscreen(composite_frag, defines); | ||||
| MEM_freeN(composite_frag); | MEM_freeN(composite_frag); | ||||
| MEM_freeN(defines); | MEM_freeN(defines); | ||||
| } | } | ||||
| return e_data.composite_sh_cache[index]; | return e_data.composite_sh_cache[index]; | ||||
| } | } | ||||
| Show All 10 Lines | if (e_data.background_sh[index] == NULL) { | ||||
| e_data.background_sh[index] = DRW_shader_create_fullscreen(frag, defines); | e_data.background_sh[index] = DRW_shader_create_fullscreen(frag, defines); | ||||
| MEM_freeN(frag); | MEM_freeN(frag); | ||||
| } | } | ||||
| return e_data.background_sh[index]; | return e_data.background_sh[index]; | ||||
| } | } | ||||
| static void select_deferred_shaders(WORKBENCH_PrivateData *wpd, eGPUShaderConfig sh_cfg) | static void select_deferred_shaders(WORKBENCH_PrivateData *wpd, eGPUShaderConfig sh_cfg) | ||||
| { | { | ||||
| wpd->prepass_sh = ensure_deferred_prepass_shader(wpd, false, false, sh_cfg); | wpd->prepass_sh = ensure_deferred_prepass_shader(wpd, false, false, false, sh_cfg); | ||||
| wpd->prepass_hair_sh = ensure_deferred_prepass_shader(wpd, false, true, sh_cfg); | wpd->prepass_hair_sh = ensure_deferred_prepass_shader(wpd, false, true, false, sh_cfg); | ||||
| wpd->prepass_uniform_sh = ensure_deferred_prepass_shader(wpd, true, false, sh_cfg); | wpd->prepass_uniform_sh = ensure_deferred_prepass_shader(wpd, true, false, false, sh_cfg); | ||||
| wpd->prepass_uniform_hair_sh = ensure_deferred_prepass_shader(wpd, true, true, sh_cfg); | wpd->prepass_uniform_hair_sh = ensure_deferred_prepass_shader(wpd, true, true, false, sh_cfg); | ||||
| wpd->prepass_textured_sh = ensure_deferred_prepass_shader(wpd, false, false, true, sh_cfg); | |||||
| wpd->composite_sh = ensure_deferred_composite_shader(wpd); | wpd->composite_sh = ensure_deferred_composite_shader(wpd); | ||||
| wpd->background_sh = ensure_background_shader(wpd); | wpd->background_sh = ensure_background_shader(wpd); | ||||
| } | } | ||||
| /* Using Hammersley distribution */ | /* Using Hammersley distribution */ | ||||
| static float *create_disk_samples(int num_samples, int num_iterations) | static float *create_disk_samples(int num_samples, int num_iterations) | ||||
| { | { | ||||
| /* vec4 to ensure memory alignment. */ | /* vec4 to ensure memory alignment. */ | ||||
| ▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | if (OIT_ENABLED(wpd)) { | ||||
| e_data.color_buffer_tx = NULL; | e_data.color_buffer_tx = NULL; | ||||
| e_data.composite_buffer_tx = NULL; | e_data.composite_buffer_tx = NULL; | ||||
| e_data.normal_buffer_tx = NULL; | e_data.normal_buffer_tx = NULL; | ||||
| e_data.cavity_buffer_tx = NULL; | e_data.cavity_buffer_tx = NULL; | ||||
| e_data.composite_buffer_tx = DRW_texture_pool_query_2d( | e_data.composite_buffer_tx = DRW_texture_pool_query_2d( | ||||
| size[0], size[1], comp_tex_format, &draw_engine_workbench_solid); | size[0], size[1], comp_tex_format, &draw_engine_workbench_solid); | ||||
| if (MATDATA_PASS_ENABLED(wpd) || GPU_unused_fb_slot_workaround()) { | if (workbench_is_matdata_pass_enabled(wpd) || GPU_unused_fb_slot_workaround()) { | ||||
| e_data.color_buffer_tx = DRW_texture_pool_query_2d( | e_data.color_buffer_tx = DRW_texture_pool_query_2d( | ||||
| size[0], size[1], col_tex_format, &draw_engine_workbench_solid); | size[0], size[1], col_tex_format, &draw_engine_workbench_solid); | ||||
| } | } | ||||
| if (OBJECT_ID_PASS_ENABLED(wpd) || GPU_unused_fb_slot_workaround()) { | if (OBJECT_ID_PASS_ENABLED(wpd) || GPU_unused_fb_slot_workaround()) { | ||||
| e_data.object_id_tx = DRW_texture_pool_query_2d( | e_data.object_id_tx = DRW_texture_pool_query_2d( | ||||
| size[0], size[1], id_tex_format, &draw_engine_workbench_solid); | size[0], size[1], id_tex_format, &draw_engine_workbench_solid); | ||||
| } | } | ||||
| if (NORMAL_VIEWPORT_PASS_ENABLED(wpd)) { | if (NORMAL_VIEWPORT_PASS_ENABLED(wpd)) { | ||||
| Show All 23 Lines | GPU_framebuffer_ensure_config(&fbl->composite_fb, | ||||
| GPU_ATTACHMENT_TEXTURE(e_data.composite_buffer_tx), | GPU_ATTACHMENT_TEXTURE(e_data.composite_buffer_tx), | ||||
| }); | }); | ||||
| GPU_framebuffer_ensure_config(&fbl->color_only_fb, | GPU_framebuffer_ensure_config(&fbl->color_only_fb, | ||||
| { | { | ||||
| GPU_ATTACHMENT_NONE, | GPU_ATTACHMENT_NONE, | ||||
| GPU_ATTACHMENT_TEXTURE(e_data.composite_buffer_tx), | GPU_ATTACHMENT_TEXTURE(e_data.composite_buffer_tx), | ||||
| }); | }); | ||||
| if (!MATDATA_PASS_ENABLED(wpd) && !GPU_unused_fb_slot_workaround()) { | if (!workbench_is_matdata_pass_enabled(wpd) && !GPU_unused_fb_slot_workaround()) { | ||||
| e_data.color_buffer_tx = DRW_texture_pool_query_2d( | e_data.color_buffer_tx = DRW_texture_pool_query_2d( | ||||
| size[0], size[1], col_tex_format, &draw_engine_workbench_solid); | size[0], size[1], col_tex_format, &draw_engine_workbench_solid); | ||||
| } | } | ||||
| GPU_framebuffer_ensure_config(&fbl->effect_fb, | GPU_framebuffer_ensure_config(&fbl->effect_fb, | ||||
| { | { | ||||
| GPU_ATTACHMENT_NONE, | GPU_ATTACHMENT_NONE, | ||||
| GPU_ATTACHMENT_TEXTURE(e_data.color_buffer_tx), | GPU_ATTACHMENT_TEXTURE(e_data.color_buffer_tx), | ||||
| ▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | void workbench_deferred_engine_free(void) | ||||
| workbench_fxaa_engine_free(); | workbench_fxaa_engine_free(); | ||||
| workbench_taa_engine_free(); | workbench_taa_engine_free(); | ||||
| workbench_dof_engine_free(); | workbench_dof_engine_free(); | ||||
| } | } | ||||
| static void workbench_composite_uniforms(WORKBENCH_PrivateData *wpd, DRWShadingGroup *grp) | static void workbench_composite_uniforms(WORKBENCH_PrivateData *wpd, DRWShadingGroup *grp) | ||||
| { | { | ||||
| DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo); | DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo); | ||||
| if (MATDATA_PASS_ENABLED(wpd)) { | if (workbench_is_matdata_pass_enabled(wpd)) { | ||||
| DRW_shgroup_uniform_texture_ref(grp, "materialBuffer", &e_data.color_buffer_tx); | DRW_shgroup_uniform_texture_ref(grp, "materialBuffer", &e_data.color_buffer_tx); | ||||
| } | } | ||||
| else { | else { | ||||
| DRW_shgroup_uniform_vec3(grp, "materialSingleColor", wpd->shading.single_color, 1); | DRW_shgroup_uniform_vec3(grp, "materialSingleColor", wpd->shading.single_color, 1); | ||||
| } | } | ||||
| if (OBJECT_OUTLINE_ENABLED(wpd)) { | if (OBJECT_OUTLINE_ENABLED(wpd)) { | ||||
| DRW_shgroup_uniform_texture_ref(grp, "objectId", &e_data.object_id_tx); | DRW_shgroup_uniform_texture_ref(grp, "objectId", &e_data.object_id_tx); | ||||
| } | } | ||||
| Show All 22 Lines | void workbench_deferred_cache_init(WORKBENCH_Data *vedata) | ||||
| WORKBENCH_PassList *psl = vedata->psl; | WORKBENCH_PassList *psl = vedata->psl; | ||||
| WORKBENCH_PrivateData *wpd = stl->g_data; | WORKBENCH_PrivateData *wpd = stl->g_data; | ||||
| DRWShadingGroup *grp; | DRWShadingGroup *grp; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| Scene *scene = draw_ctx->scene; | Scene *scene = draw_ctx->scene; | ||||
| workbench_volume_cache_init(vedata); | workbench_volume_cache_init(vedata); | ||||
| select_deferred_shaders(wpd, draw_ctx->sh_cfg); | select_deferred_shaders(wpd, draw_ctx->sh_cfg); | ||||
| /* Background Pass */ | /* Background Pass */ | ||||
| { | { | ||||
| psl->background_pass = DRW_pass_create("Background", | psl->background_pass = DRW_pass_create("Background", | ||||
| DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL); | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL); | ||||
| grp = DRW_shgroup_create(wpd->background_sh, psl->background_pass); | grp = DRW_shgroup_create(wpd->background_sh, psl->background_pass); | ||||
| DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo); | DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo); | ||||
| ▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | WORKBENCH_ObjectData *engine_object_data = (WORKBENCH_ObjectData *)DRW_drawdata_ensure( | ||||
| &draw_engine_workbench_solid, | &draw_engine_workbench_solid, | ||||
| sizeof(WORKBENCH_ObjectData), | sizeof(WORKBENCH_ObjectData), | ||||
| &workbench_init_object_data, | &workbench_init_object_data, | ||||
| NULL); | NULL); | ||||
| WORKBENCH_MaterialData material_template; | WORKBENCH_MaterialData material_template; | ||||
| const bool is_ghost = (ob->dtx & OB_DRAWXRAY); | const bool is_ghost = (ob->dtx & OB_DRAWXRAY); | ||||
| /* Solid */ | /* Solid */ | ||||
| workbench_material_update_data(wpd, ob, mat, &material_template); | workbench_material_update_data(wpd, ob, mat, &material_template, color_type); | ||||
| material_template.object_id = OBJECT_ID_PASS_ENABLED(wpd) ? engine_object_data->object_id : 1; | material_template.object_id = OBJECT_ID_PASS_ENABLED(wpd) ? engine_object_data->object_id : 1; | ||||
| material_template.color_type = color_type; | material_template.color_type = color_type; | ||||
| material_template.ima = ima; | material_template.ima = ima; | ||||
| material_template.iuser = iuser; | material_template.iuser = iuser; | ||||
| material_template.interp = interp; | material_template.interp = interp; | ||||
| uint hash = workbench_material_get_hash(&material_template, is_ghost); | uint hash = workbench_material_get_hash(&material_template, is_ghost); | ||||
| material = BLI_ghash_lookup(wpd->material_hash, POINTER_FROM_UINT(hash)); | material = BLI_ghash_lookup(wpd->material_hash, POINTER_FROM_UINT(hash)); | ||||
| if (material == NULL) { | if (material == NULL) { | ||||
| material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), __func__); | material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), __func__); | ||||
| /* select the correct prepass shader */ | |||||
| GPUShader *shader = (wpd->shading.color_type == color_type) ? wpd->prepass_sh : | |||||
| wpd->prepass_uniform_sh; | |||||
| if (color_type == V3D_SHADING_TEXTURE_COLOR) { | |||||
| shader = wpd->prepass_textured_sh; | |||||
| } | |||||
| material->shgrp = DRW_shgroup_create( | material->shgrp = DRW_shgroup_create( | ||||
| (wpd->shading.color_type == color_type) ? wpd->prepass_sh : wpd->prepass_uniform_sh, | shader, (ob->dtx & OB_DRAWXRAY) ? psl->ghost_prepass_pass : psl->prepass_pass); | ||||
| (ob->dtx & OB_DRAWXRAY) ? psl->ghost_prepass_pass : psl->prepass_pass); | |||||
| workbench_material_copy(material, &material_template); | workbench_material_copy(material, &material_template); | ||||
| DRW_shgroup_stencil_mask(material->shgrp, (ob->dtx & OB_DRAWXRAY) ? 0x00 : 0xFF); | DRW_shgroup_stencil_mask(material->shgrp, (ob->dtx & OB_DRAWXRAY) ? 0x00 : 0xFF); | ||||
| DRW_shgroup_uniform_int(material->shgrp, "object_id", &material->object_id, 1); | DRW_shgroup_uniform_int(material->shgrp, "object_id", &material->object_id, 1); | ||||
| workbench_material_shgroup_uniform(wpd, material->shgrp, material, ob, true, true, interp); | workbench_material_shgroup_uniform(wpd, material->shgrp, material, ob, true, true, interp); | ||||
| BLI_ghash_insert(wpd->material_hash, POINTER_FROM_UINT(hash), material); | BLI_ghash_insert(wpd->material_hash, POINTER_FROM_UINT(hash), material); | ||||
| } | } | ||||
| return material; | return material; | ||||
| } | } | ||||
| Show All 36 Lines | if (draw_as == PART_DRAW_PATH) { | ||||
| shader); | shader); | ||||
| DRW_shgroup_stencil_mask(shgrp, (ob->dtx & OB_DRAWXRAY) ? 0x00 : 0xFF); | DRW_shgroup_stencil_mask(shgrp, (ob->dtx & OB_DRAWXRAY) ? 0x00 : 0xFF); | ||||
| DRW_shgroup_uniform_int(shgrp, "object_id", &material->object_id, 1); | DRW_shgroup_uniform_int(shgrp, "object_id", &material->object_id, 1); | ||||
| workbench_material_shgroup_uniform(wpd, shgrp, material, ob, true, true, interp); | workbench_material_shgroup_uniform(wpd, shgrp, material, ob, true, true, interp); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static bool workbench_cache_populate_texture_paint_mode(WORKBENCH_Data *vedata, Object *ob) | |||||
fclem: I don't really like having this function and using it as test to continue drawing. I think it… | |||||
| { | |||||
| WORKBENCH_StorageList *stl = vedata->stl; | |||||
| WORKBENCH_PrivateData *wpd = stl->g_data; | |||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | |||||
| if (ob->type != OB_MESH) { | |||||
| return false; | |||||
| } | |||||
| bool drawn = false; | |||||
| Mesh *mesh = ob->data; | |||||
| Scene *scene = draw_ctx->scene; | |||||
| const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d); | |||||
| WORKBENCH_MaterialData *material; | |||||
| /* Force workbench to render active object textured when in texture paint mode */ | |||||
| const bool texture_paint_mode = workbench_is_object_in_texture_paint_mode(ob); | |||||
| if (mesh && mesh->mloopuv && texture_paint_mode) { | |||||
| const ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; | |||||
| /* Single Image mode */ | |||||
| if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) { | |||||
| Image *image = imapaint->canvas; | |||||
| int interp = (imapaint->interp == IMAGEPAINT_INTERP_LINEAR) ? SHD_INTERP_LINEAR : | |||||
| SHD_INTERP_CLOSEST; | |||||
| int color_type = workbench_material_determine_color_type(wpd, image, ob, use_sculpt_pbvh); | |||||
| struct GPUBatch *geom = DRW_cache_mesh_surface_texpaint_single_get(ob); | |||||
| material = get_or_create_material_data(vedata, ob, NULL, image, NULL, color_type, interp); | |||||
| DRW_shgroup_call(material->shgrp, geom, ob); | |||||
| } | |||||
| else { | |||||
| /* IMAGEPAINT_MODE_MATERIAL */ | |||||
| const int materials_len = MAX2(1, ob->totcol); | |||||
| struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob); | |||||
| for (int i = 0; i < materials_len; i++) { | |||||
| if (geom_array != NULL && geom_array[i] != NULL) { | |||||
| Material *mat; | |||||
| Image *image; | |||||
| ImageUser *iuser; | |||||
| int interp; | |||||
| workbench_material_get_image_and_mat(ob, i + 1, &image, &iuser, &interp, &mat); | |||||
| int color_type = workbench_material_determine_color_type( | |||||
| wpd, image, ob, use_sculpt_pbvh); | |||||
| material = get_or_create_material_data( | |||||
| vedata, ob, mat, image, iuser, color_type, interp); | |||||
| DRW_shgroup_call(material->shgrp, geom_array[i], ob); | |||||
| } | |||||
| } | |||||
| } | |||||
| drawn = true; | |||||
fclemUnsubmitted Not Done Inline ActionsRemove draw variable and use return true here. fclem: Remove `draw` variable and use `return true` here. | |||||
| } | |||||
| return drawn; | |||||
| } | |||||
| void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) | void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) | ||||
| { | { | ||||
| WORKBENCH_StorageList *stl = vedata->stl; | WORKBENCH_StorageList *stl = vedata->stl; | ||||
| WORKBENCH_PassList *psl = vedata->psl; | WORKBENCH_PassList *psl = vedata->psl; | ||||
| WORKBENCH_PrivateData *wpd = stl->g_data; | WORKBENCH_PrivateData *wpd = stl->g_data; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| Scene *scene = draw_ctx->scene; | Scene *scene = draw_ctx->scene; | ||||
| Show All 25 Lines | void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) | ||||
| 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)) { | ||||
| const bool is_active = (ob == draw_ctx->obact); | const bool is_active = (ob == draw_ctx->obact); | ||||
| const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d); | const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d); | ||||
| const bool use_hide = is_active && DRW_object_use_hide_faces(ob); | const bool use_hide = is_active && DRW_object_use_hide_faces(ob); | ||||
| const int materials_len = MAX2(1, ob->totcol); | const int materials_len = MAX2(1, ob->totcol); | ||||
| const Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL; | const Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL; | ||||
| bool has_transp_mat = false; | bool has_transp_mat = false; | ||||
| if (!workbench_cache_populate_texture_paint_mode(vedata, ob)) { | |||||
| if (!use_sculpt_pbvh && TEXTURE_DRAWING_ENABLED(wpd) && me && me->mloopuv) { | if (!use_sculpt_pbvh && TEXTURE_DRAWING_ENABLED(wpd) && me && me->mloopuv) { | ||||
| /* Draw textured */ | /* Draw textured */ | ||||
| struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob); | struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob); | ||||
| for (int i = 0; i < materials_len; i++) { | for (int i = 0; i < materials_len; i++) { | ||||
| if (geom_array != NULL && geom_array[i] != NULL) { | if (geom_array != NULL && geom_array[i] != NULL) { | ||||
| Material *mat; | Material *mat; | ||||
| Image *image; | Image *image; | ||||
| ImageUser *iuser; | ImageUser *iuser; | ||||
| int interp; | int interp; | ||||
| workbench_material_get_image_and_mat(ob, i + 1, &image, &iuser, &interp, &mat); | workbench_material_get_image_and_mat(ob, i + 1, &image, &iuser, &interp, &mat); | ||||
| int color_type = workbench_material_determine_color_type( | int color_type = workbench_material_determine_color_type( | ||||
| wpd, image, ob, use_sculpt_pbvh); | wpd, image, ob, use_sculpt_pbvh); | ||||
| if (color_type == V3D_SHADING_MATERIAL_COLOR && mat && mat->a < 1.0) { | if (color_type == V3D_SHADING_MATERIAL_COLOR && mat && mat->a < 1.0) { | ||||
| material = workbench_forward_get_or_create_material_data( | material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, mat, image, iuser, color_type, 0, use_sculpt_pbvh); | vedata, ob, mat, image, iuser, color_type, 0); | ||||
| has_transp_mat = true; | has_transp_mat = true; | ||||
| } | } | ||||
| else { | else { | ||||
| material = get_or_create_material_data( | material = get_or_create_material_data( | ||||
| vedata, ob, mat, image, iuser, color_type, interp); | vedata, ob, mat, image, iuser, color_type, interp); | ||||
| } | } | ||||
| DRW_shgroup_call(material->shgrp, geom_array[i], ob); | DRW_shgroup_call(material->shgrp, geom_array[i], ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (ELEM(wpd->shading.color_type, | else if (ELEM(wpd->shading.color_type, | ||||
| V3D_SHADING_SINGLE_COLOR, | V3D_SHADING_SINGLE_COLOR, | ||||
| V3D_SHADING_OBJECT_COLOR, | V3D_SHADING_OBJECT_COLOR, | ||||
| V3D_SHADING_RANDOM_COLOR, | V3D_SHADING_RANDOM_COLOR, | ||||
| V3D_SHADING_VERTEX_COLOR)) { | V3D_SHADING_VERTEX_COLOR)) { | ||||
| int color_type = workbench_material_determine_color_type(wpd, NULL, ob, use_sculpt_pbvh); | int color_type = workbench_material_determine_color_type(wpd, NULL, ob, use_sculpt_pbvh); | ||||
| if ((ob->color[3] < 1.0f) && (color_type == V3D_SHADING_OBJECT_COLOR)) { | if ((ob->color[3] < 1.0f) && (color_type == V3D_SHADING_OBJECT_COLOR)) { | ||||
| material = workbench_forward_get_or_create_material_data( | material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, NULL, NULL, NULL, color_type, 0, use_sculpt_pbvh); | vedata, ob, NULL, NULL, NULL, color_type, 0); | ||||
| has_transp_mat = true; | has_transp_mat = true; | ||||
| } | } | ||||
| else { | else { | ||||
| /* Draw solid color */ | /* Draw solid color */ | ||||
| material = get_or_create_material_data(vedata, ob, NULL, NULL, NULL, color_type, 0); | material = get_or_create_material_data(vedata, ob, NULL, NULL, NULL, color_type, 0); | ||||
| } | } | ||||
| if (use_sculpt_pbvh) { | if (use_sculpt_pbvh) { | ||||
| bool use_vcol = (color_type == V3D_SHADING_VERTEX_COLOR); | bool use_vcol = (color_type == V3D_SHADING_VERTEX_COLOR); | ||||
| DRW_shgroup_call_sculpt(material->shgrp, ob, false, false, use_vcol); | DRW_shgroup_call_sculpt(material->shgrp, ob, false, false, use_vcol); | ||||
| } | } | ||||
| else { | else { | ||||
| struct GPUBatch *geom; | struct GPUBatch *geom; | ||||
| if (color_type == V3D_SHADING_VERTEX_COLOR) { | if (color_type == V3D_SHADING_VERTEX_COLOR) { | ||||
| geom = DRW_cache_mesh_surface_vertpaint_get(ob); | geom = DRW_cache_mesh_surface_vertpaint_get(ob); | ||||
| } | } | ||||
| else { | else { | ||||
| geom = DRW_cache_object_surface_get(ob); | geom = DRW_cache_object_surface_get(ob); | ||||
| } | } | ||||
| if (geom) { | if (geom) { | ||||
| DRW_shgroup_call(material->shgrp, geom, ob); | DRW_shgroup_call(material->shgrp, geom, ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Draw material color */ | /* Draw material color */ | ||||
| if (use_sculpt_pbvh) { | if (use_sculpt_pbvh) { | ||||
| struct DRWShadingGroup **shgrps = BLI_array_alloca(shgrps, materials_len); | struct DRWShadingGroup **shgrps = BLI_array_alloca(shgrps, materials_len); | ||||
| for (int i = 0; i < materials_len; ++i) { | for (int i = 0; i < materials_len; ++i) { | ||||
| struct Material *mat = give_current_material(ob, i + 1); | struct Material *mat = give_current_material(ob, i + 1); | ||||
| if (mat != NULL && mat->a < 1.0f) { | if (mat != NULL && mat->a < 1.0f) { | ||||
| material = workbench_forward_get_or_create_material_data( | material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, use_sculpt_pbvh); | vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0); | ||||
| has_transp_mat = true; | has_transp_mat = true; | ||||
| } | } | ||||
| else { | else { | ||||
| material = get_or_create_material_data( | material = get_or_create_material_data( | ||||
| vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0); | vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0); | ||||
| } | } | ||||
| shgrps[i] = material->shgrp; | shgrps[i] = material->shgrp; | ||||
| } | } | ||||
| DRW_shgroup_call_sculpt_with_materials(shgrps, ob, false); | DRW_shgroup_call_sculpt_with_materials(shgrps, ob, false); | ||||
| } | } | ||||
| else { | else { | ||||
| struct GPUBatch **geoms; | struct GPUBatch **geoms; | ||||
| struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len); | struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len); | ||||
| memset(gpumat_array, 0, sizeof(*gpumat_array) * materials_len); | memset(gpumat_array, 0, sizeof(*gpumat_array) * materials_len); | ||||
| geoms = DRW_cache_object_surface_material_get( | geoms = DRW_cache_object_surface_material_get( | ||||
| ob, gpumat_array, materials_len, NULL, NULL, NULL); | ob, gpumat_array, materials_len, NULL, NULL, NULL); | ||||
| for (int i = 0; i < materials_len; ++i) { | for (int i = 0; i < materials_len; ++i) { | ||||
| if (geoms != NULL && geoms[i] != NULL) { | if (geoms != NULL && geoms[i] != NULL) { | ||||
| Material *mat = give_current_material(ob, i + 1); | Material *mat = give_current_material(ob, i + 1); | ||||
| if (mat != NULL && mat->a < 1.0f) { | if (mat != NULL && mat->a < 1.0f) { | ||||
| material = workbench_forward_get_or_create_material_data( | material = workbench_forward_get_or_create_material_data( | ||||
| vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, use_sculpt_pbvh); | vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0); | ||||
| has_transp_mat = true; | has_transp_mat = true; | ||||
| } | } | ||||
| else { | else { | ||||
| material = get_or_create_material_data( | material = get_or_create_material_data( | ||||
| vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0); | vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0); | ||||
| } | } | ||||
| DRW_shgroup_call(material->shgrp, geoms[i], ob); | DRW_shgroup_call(material->shgrp, geoms[i], ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| if (SHADOW_ENABLED(wpd) && !(ob->dtx & OB_DRAW_NO_SHADOW_CAST)) { | if (SHADOW_ENABLED(wpd) && !(ob->dtx & OB_DRAW_NO_SHADOW_CAST)) { | ||||
| bool is_manifold; | bool is_manifold; | ||||
| struct GPUBatch *geom_shadow = DRW_cache_object_edge_detection_get(ob, &is_manifold); | struct GPUBatch *geom_shadow = DRW_cache_object_edge_detection_get(ob, &is_manifold); | ||||
| if (geom_shadow) { | if (geom_shadow) { | ||||
| if (use_sculpt_pbvh || use_hide) { | if (use_sculpt_pbvh || use_hide) { | ||||
| /* Currently unsupported in sculpt mode. We could revert to the slow | /* Currently unsupported in sculpt mode. We could revert to the slow | ||||
| * method in this case but I'm not sure if it's a good idea given that | * method in this case but I'm not sure if it's a good idea given that | ||||
| ▲ Show 20 Lines • Show All 225 Lines • Show Last 20 Lines | |||||
I don't really like having this function and using it as test to continue drawing. I think it should be a case inside workbench_deferred_solid_cache_populate to avoid some code duplication and increase readability.