[Bf-blender-cvs] [500d7545f07] new-object-types: Volumes: use full transform matrix for workbench drawing

Brecht Van Lommel noreply at git.blender.org
Fri Jan 31 12:41:31 CET 2020


Commit: 500d7545f074bed19b116720029e8590d0f4e77c
Author: Brecht Van Lommel
Date:   Fri Jan 31 11:19:36 2020 +0100
Branches: new-object-types
https://developer.blender.org/rB500d7545f074bed19b116720029e8590d0f4e77c

Volumes: use full transform matrix for workbench drawing

===================================================================

M	source/blender/draw/engines/workbench/workbench_volume.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl_volume.c

===================================================================

diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c
index 9d0d40a1675..ea8a0a82479 100644
--- a/source/blender/draw/engines/workbench/workbench_volume.c
+++ b/source/blender/draw/engines/workbench/workbench_volume.c
@@ -256,12 +256,14 @@ static void workbench_volume_object_cache_populate(WORKBENCH_Data *vedata, Objec
   /* Create shader. */
   GPUShader *sh = volume_shader_get(use_slice, false, cubic_interp);
 
+  /* Combined texture to object, and object to world transform. */
+  float texture_to_world[4][4];
+  mul_m4_m4m4(texture_to_world, ob->obmat, density->texture_to_object);
+
   /* Compute world space dimensions for step size. */
-  float ob_size[3];
-  mat4_to_size(ob_size, ob->obmat);
-  float world_space_size[3] = {fabsf(ob_size[0]) * density->size[0],
-                               fabsf(ob_size[1]) * density->size[1],
-                               fabsf(ob_size[2]) * density->size[2]};
+  float world_size[3];
+  mat4_to_size(world_size, texture_to_world);
+  abs_v3(world_size);
 
   /* Compute slice parameters. */
   double noise_ofs;
@@ -271,7 +273,7 @@ static void workbench_volume_object_cache_populate(WORKBENCH_Data *vedata, Objec
   mul_v3_fl(slice_ct, max_ff(0.001f, slice_per_voxel));
   max_slice = max_fff(slice_ct[0], slice_ct[1], slice_ct[2]);
   invert_v3(slice_ct);
-  mul_v3_v3(slice_ct, world_space_size);
+  mul_v3_v3(slice_ct, world_size);
   step_length = len_v3(slice_ct);
 
   DRWShadingGroup *grp = DRW_shgroup_create(sh, vedata->psl->volume_pass);
@@ -293,19 +295,13 @@ static void workbench_volume_object_cache_populate(WORKBENCH_Data *vedata, Objec
   DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
   DRW_shgroup_uniform_float_copy(grp, "densityScale", 10.0f * display_thickness);
 
-  /* Combined object and unit cube to bounding box transform. */
-  float unit_cube_to_bb[4][4], drawmat[4][4];
-  size_to_mat4(unit_cube_to_bb, density->size);
-  copy_v3_v3(unit_cube_to_bb[3], density->loc);
-  mul_m4_m4m4(drawmat, ob->obmat, unit_cube_to_bb);
-
   // TODO: DRW_shgroup_call_obmat is not working here, and also does not
   // support culling, so we hack around it like this.
   float backup_obmat[4][4], backup_imat[4][4];
   copy_m4_m4(backup_obmat, ob->obmat);
   copy_m4_m4(backup_imat, ob->imat);
-  copy_m4_m4(ob->obmat, drawmat);
-  invert_m4_m4(ob->imat, drawmat);
+  copy_m4_m4(ob->obmat, texture_to_world);
+  invert_m4_m4(ob->imat, texture_to_world);
   DRW_shgroup_call(grp, DRW_cache_cube_get(), ob);
   copy_m4_m4(ob->obmat, backup_obmat);
   copy_m4_m4(ob->imat, backup_imat);
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 22cad8f01af..52172be8990 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -220,9 +220,10 @@ typedef struct DRWVolumeGrid {
   struct GPUTexture *texture;
   size_t resolution[3];
 
+  /* Transform from 0..1 texture space to object space. */
+  float texture_to_object[4][4];
+
   /* Grid bounding box to fit 3D texture to. */
-  float loc[3];
-  float size[3];
   float mid[3];
   float halfsize[3];
 } DRWVolumeGrid;
diff --git a/source/blender/draw/intern/draw_cache_impl_volume.c b/source/blender/draw/intern/draw_cache_impl_volume.c
index c3dc1aca815..b5696eda628 100644
--- a/source/blender/draw/intern/draw_cache_impl_volume.c
+++ b/source/blender/draw/intern/draw_cache_impl_volume.c
@@ -199,12 +199,13 @@ static DRWVolumeGrid *volume_grid_cache_get(Volume *volume,
 
     MEM_freeN(voxels);
 
-    /* Compute transform. */
-    /* TODO: support full transform, compute bbox as part of dense conversion for perfomance. */
+    /* Compute transform matrix. */
+    BKE_volume_grid_dense_transform_matrix(
+        grid, dense_min, dense_max, cache_grid->texture_to_object);
+
+    /* TODO: support transform matrix in Eevee and remove this code. */
     float min[3], max[3];
     BKE_volume_grid_bounds(grid, min, max);
-    copy_v3_v3(cache_grid->loc, min);
-    sub_v3_v3v3(cache_grid->size, max, min);
     mid_v3_v3v3(cache_grid->mid, min, max);
     cache_grid->halfsize[0] = (max[0] - min[0]) / 2.0f;
     cache_grid->halfsize[1] = (max[1] - min[1]) / 2.0f;



More information about the Bf-blender-cvs mailing list