Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_deferred.c
| Show First 20 Lines • Show All 208 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, | WORKBENCH_ObjectColorOverride color_override, | ||||
| 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( | int index = workbench_material_get_prepass_shader_index( | ||||
| wpd, is_uniform_color, is_hair, is_texture_painting); | wpd, is_uniform_color, is_hair, color_override); | ||||
| 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( | char *defines = workbench_material_build_defines( | ||||
| wpd, is_uniform_color, is_hair, is_texture_painting); | wpd, is_uniform_color, is_hair, color_override); | ||||
| 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, false); | char *defines = workbench_material_build_defines( | ||||
| wpd, false, false, WORKBENCH_COLOR_OVERRIDE_OFF); | |||||
| 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, false, sh_cfg); | wpd->prepass_sh = ensure_deferred_prepass_shader( | ||||
| wpd->prepass_hair_sh = ensure_deferred_prepass_shader(wpd, false, true, false, sh_cfg); | wpd, false, false, WORKBENCH_COLOR_OVERRIDE_OFF, sh_cfg); | ||||
| wpd->prepass_uniform_sh = ensure_deferred_prepass_shader(wpd, true, false, false, sh_cfg); | wpd->prepass_hair_sh = ensure_deferred_prepass_shader( | ||||
| wpd->prepass_uniform_hair_sh = ensure_deferred_prepass_shader(wpd, true, true, false, sh_cfg); | wpd, false, true, WORKBENCH_COLOR_OVERRIDE_OFF, sh_cfg); | ||||
| wpd->prepass_textured_sh = ensure_deferred_prepass_shader(wpd, false, false, true, sh_cfg); | wpd->prepass_uniform_sh = ensure_deferred_prepass_shader( | ||||
| wpd, true, false, WORKBENCH_COLOR_OVERRIDE_OFF, sh_cfg); | |||||
| wpd->prepass_uniform_hair_sh = ensure_deferred_prepass_shader( | |||||
| wpd, true, true, WORKBENCH_COLOR_OVERRIDE_OFF, sh_cfg); | |||||
| wpd->prepass_textured_sh = ensure_deferred_prepass_shader( | |||||
| wpd, false, false, WORKBENCH_COLOR_OVERRIDE_TEXTURE, sh_cfg); | |||||
| wpd->prepass_vertex_sh = ensure_deferred_prepass_shader( | |||||
| wpd, false, false, WORKBENCH_COLOR_OVERRIDE_VERTEX, 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 578 Lines • ▼ Show 20 Lines | static WORKBENCH_MaterialData *get_or_create_material_data(WORKBENCH_Data *vedata, | ||||
| 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 */ | /* select the correct prepass shader */ | ||||
| GPUShader *shader = (wpd->shading.color_type == color_type) ? wpd->prepass_sh : | GPUShader *shader = (wpd->shading.color_type == color_type) ? wpd->prepass_sh : | ||||
| wpd->prepass_uniform_sh; | wpd->prepass_uniform_sh; | ||||
| if (color_type == V3D_SHADING_TEXTURE_COLOR) { | if (color_type == V3D_SHADING_TEXTURE_COLOR) { | ||||
| shader = wpd->prepass_textured_sh; | shader = wpd->prepass_textured_sh; | ||||
| } | } | ||||
| if (color_type == V3D_SHADING_VERTEX_COLOR) { | |||||
| shader = wpd->prepass_vertex_sh; | |||||
| } | |||||
| material->shgrp = DRW_shgroup_create( | material->shgrp = DRW_shgroup_create( | ||||
| shader, (ob->dtx & OB_DRAWXRAY) ? psl->ghost_prepass_pass : psl->prepass_pass); | shader, (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); | ||||
| workbench_material_shgroup_uniform(wpd, material->shgrp, material, ob, true, interp); | workbench_material_shgroup_uniform(wpd, material->shgrp, material, ob, 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 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | for (int i = 0; i < materials_len; i++) { | ||||
| int color_type = workbench_material_determine_color_type(wpd, image, ob, use_sculpt_pbvh); | 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); | material = get_or_create_material_data(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); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void workbench_cache_populate_vertex_paint_mode(WORKBENCH_Data *vedata, Object *ob) | |||||
| { | |||||
| WORKBENCH_StorageList *stl = vedata->stl; | |||||
| WORKBENCH_PrivateData *wpd = stl->g_data; | |||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | |||||
| const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) && | |||||
| !DRW_state_is_image_render(); | |||||
| WORKBENCH_MaterialData *material; | |||||
| int color_type = workbench_material_determine_color_type(wpd, NULL, ob, use_sculpt_pbvh); | |||||
| struct GPUBatch *geom = DRW_cache_mesh_surface_vertpaint_get(ob); | |||||
| material = get_or_create_material_data(vedata, ob, NULL, NULL, NULL, color_type, false); | |||||
| DRW_shgroup_call(material->shgrp, geom, ob); | |||||
| } | |||||
| 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) | ||||
| WORKBENCH_MaterialData *material; | 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)) { | ||||
| 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; | ||||
| const WORKBENCH_ObjectColorOverride color_override = workbench_object_color_override_get(ob); | |||||
| const bool use_texture_paint_drawing = !(DRW_state_is_image_render() && | const bool use_texture_paint_drawing = !(DRW_state_is_image_render() && | ||||
| draw_ctx->v3d == NULL) && | draw_ctx->v3d == NULL) && | ||||
| workbench_is_object_in_texture_paint_mode(ob) && me && | (color_override == WORKBENCH_COLOR_OVERRIDE_TEXTURE) && | ||||
| me->mloopuv; | me && me->mloopuv; | ||||
| const bool use_vertex_paint_drawing = !(DRW_state_is_image_render() && | |||||
| draw_ctx->v3d == NULL) && | |||||
| (color_override == WORKBENCH_COLOR_OVERRIDE_VERTEX) && | |||||
| me && me->mloopcol; | |||||
| if (use_texture_paint_drawing) { | if (use_texture_paint_drawing) { | ||||
| workbench_cache_populate_texture_paint_mode(vedata, ob); | workbench_cache_populate_texture_paint_mode(vedata, ob); | ||||
| } | } | ||||
| else if (use_vertex_paint_drawing) { | |||||
| workbench_cache_populate_vertex_paint_mode(vedata, ob); | |||||
| } | |||||
| else if (!use_sculpt_pbvh && TEXTURE_DRAWING_ENABLED(wpd) && me && me->mloopuv) { | else 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; | ||||
| ▲ Show 20 Lines • Show All 360 Lines • Show Last 20 Lines | |||||