From f137022f9919f4dd315ec6b325a08e1bf5aec6fb Mon Sep 17 00:00:00 2001 From: Sriharsha Kotcharlakot Date: Tue, 15 Sep 2020 21:21:14 +0530 Subject: Liquid Simulation Display Options (GSoC 2020) All the changes made in the branch `soc-2020-fluid-tools` are included in this patch. **Major changes:** === Viewport Display === - //Raw voxel display// or //closest (nearest-neighbor)// interpolation for displaying the underlying voxel data of the simulation grids more clearly. - An option to display //gridlines// when the slicing method is //single//. ==== Grid Display ==== - Visualization for flags, pressure and level-set representation grids with a fixed color coding based on Manta GUI. ==== Vector Display ==== - //**M**arker **A**nd **C**ell// grid visualization options for vector grids like velocity or external forces. - Made vector display options available for external forces. ==== Coloring options for //gridlines// ==== - Range highlighting and cell filtering options for displaying the simulation grid data more precisely. - Color gridlines with flags. - Also, made slicing and interpolation options available for Volume Object. Reviewed By: JacquesLucke, sebbas Differential Revision: https://developer.blender.org/D8705 --- .../workbench/shaders/workbench_volume_frag.glsl | 83 +++++++++++++++++++++- 1 file changed, 80 insertions(+), 3 deletions(-) (limited to 'source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl') diff --git a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl index aa938d80fa3..eaa553a10de 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl @@ -10,6 +10,7 @@ uniform sampler2D depthBuffer; uniform sampler3D densityTexture; uniform sampler3D shadowTexture; uniform sampler3D flameTexture; +uniform usampler3D flagTexture; uniform sampler1D flameColorTexture; uniform sampler1D transferTexture; uniform mat4 volumeObjectToTexture; @@ -18,11 +19,16 @@ uniform int samplesLen = 256; uniform float noiseOfs = 0.0; uniform float stepLength; /* Step length in local space. */ uniform float densityScale; /* Simple Opacity multiplicator. */ +uniform float gridScale; /* Multiplicator for grid scaling. */ uniform vec3 activeColor; uniform float slicePosition; uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */ +uniform bool showPhi = false; +uniform bool showFlags = false; +uniform bool showPressure = false; + #ifdef VOLUME_SLICE in vec3 localPos; #endif @@ -91,18 +97,89 @@ vec4 sample_tricubic(sampler3D ima, vec3 co) return color; } +/* Nearest-neighbor interpolation */ +vec4 sample_closest(sampler3D ima, vec3 co) +{ + /* Unnormalize coordinates */ + ivec3 cell_co = ivec3(co * vec3(textureSize(ima, 0).xyz)); + + return texelFetch(ima, cell_co, 0); +} + +vec4 flag_to_color(uint flag) +{ + /* Color mapping for flags */ + vec4 color = vec4(0.0, 0.0, 0.0, 0.06); + /* Cell types: 1 is Fluid, 2 is Obstacle, 4 is Empty, 8 is Inflow, 16 is Outflow */ + if (bool(flag & uint(1))) { + color.rgb += vec3(0.0, 0.0, 0.75); /* blue */ + } + if (bool(flag & uint(2))) { + color.rgb += vec3(0.2, 0.2, 0.2); /* dark gray */ + } + if (bool(flag & uint(4))) { + color.rgb += vec3(0.25, 0.0, 0.2); /* dark purple */ + } + if (bool(flag & uint(8))) { + color.rgb += vec3(0.0, 0.5, 0.0); /* dark green */ + } + if (bool(flag & uint(16))) { + color.rgb += vec3(0.9, 0.3, 0.0); /* orange */ + } + if (color.rgb == vec3(0.0)) { + color.rgb += vec3(0.5, 0.0, 0.0); /* medium red */ + } + return color; +} + #ifdef USE_TRICUBIC # define sample_volume_texture sample_tricubic -#else +#elif defined(USE_TRILINEAR) # define sample_volume_texture sample_trilinear +#elif defined(USE_CLOSEST) +# define sample_volume_texture sample_closest #endif void volume_properties(vec3 ls_pos, out vec3 scattering, out float extinction) { vec3 co = ls_pos * 0.5 + 0.5; #ifdef USE_COBA - float val = sample_volume_texture(densityTexture, co).r; - vec4 tval = texture(transferTexture, val) * densityScale; + vec4 tval; + if (showPhi) { + /* Color mapping for level-set representation */ + float val = sample_volume_texture(densityTexture, co).r * gridScale; + + val = max(min(val * 0.2, 1.0), -1.0); + + if (val >= 0.0) { + tval = vec4(val, 0.0, 0.5, 0.06); + } + else { + tval = vec4(0.5, 1.0 + val, 0.0, 0.06); + } + } + else if (showFlags) { + /* Color mapping for flags */ + uint flag = texture(flagTexture, co).r; + tval = flag_to_color(flag); + } + else if (showPressure) { + /* Color mapping for pressure */ + float val = sample_volume_texture(densityTexture, co).r * gridScale; + + if (val > 0) { + tval = vec4(val, val, val, 0.06); + } + else { + tval = vec4(-val, 0.0, 0.0, 0.06); + } + } + else { + float val = sample_volume_texture(densityTexture, co).r * gridScale; + tval = texture(transferTexture, val); + } + tval *= densityScale; + tval.rgb = pow(tval.rgb, vec3(2.2)); scattering = tval.rgb * 1500.0; extinction = max(1e-4, tval.a * 50.0); #else -- cgit v1.2.3