[Bf-blender-cvs] [ccc99b5b395] new-object-types: Fix Eevee volume tests failures due to wrong transforms

Brecht Van Lommel noreply at git.blender.org
Sun Feb 16 00:24:20 CET 2020


Commit: ccc99b5b395a8d08c2f82a2c5567251402ef661f
Author: Brecht Van Lommel
Date:   Sun Feb 16 00:13:24 2020 +0100
Branches: new-object-types
https://developer.blender.org/rBccc99b5b395a8d08c2f82a2c5567251402ef661f

Fix Eevee volume tests failures due to wrong transforms

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

M	source/blender/draw/engines/eevee/eevee_volumes.c
M	source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl

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

diff --git a/source/blender/draw/engines/eevee/eevee_volumes.c b/source/blender/draw/engines/eevee/eevee_volumes.c
index 814d0b17b09..ab0001b41e6 100644
--- a/source/blender/draw/engines/eevee/eevee_volumes.c
+++ b/source/blender/draw/engines/eevee/eevee_volumes.c
@@ -437,18 +437,16 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata,
 
   DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
 
-  static const float zero_transform[4][4] = {{0.0f, 0.0f}};
-
   ListBase textures = GPU_material_textures(mat);
 
+  float texture_to_object[4][4];
+  bool have_transform = false;
+
   /* Volume Object */
   if (ob->type == OB_VOLUME) {
     Volume *volume = ob->data;
     BKE_volume_load(volume, G.main);
 
-    /* TODO: ensure we are culling volumes out of view. */
-    bool have_transform = false;
-
     for (GPUMaterialTexture *tex = textures.first; tex; tex = tex->next) {
       if (tex->volume_grid == NULL) {
         continue;
@@ -465,7 +463,7 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata,
       /* Volume dimensions for texture sampling. */
       if (!have_transform && drw_grid) {
         /* TODO: support different transform per grid. */
-        DRW_shgroup_uniform_mat4(grp, "volumeObjectToLocal", drw_grid->object_to_texture);
+        copy_m4_m4(texture_to_object, drw_grid->texture_to_object);
         have_transform = true;
       }
     }
@@ -538,7 +536,17 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata,
     /* Output is such that 0..1 maps to 0..1000K */
     float volume_temperature[2] = {mds->flame_ignition, mds->flame_max_temp};
     DRW_shgroup_uniform_vec2_copy(grp, "volumeTemperature", volume_temperature);
+  }
+  else {
+    for (GPUMaterialTexture *tex = textures.first; tex; tex = tex->next) {
+      if (tex->volume_grid) {
+        DRW_shgroup_uniform_texture(grp, tex->shadername, e_data.dummy_density);
+        continue;
+      }
+    }
+  }
 
+  if (!have_transform) {
     /* Compute transform matrix from object to texture space. */
     float *texco_mid, *texco_halfsize;
     BKE_mesh_texspace_get_reference((struct Mesh *)ob->data, NULL, &texco_mid, &texco_halfsize);
@@ -547,26 +555,25 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata,
     sub_v3_v3v3(texco_loc, texco_mid, texco_halfsize);
     mul_v3_v3fl(texco_size, texco_halfsize, 2.0f);
 
-    size_to_mat4(mds->tex_transform, texco_size);
-    copy_v3_v3(mds->tex_transform[3], texco_loc);
-    invert_m4(mds->tex_transform);
-
-    DRW_shgroup_uniform_mat4(grp, "volumeObjectToLocal", mds->tex_transform);
-  }
-  else {
-    for (GPUMaterialTexture *tex = textures.first; tex; tex = tex->next) {
-      if (tex->volume_grid) {
-        DRW_shgroup_uniform_texture(grp, tex->shadername, e_data.dummy_density);
-        continue;
-      }
-    }
-    DRW_shgroup_uniform_mat4(grp, "volumeObjectToLocal", zero_transform);
+    size_to_mat4(texture_to_object, texco_size);
+    copy_v3_v3(texture_to_object[3], texco_loc);
   }
 
+  /* Hack to add additional transform. */
+  /* TODO: add proper way to pass custom matrix overriding object. */
+  float backup_obmat[4][4], backup_imat[4][4];
+  copy_m4_m4(backup_obmat, ob->obmat);
+  copy_m4_m4(backup_imat, ob->imat);
+  mul_m4_m4m4(ob->obmat, ob->obmat, texture_to_object);
+  invert_m4_m4(ob->imat, ob->obmat);
+
   /* TODO Reduce to number of slices intersecting. */
   /* TODO Preemptive culling. */
   DRW_shgroup_call_procedural_triangles(grp, ob, sldata->common_data.vol_tex_size[2]);
 
+  copy_m4_m4(ob->obmat, backup_obmat);
+  copy_m4_m4(ob->imat, backup_imat);
+
   vedata->stl->effects->enabled_effects |= (EFFECT_VOLUMETRIC | EFFECT_POST_BUFFER);
 }
 
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl
index 182b0864f8d..327e25ab7c1 100644
--- a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl
@@ -4,10 +4,6 @@
 
 #define NODETREE_EXEC
 
-#ifdef MESH_SHADER
-uniform mat4 volumeObjectToLocal;
-#endif
-
 flat in int slice;
 
 /* Warning: these are not attributes, these are global vars. */
@@ -34,7 +30,6 @@ void main()
   worldPosition = point_view_to_world(viewPosition);
 #ifdef MESH_SHADER
   volumeObjectLocalCoord = point_world_to_object(worldPosition);
-  volumeObjectLocalCoord = (volumeObjectToLocal * vec4(volumeObjectLocalCoord, 1.0)).xyz;
 
   if (any(lessThan(volumeObjectLocalCoord, vec3(0.0))) ||
       any(greaterThan(volumeObjectLocalCoord, vec3(1.0))))



More information about the Bf-blender-cvs mailing list