Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-11-07 15:22:22 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-11-07 15:25:28 +0300
commit84ad9b102e708da54188752bde34daba8b6611b2 (patch)
tree63a79d141fe9b934ae33d86d25a148e817b04272 /source/blender/draw/engines/workbench/workbench_volume.c
parentfaecd16d3168981b5af95be613e5a91de5c28133 (diff)
Workbench: Add cubic filtering for smoke simulation
The option is per domain and only affects the solid / xray / wireframe view. Eevee is not yet supported.
Diffstat (limited to 'source/blender/draw/engines/workbench/workbench_volume.c')
-rw-r--r--source/blender/draw/engines/workbench/workbench_volume.c71
1 files changed, 48 insertions, 23 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c
index 0f6b3e5954a..e720bb6aa64 100644
--- a/source/blender/draw/engines/workbench/workbench_volume.c
+++ b/source/blender/draw/engines/workbench/workbench_volume.c
@@ -28,6 +28,7 @@
#include "BKE_modifier.h"
#include "BLI_rand.h"
+#include "BLI_dynstr.h"
#include "DNA_modifier_types.h"
#include "DNA_object_force_types.h"
@@ -35,8 +36,16 @@
#include "GPU_draw.h"
+enum {
+ VOLUME_SH_SLICE = 0,
+ VOLUME_SH_COBA,
+ VOLUME_SH_CUBIC,
+};
+
+#define VOLUME_SH_MAX (1 << (VOLUME_SH_CUBIC + 1))
+
static struct {
- struct GPUShader *volume_sh;
+ struct GPUShader *volume_sh[VOLUME_SH_MAX];
struct GPUShader *volume_coba_sh;
struct GPUShader *volume_slice_sh;
struct GPUShader *volume_slice_coba_sh;
@@ -47,26 +56,43 @@ static struct {
extern char datatoc_workbench_volume_vert_glsl[];
extern char datatoc_workbench_volume_frag_glsl[];
-void workbench_volume_engine_init(void)
+static GPUShader *volume_shader_get(bool slice, bool coba, bool cubic)
{
- if (!e_data.volume_sh) {
- e_data.volume_sh = DRW_shader_create(
- datatoc_workbench_volume_vert_glsl, NULL,
- datatoc_workbench_volume_frag_glsl, NULL);
- e_data.volume_coba_sh = DRW_shader_create(
- datatoc_workbench_volume_vert_glsl, NULL,
- datatoc_workbench_volume_frag_glsl,
- "#define USE_COBA\n");
- e_data.volume_slice_sh = DRW_shader_create(
- datatoc_workbench_volume_vert_glsl, NULL,
- datatoc_workbench_volume_frag_glsl,
- "#define VOLUME_SLICE\n");
- e_data.volume_slice_coba_sh = DRW_shader_create(
+ int id = 0;
+ id += (slice) ? (1 << VOLUME_SH_SLICE) : 0;
+ id += (coba) ? (1 << VOLUME_SH_COBA) : 0;
+ id += (cubic) ? (1 << VOLUME_SH_CUBIC) : 0;
+
+ if (!e_data.volume_sh[id]) {
+ DynStr *ds = BLI_dynstr_new();
+
+ if (slice) {
+ BLI_dynstr_append(ds, "#define VOLUME_SLICE\n");
+ }
+ if (coba) {
+ BLI_dynstr_append(ds, "#define USE_COBA\n");
+ }
+ if (cubic) {
+ BLI_dynstr_append(ds, "#define USE_TRICUBIC\n");
+ }
+
+ char *defines = BLI_dynstr_get_cstring(ds);
+ BLI_dynstr_free(ds);
+
+ e_data.volume_sh[id] = DRW_shader_create(
datatoc_workbench_volume_vert_glsl, NULL,
datatoc_workbench_volume_frag_glsl,
- "#define VOLUME_SLICE\n"
- "#define USE_COBA\n");
+ defines);
+ MEM_freeN(defines);
+ }
+
+ return e_data.volume_sh[id];
+}
+
+void workbench_volume_engine_init(void)
+{
+ if (!e_data.dummy_tex) {
float pixel[4] = {0.0f, 0.0f, 0.0f, 0.0f};
e_data.dummy_tex = GPU_texture_create_3D(1, 1, 1, GPU_RGBA8, pixel, NULL);
e_data.dummy_coba_tex = GPU_texture_create_1D(1, GPU_RGBA8, pixel, NULL);
@@ -75,10 +101,9 @@ void workbench_volume_engine_init(void)
void workbench_volume_engine_free(void)
{
- DRW_SHADER_FREE_SAFE(e_data.volume_sh);
- DRW_SHADER_FREE_SAFE(e_data.volume_coba_sh);
- DRW_SHADER_FREE_SAFE(e_data.volume_slice_sh);
- DRW_SHADER_FREE_SAFE(e_data.volume_slice_coba_sh);
+ for (int i = 0; i < VOLUME_SH_MAX; ++i) {
+ DRW_SHADER_FREE_SAFE(e_data.volume_sh[i]);
+ }
DRW_TEXTURE_FREE_SAFE(e_data.dummy_tex);
DRW_TEXTURE_FREE_SAFE(e_data.dummy_coba_tex);
}
@@ -121,6 +146,8 @@ void workbench_volume_cache_populate(WORKBENCH_Data *vedata, Scene *scene, Objec
const bool use_slice = (sds->slice_method == MOD_SMOKE_SLICE_AXIS_ALIGNED &&
sds->axis_slice_method == AXIS_SLICE_SINGLE);
+ const bool cubic_interp = (sds->interp_method == VOLUME_INTERP_CUBIC);
+ GPUShader *sh = volume_shader_get(use_slice, sds->use_coba, cubic_interp);
if (use_slice) {
float invviewmat[4][4];
@@ -130,7 +157,6 @@ void workbench_volume_cache_populate(WORKBENCH_Data *vedata, Scene *scene, Objec
? axis_dominant_v3_single(invviewmat[2])
: sds->slice_axis - 1;
- GPUShader *sh = (sds->use_coba) ? e_data.volume_slice_coba_sh : e_data.volume_slice_sh;
grp = DRW_shgroup_create(sh, vedata->psl->volume_pass);
DRW_shgroup_uniform_float_copy(grp, "slicePosition", sds->slice_depth);
DRW_shgroup_uniform_int_copy(grp, "sliceAxis", axis);
@@ -140,7 +166,6 @@ void workbench_volume_cache_populate(WORKBENCH_Data *vedata, Scene *scene, Objec
BLI_halton_1D(3, 0.0, effect_info->jitter_index, &noise_ofs);
int max_slices = max_iii(sds->res[0], sds->res[1], sds->res[2]) * sds->slice_per_voxel;
- GPUShader *sh = (sds->use_coba) ? e_data.volume_coba_sh : e_data.volume_sh;
grp = DRW_shgroup_create(sh, vedata->psl->volume_pass);
DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)wpd->viewvecs, 3);
DRW_shgroup_uniform_int_copy(grp, "samplesLen", max_slices);