Skip to content

Commit

Permalink
highlight DLB files
Browse files Browse the repository at this point in the history
  • Loading branch information
HanetakaChou committed Nov 4, 2024
1 parent 45bff1c commit 64a55e0
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## DLB (Dual Quaternion Linear Blending)

- code/DLB.h: the c++ code of mapping the rigid transformation to the unit dual quaternion
- shaders/DLB.hlsli: the hlsl code of DLB (Dual quaternion Linear Blending) and mapping the unit dual quaternion to the rigid transformation
- [DLB.h](https://github.com/HanetakaChou/Dual-Quaternion-Linear-Blending/blob/master/code/DLB.h) the c++ code of mapping the rigid transformation to the unit dual quaternion
- [DLB.hlsli](https://github.com/HanetakaChou/Dual-Quaternion-Linear-Blending/blob/master/shaders/DLB.hlsli) the hlsl code of DLB (Dual quaternion Linear Blending) and mapping the unit dual quaternion to the rigid transformation
- [DLB.glsli](https://github.com/HanetakaChou/Dual-Quaternion-Linear-Blending/blob/master/shaders/DLB.hlsli) the glsl code of DLB (Dual quaternion Linear Blending) and mapping the unit dual quaternion to the rigid transformation

[![build windows](https://github.com/HanetakaChou/Dual-Quaternion-Linear-Blending/actions/workflows/build-windows.yml/badge.svg)](https://github.com/HanetakaChou/Dual-Quaternion-Linear-Blending/actions/workflows/build-windows.yml)
![](README.png)
6 changes: 3 additions & 3 deletions code/DLB.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifndef _DLB_H_
#define _DLB_H_ 1

//
// Copyright (C) YuqiaoZhang(HanetakaChou)
//
Expand All @@ -18,6 +15,9 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#ifndef _DLB_H_
#define _DLB_H_ 1

//
// Mapping the rigid transformation to the unit dual quaternion.
//
Expand Down
79 changes: 79 additions & 0 deletions shaders/DLB.glsli
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// Copyright (C) YuqiaoZhang(HanetakaChou)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#ifndef _DLB_GLSLI_
#define _DLB_GLSLI_ 1

//
// DLB (Dual quaternion Linear Blending)
//
mat2x4 dual_quaternion_linear_blending(in mat2x4 q_indices_x, in mat2x4 q_indices_y, in mat2x4 q_indices_z, in mat2x4 q_indices_w, in vec4 weights)
{
#if 1
// NOTE:
// The original DLB does NOT check the sign of the inner product of the unit quaternion q_x_0 and q_y_0(q_z_0 q_w_0).
// However, since the unit quaternion q and -q represent the same rotation transform, we may get the result of which the real part is zero.
mat2x4 b = weights.x * q_indices_x + weights.y * sign(dot(q_indices_x[0], q_indices_y[0])) * q_indices_y + weights.z * sign(dot(q_indices_x[0], q_indices_z[0])) * q_indices_z + weights.w * sign(dot(q_indices_x[0], q_indices_w[0])) * q_indices_w;
#else
mat2x4 b = weights.x * q_indices_x + weights.y * q_indices_y + weights.z * q_indices_z + weights.w * q_indices_w;
#endif

// "4 Implementation Notes" of [Ladislav Kavan, Steven Collins, Jiri Zara, Carol O'Sullivan. "Geometric Skinning with Approximate Dual Quaternion Blending." SIGGRAPH 2008.](http://www.cs.utah.edu/~ladislav/kavan08geometric/kavan08geometric.html)
// We do NOT need to calculate the exact dual part "\boldsymbol{q_\epsilon}", since the scalar part of the "\boldsymbol{q_\epsilon} {\boldsymbol{q_0}}^*" is ignored when we calculate the "\frac{1}{2}\overrightarrow{t}".
return (b / length(b[0]));
}

//
// Mapping the rigid transformation to the unit dual quaternion.
//
// [in] q: The unit dual quaternion of which the q[0] is the real part and the q[1] is the dual part.
//
// [out] r: The unit quaternion which represents the rotation transform of the rigid transformation.
//
// [out] t: The 3D vector which represnets the translation transform of the rigid transformation.
//
void unit_dual_quaternion_to_rigid_transform(in mat2x4 q, out vec4 r, out vec3 t)
{
vec4 q_0 = q[0];
vec4 q_e = q[1];

// \boldsymbol{r_0} = \boldsymbol{q_0}
r = q_0;

// \overrightarrow{t} = 2 (- s_ϵ \overrightarrow{v_0} + s_0 \overrightarrow{v_ϵ} - \overrightarrow{v_ϵ} \times \overrightarrow{v_0}
// t = 2.0 * (- q_e.w * q_0.xyz + q_0.w * q_e.xyz - cross(q_e.xyz, q_0.xyz));
t = 2.0 * (q_0.w * q_e.xyz - q_e.w * q_0.xyz + cross(q_0.xyz, q_e.xyz));
}

//
// Mapping the unit quaternion to the rotation transformation.
//
// [in] q: The unit quaternion.
//
// [out] p: The 3D vector which represents the position before the rotation transform.
//
// [return] : The 3D vector which represents the position after the rotation transform.
//
vec3 unit_quaternion_to_rotation_transform(in vec4 r, in vec3 p)
{
// "Fig. 6.7" and "Fig. 6.8" of [Quaternions for Computer Graphics](https://link.springer.com/book/10.1007/978-1-4471-7509-4)
// "Lemma 4" of [Ladislav Kavan, Steven Collins, Jiri Zara, Carol O'Sullivan. "Geometric Skinning with Approximate Dual Quaternion Blending." SIGGRAPH 2008.](http://www.cs.utah.edu/~ladislav/kavan08geometric/kavan08geometric.html)

return (p + 2.0 * cross(r.xyz, cross(r.xyz, p) + r.w * p));
}

#endif
6 changes: 3 additions & 3 deletions shaders/DLB.hlsli
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifndef _DLB_HLSLI_
#define _DLB_HLSLI_ 1

//
// Copyright (C) YuqiaoZhang(HanetakaChou)
//
Expand All @@ -18,6 +15,9 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#ifndef _DLB_HLSLI_
#define _DLB_HLSLI_ 1

//
// DLB (Dual quaternion Linear Blending)
//
Expand Down

0 comments on commit 64a55e0

Please sign in to comment.