Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_volume.c
| Show All 17 Lines | |||||
| /** \file | /** \file | ||||
| * \ingroup draw_engine | * \ingroup draw_engine | ||||
| */ | */ | ||||
| #include "workbench_private.h" | #include "workbench_private.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_smoke.h" | #include "BKE_manta.h" | ||||
| #include "BLI_rand.h" | #include "BLI_rand.h" | ||||
| #include "BLI_dynstr.h" | #include "BLI_dynstr.h" | ||||
| #include "DNA_modifier_types.h" | #include "DNA_modifier_types.h" | ||||
| #include "DNA_object_force_types.h" | #include "DNA_object_force_types.h" | ||||
| #include "DNA_smoke_types.h" | #include "DNA_manta_types.h" | ||||
| #include "GPU_draw.h" | #include "GPU_draw.h" | ||||
| enum { | enum { | ||||
| VOLUME_SH_SLICE = 0, | VOLUME_SH_SLICE = 0, | ||||
| VOLUME_SH_COBA, | VOLUME_SH_COBA, | ||||
| VOLUME_SH_CUBIC, | VOLUME_SH_CUBIC, | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | vedata->psl->volume_pass = DRW_pass_create( | ||||
| "Volumes", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA_PREMUL | DRW_STATE_CULL_FRONT); | "Volumes", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA_PREMUL | DRW_STATE_CULL_FRONT); | ||||
| } | } | ||||
| void workbench_volume_cache_populate(WORKBENCH_Data *vedata, | void workbench_volume_cache_populate(WORKBENCH_Data *vedata, | ||||
| Scene *scene, | Scene *scene, | ||||
| Object *ob, | Object *ob, | ||||
| ModifierData *md) | ModifierData *md) | ||||
| { | { | ||||
| SmokeModifierData *smd = (SmokeModifierData *)md; | MantaModifierData *mmd = (MantaModifierData *)md; | ||||
| SmokeDomainSettings *sds = smd->domain; | MantaDomainSettings *mds = mmd->domain; | ||||
| WORKBENCH_PrivateData *wpd = vedata->stl->g_data; | WORKBENCH_PrivateData *wpd = vedata->stl->g_data; | ||||
| WORKBENCH_EffectInfo *effect_info = vedata->stl->effects; | WORKBENCH_EffectInfo *effect_info = vedata->stl->effects; | ||||
| DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | ||||
| DRWShadingGroup *grp = NULL; | DRWShadingGroup *grp = NULL; | ||||
| /* Don't show smoke before simulation starts, this could be made an option in the future. */ | /* Don't try to show liquid domains here */ | ||||
| if (!sds->fluid || CFRA < sds->point_cache[0]->startframe) { | if (!mds->fluid || !(mds->type == FLUID_DOMAIN_TYPE_GAS)) { | ||||
| return; | return; | ||||
| } | } | ||||
| wpd->volumes_do = true; | wpd->volumes_do = true; | ||||
| const bool show_highres = BKE_smoke_show_highres(scene, sds); | if (mds->use_coba) { | ||||
| if (sds->use_coba) { | GPU_create_smoke_coba_field(mmd); | ||||
| GPU_create_smoke_coba_field(smd); | |||||
| } | } | ||||
| else if (!sds->wt || !show_highres) { | else if (!(mds->flags & FLUID_DOMAIN_USE_NOISE)) { | ||||
| GPU_create_smoke(smd, 0); | GPU_create_smoke(mmd, 0); | ||||
| } | } | ||||
| else if (sds->wt && show_highres) { | else if (mds->flags & FLUID_DOMAIN_USE_NOISE) { | ||||
| GPU_create_smoke(smd, 1); | GPU_create_smoke(mmd, 1); | ||||
| } | } | ||||
| if ((!sds->use_coba && sds->tex == NULL) || (sds->use_coba && sds->tex_field == NULL)) { | if ((!mds->use_coba && mds->tex == NULL) || (mds->use_coba && mds->tex_field == NULL)) { | ||||
| return; | return; | ||||
| } | } | ||||
| const bool use_slice = (sds->slice_method == MOD_SMOKE_SLICE_AXIS_ALIGNED && | const bool use_slice = (mds->slice_method == FLUID_DOMAIN_SLICE_AXIS_ALIGNED && | ||||
| sds->axis_slice_method == AXIS_SLICE_SINGLE); | mds->axis_slice_method == AXIS_SLICE_SINGLE); | ||||
| const bool cubic_interp = (sds->interp_method == VOLUME_INTERP_CUBIC); | const bool cubic_interp = (mds->interp_method == VOLUME_INTERP_CUBIC); | ||||
| GPUShader *sh = volume_shader_get(use_slice, sds->use_coba, cubic_interp); | GPUShader *sh = volume_shader_get(use_slice, mds->use_coba, cubic_interp); | ||||
| if (use_slice) { | if (use_slice) { | ||||
| float invviewmat[4][4]; | float invviewmat[4][4]; | ||||
| DRW_view_viewmat_get(NULL, invviewmat, true); | DRW_view_viewmat_get(NULL, invviewmat, true); | ||||
| const int axis = (sds->slice_axis == SLICE_AXIS_AUTO) ? | const int axis = (mds->slice_axis == SLICE_AXIS_AUTO) ? | ||||
| axis_dominant_v3_single(invviewmat[2]) : | axis_dominant_v3_single(invviewmat[2]) : | ||||
| sds->slice_axis - 1; | mds->slice_axis - 1; | ||||
| float dim[3]; | float dim[3]; | ||||
| BKE_object_dimensions_get(ob, dim); | BKE_object_dimensions_get(ob, dim); | ||||
| /* 0.05f to achieve somewhat the same opacity as the full view. */ | /* 0.05f to achieve somewhat the same opacity as the full view. */ | ||||
| float step_length = max_ff(1e-16f, dim[axis] * 0.05f); | float step_length = max_ff(1e-16f, dim[axis] * 0.05f); | ||||
| grp = DRW_shgroup_create(sh, vedata->psl->volume_pass); | grp = DRW_shgroup_create(sh, vedata->psl->volume_pass); | ||||
| DRW_shgroup_uniform_float_copy(grp, "slicePosition", sds->slice_depth); | DRW_shgroup_uniform_float_copy(grp, "slicePosition", mds->slice_depth); | ||||
| DRW_shgroup_uniform_int_copy(grp, "sliceAxis", axis); | DRW_shgroup_uniform_int_copy(grp, "sliceAxis", axis); | ||||
| DRW_shgroup_uniform_float_copy(grp, "stepLength", step_length); | DRW_shgroup_uniform_float_copy(grp, "stepLength", step_length); | ||||
| DRW_shgroup_state_disable(grp, DRW_STATE_CULL_FRONT); | DRW_shgroup_state_disable(grp, DRW_STATE_CULL_FRONT); | ||||
| } | } | ||||
| else { | else { | ||||
| double noise_ofs; | double noise_ofs; | ||||
| BLI_halton_1d(3, 0.0, effect_info->jitter_index, &noise_ofs); | BLI_halton_1d(3, 0.0, effect_info->jitter_index, &noise_ofs); | ||||
| float dim[3], step_length, max_slice; | float dim[3], step_length, max_slice; | ||||
| float slice_ct[3] = {sds->res[0], sds->res[1], sds->res[2]}; | float slice_ct[3] = {mds->res[0], mds->res[1], mds->res[2]}; | ||||
| mul_v3_fl(slice_ct, max_ff(0.001f, sds->slice_per_voxel)); | mul_v3_fl(slice_ct, max_ff(0.001f, mds->slice_per_voxel)); | ||||
| max_slice = max_fff(slice_ct[0], slice_ct[1], slice_ct[2]); | max_slice = max_fff(slice_ct[0], slice_ct[1], slice_ct[2]); | ||||
| BKE_object_dimensions_get(ob, dim); | BKE_object_dimensions_get(ob, dim); | ||||
| invert_v3(slice_ct); | invert_v3(slice_ct); | ||||
| mul_v3_v3(dim, slice_ct); | mul_v3_v3(dim, slice_ct); | ||||
| step_length = len_v3(dim); | step_length = len_v3(dim); | ||||
| grp = DRW_shgroup_create(sh, vedata->psl->volume_pass); | grp = DRW_shgroup_create(sh, vedata->psl->volume_pass); | ||||
| DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)wpd->viewvecs, 3); | DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)wpd->viewvecs, 3); | ||||
| DRW_shgroup_uniform_int_copy(grp, "samplesLen", max_slice); | DRW_shgroup_uniform_int_copy(grp, "samplesLen", max_slice); | ||||
| DRW_shgroup_uniform_float_copy(grp, "stepLength", step_length); | DRW_shgroup_uniform_float_copy(grp, "stepLength", step_length); | ||||
| DRW_shgroup_uniform_float_copy(grp, "noiseOfs", noise_ofs); | DRW_shgroup_uniform_float_copy(grp, "noiseOfs", noise_ofs); | ||||
| DRW_shgroup_state_enable(grp, DRW_STATE_CULL_FRONT); | DRW_shgroup_state_enable(grp, DRW_STATE_CULL_FRONT); | ||||
| } | } | ||||
| if (sds->use_coba) { | if (mds->use_coba) { | ||||
| DRW_shgroup_uniform_texture(grp, "densityTexture", sds->tex_field); | DRW_shgroup_uniform_texture(grp, "densityTexture", mds->tex_field); | ||||
| DRW_shgroup_uniform_texture(grp, "transferTexture", sds->tex_coba); | DRW_shgroup_uniform_texture(grp, "transferTexture", mds->tex_coba); | ||||
| } | } | ||||
| else { | else { | ||||
| static float white[3] = {1.0f, 1.0f, 1.0f}; | static float white[3] = {1.0f, 1.0f, 1.0f}; | ||||
| bool use_constant_color = ((sds->active_fields & SM_ACTIVE_COLORS) == 0 && | bool use_constant_color = ((mds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS) == 0 && | ||||
| (sds->active_fields & SM_ACTIVE_COLOR_SET) != 0); | (mds->active_fields & FLUID_DOMAIN_ACTIVE_COLOR_SET) != 0); | ||||
| DRW_shgroup_uniform_texture(grp, "densityTexture", sds->tex); | DRW_shgroup_uniform_texture(grp, "densityTexture", mds->tex); | ||||
| DRW_shgroup_uniform_texture(grp, "shadowTexture", sds->tex_shadow); | DRW_shgroup_uniform_texture(grp, "shadowTexture", mds->tex_shadow); | ||||
| DRW_shgroup_uniform_texture( | DRW_shgroup_uniform_texture( | ||||
| grp, "flameTexture", (sds->tex_flame) ? sds->tex_flame : e_data.dummy_tex); | grp, "flameTexture", (mds->tex_flame) ? mds->tex_flame : e_data.dummy_tex); | ||||
| DRW_shgroup_uniform_texture( | DRW_shgroup_uniform_texture( | ||||
| grp, "flameColorTexture", (sds->tex_flame) ? sds->tex_flame_coba : e_data.dummy_coba_tex); | grp, "flameColorTexture", (mds->tex_flame) ? mds->tex_flame_coba : e_data.dummy_coba_tex); | ||||
| DRW_shgroup_uniform_vec3( | DRW_shgroup_uniform_vec3( | ||||
| grp, "activeColor", (use_constant_color) ? sds->active_color : white, 1); | grp, "activeColor", (use_constant_color) ? mds->active_color : white, 1); | ||||
| } | } | ||||
| DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | ||||
| DRW_shgroup_uniform_float_copy(grp, "densityScale", 10.0f * sds->display_thickness); | DRW_shgroup_uniform_float_copy(grp, "densityScale", 10.0f * mds->display_thickness); | ||||
| if (use_slice) { | if (use_slice) { | ||||
| DRW_shgroup_call(grp, DRW_cache_quad_get(), ob); | DRW_shgroup_call(grp, DRW_cache_quad_get(), ob); | ||||
| } | } | ||||
| else { | else { | ||||
| DRW_shgroup_call(grp, DRW_cache_cube_get(), ob); | DRW_shgroup_call(grp, DRW_cache_cube_get(), ob); | ||||
| } | } | ||||
| BLI_addtail(&wpd->smoke_domains, BLI_genericNodeN(smd)); | BLI_addtail(&wpd->smoke_domains, BLI_genericNodeN(mmd)); | ||||
| } | } | ||||
| void workbench_volume_smoke_textures_free(WORKBENCH_PrivateData *wpd) | void workbench_volume_smoke_textures_free(WORKBENCH_PrivateData *wpd) | ||||
| { | { | ||||
| /* Free Smoke Textures after rendering */ | /* Free Smoke Textures after rendering */ | ||||
| /* XXX This is a waste of processing and GPU bandwidth if nothing | /* XXX This is a waste of processing and GPU bandwidth if nothing | ||||
| * is updated. But the problem is since Textures are stored in the | * is updated. But the problem is since Textures are stored in the | ||||
| * modifier we don't want them to take precious VRAM if the | * modifier we don't want them to take precious VRAM if the | ||||
| * modifier is not used for display. We should share them for | * modifier is not used for display. We should share them for | ||||
| * all viewport in a redraw at least. */ | * all viewport in a redraw at least. */ | ||||
| for (LinkData *link = wpd->smoke_domains.first; link; link = link->next) { | for (LinkData *link = wpd->smoke_domains.first; link; link = link->next) { | ||||
| SmokeModifierData *smd = (SmokeModifierData *)link->data; | MantaModifierData *mmd = (MantaModifierData *)link->data; | ||||
| GPU_free_smoke(smd); | GPU_free_smoke(mmd); | ||||
| } | } | ||||
| BLI_freelistN(&wpd->smoke_domains); | BLI_freelistN(&wpd->smoke_domains); | ||||
| } | } | ||||