[Bf-blender-cvs] [fd53b72871e] master: Objects: Eevee and workbench rendering of new Volume, Hair, PointCloud

Brecht Van Lommel noreply at git.blender.org
Wed Mar 18 11:23:44 CET 2020


Commit: fd53b72871e045dfebfb9ddbe2b3c491491aa913
Author: Brecht Van Lommel
Date:   Tue Mar 17 16:27:08 2020 +0100
Branches: master
https://developer.blender.org/rBfd53b72871e045dfebfb9ddbe2b3c491491aa913

Objects: Eevee and workbench rendering of new Volume, Hair, PointCloud

Only the volume drawing part is really finished and exposed to the user. Hair
plugs into the existing hair rendering code and is fairly straightforward. The
pointcloud drawing is a hack using overlays rather than Eevee and workbench.

The most tricky part for volume rendering is the case where each volume grid
has a different transform, which requires an additional matrix in the shader
and non-trivial logic in Eevee volume drawing. In the common case were all the
transforms match we don't use the additional per-grid matrix in the shader.

Ref T73201, T68981

Differential Revision: https://developer.blender.org/D6955

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

M	release/scripts/startup/bl_ui/properties_data_volume.py
A	source/blender/blenkernel/BKE_volume_render.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/volume_render.cc
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/eevee/eevee_engine.c
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/draw/engines/eevee/eevee_render.c
M	source/blender/draw/engines/eevee/eevee_volumes.c
M	source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl
M	source/blender/draw/engines/overlay/overlay_engine.c
M	source/blender/draw/engines/overlay/overlay_extra.c
M	source/blender/draw/engines/overlay/overlay_private.h
M	source/blender/draw/engines/overlay/overlay_shader.c
M	source/blender/draw/engines/overlay/overlay_wireframe.c
M	source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl
M	source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl
M	source/blender/draw/engines/workbench/workbench_engine.c
M	source/blender/draw/engines/workbench/workbench_private.h
M	source/blender/draw/engines/workbench/workbench_shader.c
M	source/blender/draw/engines/workbench/workbench_volume.c
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_displist.c
M	source/blender/draw/intern/draw_cache_impl_particles.c
M	source/blender/draw/intern/draw_common.c
M	source/blender/draw/intern/draw_hair.c
M	source/blender/draw/intern/draw_hair_private.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/gpu/GPU_material.h
M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/intern/gpu_node_graph.c
M	source/blender/gpu/intern/gpu_node_graph.h
M	source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl

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

diff --git a/release/scripts/startup/bl_ui/properties_data_volume.py b/release/scripts/startup/bl_ui/properties_data_volume.py
index 29e28aa2c02..bc098e81ffb 100644
--- a/release/scripts/startup/bl_ui/properties_data_volume.py
+++ b/release/scripts/startup/bl_ui/properties_data_volume.py
@@ -108,28 +108,6 @@ class DATA_PT_volume_grids(DataButtonsPanel, Panel):
         layout.template_list("VOLUME_UL_grids", "grids", volume, "grids", volume.grids, "active_index", rows=3)
 
 
-class DATA_PT_volume_render(DataButtonsPanel, Panel):
-    bl_label = "Render"
-    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
-
-    def draw(self, context):
-        layout = self.layout
-        layout.use_property_split = True
-        layout.use_property_decorate = False
-
-        scene = context.scene
-        volume = context.volume
-        render = volume.render
-
-        col = layout.column(align=True)
-        col.prop(render, "space")
-        col.prop(render, "step_size")
-
-        if scene.render.engine == 'CYCLES':
-            col = layout.column(align=True)
-            col.prop(render, "clipping")
-
-
 class DATA_PT_volume_viewport_display(DataButtonsPanel, Panel):
     bl_label = "Viewport Display"
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
@@ -162,7 +140,6 @@ classes = (
     DATA_PT_volume_grids,
     DATA_PT_volume_file,
     DATA_PT_volume_viewport_display,
-    DATA_PT_volume_render,
     DATA_PT_custom_props_volume,
     VOLUME_UL_grids,
 )
