1 /* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_MIKKWRAP
19 #define INCLUDED_MIKKWRAP
21 #include "graphics/MeshManager.h"
22 #include "graphics/ModelDef.h"
23 #include "third_party/mikktspace/mikktspace.h"
32 MikkTSpace(const CModelDefPtr
& m
, std::vector
<float>& v
, bool gpuSkinning
);
38 SMikkTSpaceInterface m_Interface
;
39 SMikkTSpaceContext m_Context
;
41 const CModelDefPtr
& m_Model
;
43 std::vector
<float>& m_NewVertices
;
48 * @param[in] pContext - Pointer to the MikkTSpace context.
49 * @returns - the number of faces (triangles/quads) on the mesh to be processed.
51 static int GetNumFaces(const SMikkTSpaceContext
* pContext
);
54 * @param[in] pContext - Pointer to the MikkTSpace context.
55 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
56 * @returns - the number of faces (triangles/quads) on the mesh to be processed.
58 static int GetNumVerticesOfFace(const SMikkTSpaceContext
* pContext
, const int iFace
);
61 * @param[in] pContext - Pointer to the MikkTSpace context.
62 * @returns - The MikkTSpace.
64 static MikkTSpace
* GetUserDataFromContext(const SMikkTSpaceContext
* pContext
);
67 * @param[in] pContext - Pointer to the MikkTSpace context.
68 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
69 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
70 * @returns - The MikkTSpace.
72 static SModelVertex
GetVertex(const SMikkTSpaceContext
* pContext
, const int iFace
, const int iVert
);
75 * @param[in] pContext - Pointer to the MikkTSpace context.
76 * @param[out] fvPosOut - The array containing the face.
77 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
78 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
80 static void GetPosition(const SMikkTSpaceContext
* pContext
,
81 float* fvPosOut
, const int iFace
, const int iVert
);
84 * @param[in] pContext - Pointer to the MikkTSpace context.
85 * @param[out] fvNormOut iVert - The array containing the normal.
86 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
87 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
89 static void GetNormal(const SMikkTSpaceContext
* pContext
,
90 float* fvNormOut
, const int iFace
, const int iVert
);
93 * @param[in] pContext - Pointer to the MikkTSpace context.
94 * @param[out] fvTexcOut iVert - Array containing the UV.
95 * @param[in] iFace - Number in the range { 0, 1, ..., getNumFaces() - 1 }.
96 * @param[in] iVert - Number in the range { 0, 1, 2 } for triangles and { 0, 1, 2, 3 } for quads.
98 static void GetTexCoord(const SMikkTSpaceContext
* pContext
,
99 float* fvTexcOut
, const int iFace
, const int iVert
);
102 * @brief This function is used to return tangent space results to the application.
103 * For normal maps it is sufficient to use the following simplified version of the bitangent which is generated at pixel/vertex level.
104 * fSign = bIsOrientationPreserving ? 1.0f : (-1.0f);
105 * bitangent = fSign * cross(vN, tangent);
106 * @param[in] pContext - Pointer to the MikkTSpace context.
107 * @param[in] fvTangent - fvTangent - The tangent vector.
108 * @param[in] fvBiTangent - The "real" bitangent vector. Not be perpendicular to fvTangent. However, both are perpendicular to the vertex normal.
109 * @param[in] fMagS - magniture of the fvTangent vector.
110 * @param[in] fMagT - magniture of the fvBiTangent vector.
111 * @param[in] bIsOrientationPreserving - Whether the orientation should be preserved.
112 * @param[in] iFace - Number in the range {0,1,2} for triangles and {0,1,2,3} for quads.
113 * @param[in] iVert - Array containing the position vector of the face.
115 static void SetTSpace(const SMikkTSpaceContext
* pContext
, const float* fvTangent
,
116 const float* UNUSED(fvBiTangent
), const float UNUSED(fMagS
), const float UNUSED(fMagT
),
117 const tbool bIsOrientationPreserving
, const int iFace
, const int iVert
);
122 #endif // INCLUDED_MIKKWRAP