Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2018-11-01 17:12:54 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2018-11-01 17:20:50 +0300
commitd710cb91b9281e94851bddc8b49b570dc6326b5f (patch)
tree1dcca4ff99b327ce0eaf21715b5986082ac5e540 /source
parentc2aa8d03f26ceb2700730e5aeb2c72ccfa969116 (diff)
Subdiv: Cleanup, de-duplicate tangent matrix calculation
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_multires.h16
-rw-r--r--source/blender/blenkernel/intern/multires_inline.h68
-rw-r--r--source/blender/blenkernel/intern/multires_reshape.c34
-rw-r--r--source/blender/blenkernel/intern/subdiv_displacement_multires.c35
4 files changed, 88 insertions, 65 deletions
diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h
index 28a98768a06..d4e0dbb72cd 100644
--- a/source/blender/blenkernel/BKE_multires.h
+++ b/source/blender/blenkernel/BKE_multires.h
@@ -32,6 +32,8 @@
* \ingroup bke
*/
+#include "BLI_compiler_compat.h"
+
enum MultiresModifiedFlags;
struct Depsgraph;
@@ -151,4 +153,18 @@ void BKE_multires_subdiv_mesh_settings_init(
const bool use_render_params,
const bool ignore_simplify);
+/* General helpers. */
+
+/* For a given partial derivatives of a ptex face get tangent matrix for
+ * displacement.
+ * Corner needs to be known to properly "rotate" partial derivatives.
+ */
+BLI_INLINE void BKE_multires_construct_tangent_matrix(
+ float tangent_matrix[3][3],
+ const float dPdu[3],
+ const float dPdv[3],
+ const int corner);
+
#endif /* __BKE_MULTIRES_H__ */
+
+#include "intern/multires_inline.h"
diff --git a/source/blender/blenkernel/intern/multires_inline.h b/source/blender/blenkernel/intern/multires_inline.h
new file mode 100644
index 00000000000..fe01fb6e221
--- /dev/null
+++ b/source/blender/blenkernel/intern/multires_inline.h
@@ -0,0 +1,68 @@
+/*
+ * ***** 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.
+ *
+ * The Original Code is Copyright (C) 2018 by Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Sergey Sharybin.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/multires_inline.h
+ * \ingroup bke
+ */
+
+#ifndef __BKE_MULTIRES_INLINE_H__
+#define __BKE_MULTIRES_INLINE_H__
+
+#include "BKE_multires.h"
+#include "BLI_math_vector.h"
+
+BLI_INLINE void BKE_multires_construct_tangent_matrix(
+ float tangent_matrix[3][3],
+ const float dPdu[3],
+ const float dPdv[3],
+ const int corner)
+{
+ if (corner == 0) {
+ copy_v3_v3(tangent_matrix[0], dPdv);
+ copy_v3_v3(tangent_matrix[1], dPdu);
+ mul_v3_fl(tangent_matrix[0], -1.0f);
+ mul_v3_fl(tangent_matrix[1], -1.0f);
+ }
+ else if (corner == 1) {
+ copy_v3_v3(tangent_matrix[0], dPdu);
+ copy_v3_v3(tangent_matrix[1], dPdv);
+ mul_v3_fl(tangent_matrix[1], -1.0f);
+ }
+ else if (corner == 2) {
+ copy_v3_v3(tangent_matrix[0], dPdv);
+ copy_v3_v3(tangent_matrix[1], dPdu);
+ }
+ else if (corner == 3) {
+ copy_v3_v3(tangent_matrix[0], dPdu);
+ copy_v3_v3(tangent_matrix[1], dPdv);
+ mul_v3_fl(tangent_matrix[0], -1.0f);
+ }
+ cross_v3_v3v3(tangent_matrix[2], dPdu, dPdv);
+ normalize_v3(tangent_matrix[0]);
+ normalize_v3(tangent_matrix[1]);
+ normalize_v3(tangent_matrix[2]);
+}
+
+#endif /* __BKE_MULTIRES_INLINE_H__ */
diff --git a/source/blender/blenkernel/intern/multires_reshape.c b/source/blender/blenkernel/intern/multires_reshape.c
index d99e8486738..22605eb510a 100644
--- a/source/blender/blenkernel/intern/multires_reshape.c
+++ b/source/blender/blenkernel/intern/multires_reshape.c
@@ -86,37 +86,6 @@ BLI_INLINE int rotate_quad_to_corner(const float u, const float v,
return corner;
}
-BLI_INLINE void construct_tangent_matrix(float tangent_matrix[3][3],
- const float dPdu[3],
- const float dPdv[3],
- const int corner)
-{
- if (corner == 0) {
- copy_v3_v3(tangent_matrix[0], dPdv);
- copy_v3_v3(tangent_matrix[1], dPdu);
- mul_v3_fl(tangent_matrix[0], -1.0f);
- mul_v3_fl(tangent_matrix[1], -1.0f);
- }
- else if (corner == 1) {
- copy_v3_v3(tangent_matrix[0], dPdu);
- copy_v3_v3(tangent_matrix[1], dPdv);
- mul_v3_fl(tangent_matrix[1], -1.0f);
- }
- else if (corner == 2) {
- copy_v3_v3(tangent_matrix[0], dPdv);
- copy_v3_v3(tangent_matrix[1], dPdu);
- }
- else if (corner == 3) {
- copy_v3_v3(tangent_matrix[0], dPdu);
- copy_v3_v3(tangent_matrix[1], dPdv);
- mul_v3_fl(tangent_matrix[0], -1.0f);
- }
- cross_v3_v3v3(tangent_matrix[2], dPdu, dPdv);
- normalize_v3(tangent_matrix[0]);
- normalize_v3(tangent_matrix[1]);
- normalize_v3(tangent_matrix[2]);
-}
-
static void multires_reshape_init_mmd(
MultiresModifierData *reshape_mmd,
const MultiresModifierData *mmd)
@@ -364,7 +333,8 @@ static void multires_reshape_vertex_from_final_data(
float D[3];
sub_v3_v3v3(D, final_P, P);
float tangent_matrix[3][3];
- construct_tangent_matrix(tangent_matrix, dPdu, dPdv, grid_corner);
+ BKE_multires_construct_tangent_matrix(
+ tangent_matrix, dPdu, dPdv, grid_corner);
float inv_tangent_matrix[3][3];
invert_m3_m3(inv_tangent_matrix, tangent_matrix);
float tangent_D[3];
diff --git a/source/blender/blenkernel/intern/subdiv_displacement_multires.c b/source/blender/blenkernel/intern/subdiv_displacement_multires.c
index aea02c5f9c9..bcb96ce8a66 100644
--- a/source/blender/blenkernel/intern/subdiv_displacement_multires.c
+++ b/source/blender/blenkernel/intern/subdiv_displacement_multires.c
@@ -38,6 +38,7 @@
#include "BLI_math_vector.h"
#include "BKE_customdata.h"
+#include "BKE_multires.h"
#include "MEM_guardedalloc.h"
@@ -156,38 +157,6 @@ static const MDisps *displacement_get_prev_grid(
return &data->mdisps[poly->loopstart + prev_corner];
}
-/* NOTE: Derivatives are in ptex face space. */
-BLI_INLINE void construct_tangent_matrix(float tangent_matrix[3][3],
- const float dPdu[3],
- const float dPdv[3],
- const int corner)
-{
- if (corner == 0) {
- copy_v3_v3(tangent_matrix[0], dPdv);
- copy_v3_v3(tangent_matrix[1], dPdu);
- mul_v3_fl(tangent_matrix[0], -1.0f);
- mul_v3_fl(tangent_matrix[1], -1.0f);
- }
- else if (corner == 1) {
- copy_v3_v3(tangent_matrix[0], dPdu);
- copy_v3_v3(tangent_matrix[1], dPdv);
- mul_v3_fl(tangent_matrix[1], -1.0f);
- }
- else if (corner == 2) {
- copy_v3_v3(tangent_matrix[0], dPdv);
- copy_v3_v3(tangent_matrix[1], dPdu);
- }
- else if (corner == 3) {
- copy_v3_v3(tangent_matrix[0], dPdu);
- copy_v3_v3(tangent_matrix[1], dPdv);
- mul_v3_fl(tangent_matrix[0], -1.0f);
- }
- cross_v3_v3v3(tangent_matrix[2], dPdu, dPdv);
- normalize_v3(tangent_matrix[0]);
- normalize_v3(tangent_matrix[1]);
- normalize_v3(tangent_matrix[2]);
-}
-
BLI_INLINE eAverageWith read_displacement_grid(
const MDisps *displacement_grid,
const int grid_size,
@@ -331,7 +300,7 @@ static void eval_displacement(SubdivDisplacement *displacement,
tangent_D);
/* Convert it to the object space. */
float tangent_matrix[3][3];
- construct_tangent_matrix(tangent_matrix, dPdu, dPdv, corner);
+ BKE_multires_construct_tangent_matrix(tangent_matrix, dPdu, dPdv, corner);
mul_v3_m3v3(r_D, tangent_matrix, tangent_D);
}