Volumetric: Debug Voxel Size and Location

When displaying the voxel size for an adaptive domain the resolution of the adaptive domain was used to calculate the world size of the voxel.
This patch changes this to use the initial size of the domain.

When using adaptive domain the overlay was not rendered in the right
place.

Thanks to sebbas for part of the patch!

Reviewed By: sebbas, fclem

Differential Revision: https://developer.blender.org/D6076
This commit is contained in:
Jeroen Bakker
2019-10-16 11:02:01 +02:00
parent f45127c6cb
commit 78f8270ad3
2 changed files with 25 additions and 8 deletions

View File

@@ -2668,12 +2668,21 @@ static void DRW_shgroup_volume_extra(OBJECT_ShadingGroupList *sgl,
DRW_object_wire_theme_get(ob, view_layer, &color);
/* Small cube showing voxel size. */
float min[3];
madd_v3fl_v3fl_v3fl_v3i(min, sds->p0, sds->cell_size, sds->res_min);
float voxel_cubemat[4][4] = {{0.0f}};
voxel_cubemat[0][0] = 1.0f / (float)sds->res[0];
voxel_cubemat[1][1] = 1.0f / (float)sds->res[1];
voxel_cubemat[2][2] = 1.0f / (float)sds->res[2];
/* scale small cube to voxel size */
voxel_cubemat[0][0] = 1.0f / (float)sds->base_res[0];
voxel_cubemat[1][1] = 1.0f / (float)sds->base_res[1];
voxel_cubemat[2][2] = 1.0f / (float)sds->base_res[2];
voxel_cubemat[3][0] = voxel_cubemat[3][1] = voxel_cubemat[3][2] = -1.0f;
voxel_cubemat[3][3] = 1.0f;
/* translate small cube to corner */
voxel_cubemat[3][0] = min[0];
voxel_cubemat[3][1] = min[1];
voxel_cubemat[3][2] = min[2];
voxel_cubemat[3][3] = 1.0f;
/* move small cube into the domain (otherwise its centered on vertex of domain object) */
translate_m4(voxel_cubemat, 1.0f, 1.0f, 1.0f);
mul_m4_m4m4(voxel_cubemat, ob->obmat, voxel_cubemat);
@@ -2709,6 +2718,9 @@ static void DRW_shgroup_volume_extra(OBJECT_ShadingGroupList *sgl,
DRW_shgroup_uniform_texture(grp, "velocityZ", sds->tex_velocity_z);
DRW_shgroup_uniform_float_copy(grp, "displaySize", sds->vector_scale);
DRW_shgroup_uniform_float_copy(grp, "slicePosition", sds->slice_depth);
DRW_shgroup_uniform_vec3_copy(grp, "cellSize", sds->cell_size);
DRW_shgroup_uniform_vec3_copy(grp, "domainOriginOffset", sds->p0);
DRW_shgroup_uniform_ivec3_copy(grp, "adaptiveCellOffset", sds->res_min);
DRW_shgroup_uniform_int_copy(grp, "sliceAxis", slice_axis);
DRW_shgroup_call_procedural_lines(grp, ob, line_count);

View File

@@ -6,6 +6,13 @@ uniform float displaySize = 1.0;
uniform float slicePosition;
uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */
/* SmokeDomainSettings.cell_size */
uniform vec3 cellSize;
/* SmokeDomainSettings.p0 */
uniform vec3 domainOriginOffset;
/* SmokeDomainSettings.res_min */
uniform ivec3 adaptiveCellOffset;
flat out vec4 finalColor;
const vec3 corners[4] = vec3[4](vec3(0.0, 0.2, -0.5),
@@ -66,7 +73,6 @@ void main()
#endif
ivec3 volume_size = textureSize(velocityX, 0);
float voxel_size = 1.0 / float(max(max(volume_size.x, volume_size.y), volume_size.z));
ivec3 cell_ofs = ivec3(0);
ivec3 cell_div = volume_size;
@@ -89,8 +95,7 @@ void main()
cell_co.z = cell / (cell_div.x * cell_div.y);
cell_co += cell_ofs;
vec3 pos = (vec3(cell_co) + 0.5) / vec3(volume_size);
pos = pos * 2.0 - 1.0;
vec3 pos = domainOriginOffset + cellSize * (vec3(cell_co + adaptiveCellOffset) + 0.5);
vec3 velocity;
velocity.x = texelFetch(velocityX, cell_co, 0).r;
@@ -102,9 +107,9 @@ void main()
#ifdef USE_NEEDLE
mat3 rot_mat = rotation_from_vector(velocity);
vec3 rotated_pos = rot_mat * corners[indices[gl_VertexID % 12]];
pos += rotated_pos * length(velocity) * displaySize * voxel_size;
pos += rotated_pos * length(velocity) * displaySize * cellSize;
#else
pos += (((gl_VertexID % 2) == 1) ? velocity : vec3(0.0)) * displaySize * voxel_size;
pos += ((gl_VertexID % 2) == 1) ? velocity * displaySize * cellSize : vec3(0.0);
#endif
vec3 world_pos = point_object_to_world(pos);