Browse Source

Shaders: add Weights and JointIds attribute types.

Note that the order is *reversed* compared to the originally reserved
attribute IDs. This is because the "joint <id> has <weight>" order
feels more natural and consistent than "<weight> is assigned to joint
<id>".

Co-authored-by: Vladimír Vondruš <mosra@centrum.cz>
pull/499/head
Squareys 4 years ago committed by Vladimír Vondruš
parent
commit
7f94a6f914
  1. 89
      src/Magnum/Shaders/GenericGL.h
  2. 9
      src/Magnum/Shaders/Test/GenericGL_Test.cpp
  3. 4
      src/Magnum/Shaders/generic.glsl

89
src/Magnum/Shaders/GenericGL.h

@ -125,13 +125,13 @@ both bitangents and object ID for instancing, \n
<tr>
<td>6</td>
<td colspan="3">
* *Reserved* --- vertex weights
@ref JointIds
</td>
</tr>
<tr>
<td>7</td>
<td colspan="3">
* *Reserved* --- bone indices
@ref Weights
</td>
</tr>
<tr>
@ -149,13 +149,13 @@ both bitangents and object ID for instancing, \n
<tr>
<td>10</td>
<td colspan="2">
* *Reserved* --- 2nd vertex weights
@ref SecondaryJointIds
</td>
</tr>
<tr>
<td>11</td>
<td colspan="2">
* *Reserved* --- 2nd bone indices
@ref SecondaryWeights
</td>
</tr>
<tr>
@ -382,7 +382,37 @@ template<UnsignedInt dimensions> struct GenericGL {
*/
typedef GL::Attribute<5, Vector3> Normal;
/* 6, 7 reserved for vertex weights / bone IDs */
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Skin joint IDs
* @m_since_latest
*
* @ref Magnum::Vector4ui "Vector4ui", four indices of joints that affect
* the vertex with weights defined in @ref Weights. Corresponds to up to
* first four components of @ref Trade::MeshAttribute::JointIds.
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4}
* @requires_gles30 Skinning requires integer support in shaders, which is
* not available in OpenGL ES 2.0.
* @requires_webgl20 Skinning requires integer support in shaders, which is
* not available in WebGL 1.0.
*/
typedef GL::Attribute<6, Vector4ui> JointIds;
/**
* @brief Skin weights
* @m_since_latest
*
* @ref Magnum::Vector4 "Vector4", four weights of influence from joints
* referenced by @ref JointIds. Corresponds to up to four first components
* of @ref Trade::MeshAttribute::Weights.
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4}
* @requires_gles30 Skinning requires integer support in shaders, which is
* not available in OpenGL ES 2.0.
* @requires_webgl20 Skinning requires integer support in shaders, which is
* not available in WebGL 1.0.
*/
typedef GL::Attribute<7, Vector4> Weights;
#endif
/**
* @brief (Instanced) transformation matrix
@ -399,7 +429,42 @@ template<UnsignedInt dimensions> struct GenericGL {
*/
typedef GL::Attribute<8, T> TransformationMatrix;
/* 9, 10, 11 occupied by TransformationMatrix */
/* 9, 10, 11 occupied by TransformationMatrix; 10 and 11 shared with
SecondaryJointIds / SecondaryWeights */
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Secondary skin joint IDs
* @m_since_latest
*
* @ref Magnum::Vector4ui "Vector4ui", four indices of joints that affect
* the vertex with weights defined in @ref SecondaryWeights, in addition to
* @ref JointIds. Corresponds to up to four additional components of
* @ref Trade::MeshAttribute::JointIds.
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4}
* @requires_gles30 Skinning requires integer support in shaders, which is
* not available in OpenGL ES 2.0.
* @requires_webgl20 Skinning requires integer support in shaders, which is
* not available in WebGL 1.0.
*/
typedef GL::Attribute<10, Vector4ui> SecondaryJointIds;
/**
* @brief Secondary skin weights
* @m_since_latest
*
* @ref Magnum::Vector4 "Vector4", four weights of influence from joints
* referenced by @ref SecondaryJointIds, in addition to @ref Weights.
* Corresponds to up to four additional components of
* @ref Trade::MeshAttribute::Weights.
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4}
* @requires_gles30 Skinning requires integer support in shaders, which is
* not available in OpenGL ES 2.0.
* @requires_webgl20 Skinning requires integer support in shaders, which is
* not available in WebGL 1.0.
*/
typedef GL::Attribute<11, Vector4> SecondaryWeights;
#endif
/**
* @brief (Instanced) normal matrix
@ -479,6 +544,11 @@ struct BaseGenericGL {
#ifndef MAGNUM_TARGET_GLES2
typedef GL::Attribute<4, UnsignedInt> ObjectId;
#endif
typedef GL::Attribute<6, Vector4ui> JointIds;
typedef GL::Attribute<7, Vector4> Weights;
typedef GL::Attribute<10, Vector4ui> SecondaryJointIds;
typedef GL::Attribute<11, Vector4> SecondaryWeights;
typedef GL::Attribute<15, Vector2> TextureOffset;
#ifndef MAGNUM_TARGET_GLES2
@ -491,7 +561,8 @@ template<> struct GenericGL<2>: BaseGenericGL {
/* 1, 2 used by TextureCoordinates and Color */
typedef GL::Attribute<8, Matrix3> TransformationMatrix;
/* 9, 10 occupied by TransformationMatrix */
/* 9, 10 occupied by TransformationMatrix; 10 and 11 shared with
SecondaryJointIds and SecondaryWeights */
/* 15 used by TextureOffset */
};
@ -502,10 +573,10 @@ template<> struct GenericGL<3>: BaseGenericGL {
typedef GL::Attribute<3, Vector4> Tangent4;
typedef GL::Attribute<4, Vector3> Bitangent; /* also ObjectId */
typedef GL::Attribute<5, Vector3> Normal;
/* 6, 7 reserved for vertex weights / bone IDs */
typedef GL::Attribute<8, Matrix4> TransformationMatrix;
/* 9, 10, 11 occupied by TransformationMatrix */
/* 9, 10, 11 occupied by TransformationMatrix; 10 and 11 shared with
SecondaryJointIds and SecondaryWeights */
typedef GL::Attribute<12, Matrix3x3> NormalMatrix;
/* 13, 14 occupied by NormalMatrix */
/* 15 used by TextureOffset */

9
src/Magnum/Shaders/Test/GenericGL_Test.cpp

@ -74,10 +74,17 @@ void GenericGL_Test::glslMatch() {
CORRADE_COMPARE(TANGENT_ATTRIBUTE_LOCATION, GenericGL3D::Tangent4::Location);
CORRADE_COMPARE(BITANGENT_ATTRIBUTE_LOCATION, GenericGL3D::Bitangent::Location);
CORRADE_COMPARE(NORMAL_ATTRIBUTE_LOCATION, GenericGL3D::Normal::Location);
#ifndef MAGNUM_TARGET_GLES2
CORRADE_COMPARE(JOINTIDS_ATTRIBUTE_LOCATION, GenericGL3D::JointIds::Location);
CORRADE_COMPARE(WEIGHTS_ATTRIBUTE_LOCATION, GenericGL3D::Weights::Location);
#endif
CORRADE_COMPARE(TRANSFORMATION_MATRIX_ATTRIBUTE_LOCATION, GenericGL2D::TransformationMatrix::Location);
CORRADE_COMPARE(TRANSFORMATION_MATRIX_ATTRIBUTE_LOCATION, GenericGL3D::TransformationMatrix::Location);
#ifndef MAGNUM_TARGET_GLES2
CORRADE_COMPARE(SECONDARY_JOINTIDS_ATTRIBUTE_LOCATION, GenericGL3D::SecondaryJointIds::Location);
CORRADE_COMPARE(SECONDARY_WEIGHTS_ATTRIBUTE_LOCATION, GenericGL3D::SecondaryWeights::Location);
#endif
CORRADE_COMPARE(NORMAL_MATRIX_ATTRIBUTE_LOCATION, GenericGL3D::NormalMatrix::Location);
CORRADE_COMPARE(TEXTURE_OFFSET_ATTRIBUTE_LOCATION, GenericGL2D::TextureOffset::Location);

4
src/Magnum/Shaders/generic.glsl

@ -32,8 +32,12 @@
#define BITANGENT_ATTRIBUTE_LOCATION 4 /* also ObjectId */
#define OBJECT_ID_ATTRIBUTE_LOCATION 4 /* also Bitangent */
#define NORMAL_ATTRIBUTE_LOCATION 5
#define JOINTIDS_ATTRIBUTE_LOCATION 6
#define WEIGHTS_ATTRIBUTE_LOCATION 7
#define TRANSFORMATION_MATRIX_ATTRIBUTE_LOCATION 8
#define SECONDARY_JOINTIDS_ATTRIBUTE_LOCATION 10 /* also TransformationMatrix[2] */
#define SECONDARY_WEIGHTS_ATTRIBUTE_LOCATION 11 /* also TransformationMatrix[3] */
#define NORMAL_MATRIX_ATTRIBUTE_LOCATION 12
#define TEXTURE_OFFSET_ATTRIBUTE_LOCATION 15 /* + layer in the 3rd component */

Loading…
Cancel
Save