diff --git a/source/blender/blenkernel/BKE_volume_render.h b/source/blender/blenkernel/BKE_volume_render.h
new file mode 100644
index 00000000000..72360f316a0
--- /dev/null
+++ b/source/blender/blenkernel/BKE_volume_render.h
@@ -0,0 +1,72 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Brecht Van Lommel.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BKE_VOLUME_RENDER_H__
+#define __BKE_VOLUME_RENDER_H__
+
+/** \file BKE_volume_render.h
+ *  \ingroup bke
+ *  \brief Volume datablock rendering and viewport drawing utilities.
+ */
+
+#include "BLI_sys_types.h"
+
+#include "DNA_volume_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Volume;
+struct VolumeGrid;
+
+/* Dense Voxels */
+
+bool BKE_volume_grid_dense_bounds(const struct Volume *volume,
+                                  struct VolumeGrid *volume_grid,
+                                  int64_t min[3],
+                                  int64_t max[3]);
+void BKE_volume_grid_dense_transform_matrix(const struct VolumeGrid *volume_grid,
+                                            const int64_t min[3],
+                                            const int64_t max[3],
+                                            float matrix[4][4]);
+void BKE_volume_grid_dense_voxels(const struct Volume *volume,
+                                  struct VolumeGrid *volume_grid,
+                                  const int64_t min[3],
+                                  const int64_t max[3],
+                                  float *voxels);
+
+/* Wireframe */
+
+typedef void (*BKE_volume_wireframe_cb)(
+    void *userdata, float (*verts)[3], int (*edges)[2], int totvert, int totedge);
+
+void BKE_volume_grid_wireframe(const struct Volume *volume,
+                               struct VolumeGrid *volume_grid,
+                               BKE_volume_wireframe_cb cb,
+                               void *cb_userdata);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index d3dfa422ebd..7fd5470cecc 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -242,6 +242,7 @@ set(SRC
   intern/undo_system.c
   intern/unit.c
   intern/volume.cc
+  intern/volume_render.cc
   intern/workspace.c
   intern/world.c
   intern/writeavi.c
@@ -375,6 +376,7 @@ set(SRC
   BKE_undo_system.h
   BKE_unit.h
   BKE_volume.h
+  BKE_volume_render.h
   BKE_workspace.h
   BKE_world.h
   BKE_writeavi.h
diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc
new file mode 100644
index 00000000000..d8fbbce3bae
--- /dev/null
+++ b/source/blender/blenkernel/intern/volume_render.cc
@@ -0,0 +1,358 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/volume_render.cc
+ *  \ingroup bke
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math_matrix.h"
+#include "BLI_math_vector.h"
+
+#include "DNA_volume_types.h"
+
+#include "BKE_volume.h"
+#include "BKE_volume_render.h"
+
+#ifdef WITH_OPENVDB
+#  include <openvdb/openvdb.h>
+#  include <openvdb/tools/Dense.h>
+#endif
+
+/* Dense Voxels */
+
+bool BKE_volume_grid_dense_bounds(const Volume *volume,
+                                  VolumeGrid *volume_grid,
+                                  int64_t min[3],
+                                  int64_t max[3])
+{
+#ifdef WITH_OPENVDB
+  openvdb::GridBase::ConstPtr grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid);
+
+  openvdb::CoordBBox bbox = grid->evalActiveVoxelBoundingBox();
+  if (!bbox.empty()) {
+    /* OpenVDB bbox is inclusive, so add 1 to convert. */
+    min[0] = bbox.min().x();
+    min[1] = bbox.min().y();
+    min[2] = bbox.min().z();
+    max[0] = bbox.max().x() + 1;
+    max[1] = bbox.max().y() + 1;
+    max[2] = bbox.max().z() + 1;
+    return true;
+  }
+#else
+  UNUSED_VARS(volume, volume_grid);
+#endif
+
+  min[0] = 0;
+  min[1] = 0;
+  min[2] = 0;
+  max[0] = 0;
+  max[1] = 0;
+  max[2] = 0;
+  return false;
+}
+
+/* Transform matrix from unit cube to object space, for 3D texture sampling. */
+void BKE_volume_grid_dense_transform_matrix(const VolumeGrid *volume_grid,
+                                            const int64_t min[3],
+                                            const int64_t max[3],
+                                            float mat[4][4])
+{
+#ifdef WITH_OPENVDB
+  float index_to_world[4][4];
+  BKE_volume_grid_transform_matrix(volume_grid, index_to_world);
+
+  float texture_to_index[4][4];
+  float loc[3] = {(float)min[0], (float)min[1], (float)min[2]};
+  float size[3] = {(float)(max[0] - min[0]), (float)(max[1] - min[1]), (float)(max[2] - min[2])};
+  size_to_mat4(texture_to_index, size);
+  copy_v3_v3(texture_to_index[3], loc);
+
+  mul_m4_m4m4(mat, index_to_world, texture_to_index);
+#else
+  UNUSED_VARS(volume_grid, min, max);
+  unit_m4(mat);
+#endif
+}
+
+void BKE_volume_grid_dense_voxels(const Volume *volume,
+                                  VolumeGrid *volume_grid,
+                                  const int64_t min[3],
+                                  const int64_t max[3],
+                                  float *voxels)
+{
+#ifdef WITH_OPENVDB
+  openvdb::GridBase::ConstPtr grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid);
+
+  /* Convert to OpenVDB inclusive bbox with -1. */
+  openvdb::CoordBBox bbox(min[0], min[1], min[2], max[0] - 1, max[1] - 1, max[2] - 1);
+
+  switch (BKE_volume_grid_type(volume_grid)) {
+    case VOLUME_GRID_BOOLEAN: {
+      openvdb::tools::Dense<float, openvdb::tools::LayoutXYZ> dense(bbox, voxels);
+      openvdb::tools::copyToDense(*openvdb::gridConstPtrCast<openvdb::BoolGrid>(grid), dense);
+      break;
+    }
+    case VOLUME_GRID_FLOAT: {
+      openvdb::tools::Dense<float, openvdb::tools::LayoutXYZ> dense(bbox, voxels);
+      openvdb::tools::copyToDense(*openvdb::gridConstPtrCast<openvdb::FloatGrid>(grid), dense);
+      break;
+    }
+    case VOLUME_GRID_DOUBLE: {
+      openvdb::tools::Dense<float, openvdb::tools::LayoutXYZ> dense(bbox, voxels);
+      openvdb::tools::copyToDense(*openvdb::gridConstPtrCast<openvdb::DoubleGrid>(grid), dense);
+      break;
+    }
+    case VOLUME_GRID_INT: {
+      openvdb::tools::Dense<float, openvdb::tools::LayoutXYZ> dense(bbox, voxels);
+      openvdb::tools::copyToDense(*openvdb::gridConstPtrCast<openvdb::Int32Grid>(grid), dense);
+      break;
+    }
+    case VOLUME_GRID_INT64: {
+      openvdb::tools::Dense<float, openvdb::tools::LayoutXYZ> dense(bbox, voxels);
+      openvdb::tools::copyToDense(*openvdb::gridConstPtrCast<openvdb::Int64Grid>(grid), dense);
+      break;
+    }
+    case VOLUME_GRID_MASK: {
+      openvdb::tools::Dense<float, openvdb::tools::LayoutXYZ> dense(bbox, voxels);
+      openvdb::tools::copyToDense(*openvdb::gridConstPtrCast<openvdb::MaskGrid>(grid), dense);
+      break;
+    }
+    case VOLUME_GRID_VECTOR_FLOAT: {
+      openvdb::tools::Dense<openvdb::Vec3f, openvdb::tools::LayoutXYZ> dense(
+          bbox, (openvdb::Vec3f *)voxels);
+      openvdb::tools::copyToDense(*openvdb::gridConstPtrCa

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list