Subdiv: Cleanup, de-duplicate tangent matrix calculation
This commit is contained in:
@@ -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"
|
||||
|
||||
68
source/blender/blenkernel/intern/multires_inline.h
Normal file
68
source/blender/blenkernel/intern/multires_inline.h
Normal file
@@ -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__ */
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user