diff options
author | Sriharsha Kotcharlakot <k.venkatsriharsha@gmail.com> | 2020-09-15 18:51:14 +0300 |
---|---|---|
committer | Sriharsha Kotcharlakot <k.venkatsriharsha@gmail.com> | 2020-09-15 20:43:01 +0300 |
commit | f137022f9919f4dd315ec6b325a08e1bf5aec6fb (patch) | |
tree | 4b15aa230eb100e77b41dfffb8ef5e7501c55db5 /source/blender/draw/engines/overlay/shaders | |
parent | bedbd8655ed1d331aeaf756874c46dbed93168a1 (diff) |
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
Diffstat (limited to 'source/blender/draw/engines/overlay/shaders')
-rw-r--r-- | source/blender/draw/engines/overlay/shaders/volume_gridlines_vert.glsl | 121 | ||||
-rw-r--r-- | source/blender/draw/engines/overlay/shaders/volume_velocity_vert.glsl | 118 |
2 files changed, 229 insertions, 10 deletions
diff --git a/source/blender/draw/engines/overlay/shaders/volume_gridlines_vert.glsl b/source/blender/draw/engines/overlay/shaders/volume_gridlines_vert.glsl new file mode 100644 index 00000000000..f714646fe40 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/volume_gridlines_vert.glsl @@ -0,0 +1,121 @@ +uniform float slicePosition; +uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */ + +/* FluidDomainSettings.res */ +uniform ivec3 volumeSize; +/* FluidDomainSettings.cell_size */ +uniform vec3 cellSize; +/* FluidDomainSettings.p0 */ +uniform vec3 domainOriginOffset; +/* FluidDomainSettings.res_min */ +uniform ivec3 adaptiveCellOffset; + +#if defined(SHOW_FLAGS) || defined(SHOW_RANGE) +uniform usampler3D flagTexture; +#endif + +#ifdef SHOW_RANGE +uniform sampler3D fieldTexture; +uniform float lowerBound = 0.0; +uniform float upperBound = 0.0; +uniform vec4 rangeColor; +uniform int cellFilter; +#endif + +flat out vec4 finalColor; + +/* Corners for cell outlines. 0.45 is arbitrary. Any value below 0.5 can be used to avoid + * overlapping of the outlines. */ +const vec3 corners[4] = vec3[4](vec3(-0.45, 0.45, 0.0), + vec3(0.45, 0.45, 0.0), + vec3(0.45, -0.45, 0.0), + vec3(-0.45, -0.45, 0.0)); + +const int indices[8] = int[8](0, 1, 1, 2, 2, 3, 3, 0); + +vec4 flag_to_color(uint flag) +{ + /* Color mapping for flags */ + vec4 color = vec4(0.0, 0.0, 0.0, 1.0); + /* 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.4, 0.4, 0.4); /* 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; +} + +void main() +{ + int cell = gl_VertexID / 8; + mat3 rot_mat = mat3(0.0); + + vec3 cell_offset = vec3(0.5); + ivec3 cell_div = volumeSize; + if (sliceAxis == 0) { + cell_offset.x = slicePosition * float(volumeSize.x); + cell_div.x = 1; + rot_mat[2].x = 1.0; + rot_mat[0].y = 1.0; + rot_mat[1].z = 1.0; + } + else if (sliceAxis == 1) { + cell_offset.y = slicePosition * float(volumeSize.y); + cell_div.y = 1; + rot_mat[1].x = 1.0; + rot_mat[2].y = 1.0; + rot_mat[0].z = 1.0; + } + else if (sliceAxis == 2) { + cell_offset.z = slicePosition * float(volumeSize.z); + cell_div.z = 1; + rot_mat[0].x = 1.0; + rot_mat[1].y = 1.0; + rot_mat[2].z = 1.0; + } + + ivec3 cell_co; + cell_co.x = cell % cell_div.x; + cell_co.y = (cell / cell_div.x) % cell_div.y; + cell_co.z = cell / (cell_div.x * cell_div.y); + + finalColor = vec4(0.0, 0.0, 0.0, 1.0); + +#if defined(SHOW_FLAGS) || defined(SHOW_RANGE) + uint flag = texelFetch(flagTexture, cell_co + ivec3(cell_offset), 0).r; +#endif + +#ifdef SHOW_FLAGS + finalColor = flag_to_color(flag); +#endif + +#ifdef SHOW_RANGE + float value = texelFetch(fieldTexture, cell_co + ivec3(cell_offset), 0).r; + if (value >= lowerBound && value <= upperBound) { + if (cellFilter == 0 || bool(uint(cellFilter) & flag)) { + finalColor = rangeColor; + } + } +#endif + + vec3 pos = domainOriginOffset + cellSize * (vec3(cell_co + adaptiveCellOffset) + cell_offset); + vec3 rotated_pos = rot_mat * corners[indices[gl_VertexID % 8]]; + pos += rotated_pos * cellSize; + + vec3 world_pos = point_object_to_world(pos); + gl_Position = point_world_to_ndc(world_pos); +} diff --git a/source/blender/draw/engines/overlay/shaders/volume_velocity_vert.glsl b/source/blender/draw/engines/overlay/shaders/volume_velocity_vert.glsl index 752694301f7..0b827601f8e 100644 --- a/source/blender/draw/engines/overlay/shaders/volume_velocity_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/volume_velocity_vert.glsl @@ -5,6 +5,8 @@ uniform sampler3D velocityZ; uniform float displaySize = 1.0; uniform float slicePosition; uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */ +uniform bool scaleWithMagnitude = false; +uniform bool isCellCentered = false; /* FluidDomainSettings.cell_size */ uniform vec3 cellSize; @@ -13,7 +15,15 @@ uniform vec3 domainOriginOffset; /* FluidDomainSettings.res_min */ uniform ivec3 adaptiveCellOffset; +#ifdef USE_MAC +uniform bool drawMACX; +uniform bool drawMACY; +uniform bool drawMACZ; + +out vec4 finalColor; +#else flat out vec4 finalColor; +#endif const vec3 corners[4] = vec3[4](vec3(0.0, 0.2, -0.5), vec3(-0.2 * 0.866, -0.2 * 0.5, -0.5), @@ -64,10 +74,53 @@ mat3 rotation_from_vector(vec3 v) return mat3(T, B, N); } +vec3 get_vector(ivec3 cell_co) +{ + vec3 vector; + + vector.x = texelFetch(velocityX, cell_co, 0).r; + vector.y = texelFetch(velocityY, cell_co, 0).r; + vector.z = texelFetch(velocityZ, cell_co, 0).r; + + return vector; +} + +/* Interpolate MAC information for cell-centered vectors. */ +vec3 get_vector_centered(ivec3 cell_co) +{ + vec3 vector; + + vector.x = 0.5 * (texelFetch(velocityX, cell_co, 0).r + + texelFetch(velocityX, ivec3(cell_co.x + 1, cell_co.yz), 0).r); + vector.y = 0.5 * (texelFetch(velocityY, cell_co, 0).r + + texelFetch(velocityY, ivec3(cell_co.x, cell_co.y + 1, cell_co.z), 0).r); + vector.z = 0.5 * (texelFetch(velocityZ, cell_co, 0).r + + texelFetch(velocityZ, ivec3(cell_co.xy, cell_co.z + 1), 0).r); + + return vector; +} + +/* Interpolate cell-centered information for MAC vectors. */ +vec3 get_vector_mac(ivec3 cell_co) +{ + vec3 vector; + + vector.x = 0.5 * (texelFetch(velocityX, ivec3(cell_co.x - 1, cell_co.yz), 0).r + + texelFetch(velocityX, cell_co, 0).r); + vector.y = 0.5 * (texelFetch(velocityY, ivec3(cell_co.x, cell_co.y - 1, cell_co.z), 0).r + + texelFetch(velocityY, cell_co, 0).r); + vector.z = 0.5 * (texelFetch(velocityZ, ivec3(cell_co.xy, cell_co.z - 1), 0).r + + texelFetch(velocityZ, cell_co, 0).r); + + return vector; +} + void main() { #ifdef USE_NEEDLE int cell = gl_VertexID / 12; +#elif defined(USE_MAC) + int cell = gl_VertexID / 6; #else int cell = gl_VertexID / 2; #endif @@ -97,19 +150,64 @@ void main() vec3 pos = domainOriginOffset + cellSize * (vec3(cell_co + adaptiveCellOffset) + 0.5); - vec3 velocity; - velocity.x = texelFetch(velocityX, cell_co, 0).r; - velocity.y = texelFetch(velocityY, cell_co, 0).r; - velocity.z = texelFetch(velocityZ, cell_co, 0).r; + vec3 vector; + +#ifdef USE_MAC + vec3 color; + vector = (isCellCentered) ? get_vector_mac(cell_co) : get_vector(cell_co); + + switch (gl_VertexID % 6) { + case 0: /* Tail of X component. */ + pos.x += (drawMACX) ? -0.5 * cellSize.x : 0.0; + color = vec3(1.0, 0.0, 0.0); /* red */ + break; + case 1: /* Head of X component. */ + pos.x += (drawMACX) ? (-0.5 + vector.x * displaySize) * cellSize.x : 0.0; + color = vec3(1.0, 1.0, 0.0); /* yellow */ + break; + case 2: /* Tail of Y component. */ + pos.y += (drawMACY) ? -0.5 * cellSize.y : 0.0; + color = vec3(0.0, 1.0, 0.0); /* green */ + break; + case 3: /* Head of Y component. */ + pos.y += (drawMACY) ? (-0.5 + vector.y * displaySize) * cellSize.y : 0.0; + color = vec3(1.0, 1.0, 0.0); /* yellow */ + break; + case 4: /* Tail of Z component. */ + pos.z += (drawMACZ) ? -0.5 * cellSize.z : 0.0; + color = vec3(0.0, 0.0, 1.0); /* blue */ + break; + case 5: /* Head of Z component. */ + pos.z += (drawMACZ) ? (-0.5 + vector.z * displaySize) * cellSize.z : 0.0; + color = vec3(1.0, 1.0, 0.0); /* yellow */ + break; + } - finalColor = vec4(weight_to_color(length(velocity)), 1.0); + finalColor = vec4(color, 1.0); +#else + vector = (isCellCentered) ? get_vector(cell_co) : get_vector_centered(cell_co); -#ifdef USE_NEEDLE - mat3 rot_mat = rotation_from_vector(velocity); + finalColor = vec4(weight_to_color(length(vector)), 1.0); + + float vector_length = 1.0; + + if (scaleWithMagnitude) { + vector_length = length(vector); + } + else if (length(vector) == 0.0) { + vector_length = 0.0; + } + + mat3 rot_mat = rotation_from_vector(vector); + +# ifdef USE_NEEDLE vec3 rotated_pos = rot_mat * corners[indices[gl_VertexID % 12]]; - pos += rotated_pos * length(velocity) * displaySize * cellSize; -#else - pos += ((gl_VertexID % 2) == 1) ? velocity * displaySize * cellSize : vec3(0.0); + pos += rotated_pos * vector_length * displaySize * cellSize; +# else + vec3 rotated_pos = rot_mat * vec3(0.0, 0.0, 1.0); + pos += ((gl_VertexID % 2) == 1) ? rotated_pos * vector_length * displaySize * cellSize : + vec3(0.0); +# endif #endif vec3 world_pos = point_object_to_world(pos); |