1 /* Copyright (C) 2012 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
22 #include "third_party/mikktspace/mikktspace.h"
29 MikkTSpace(const CModelDefPtr
& m
, std::vector
<float>& v
, bool gpuSkinning
);
35 SMikkTSpaceInterface m_Interface
;
36 SMikkTSpaceContext m_Context
;
38 const CModelDefPtr
& m_Model
;
40 std::vector
<float>& m_NewVertices
;
44 // Returns the number of faces (triangles/quads) on the mesh to be processed.
45 static int getNumFaces(const SMikkTSpaceContext
*pContext
);
48 // Returns the number of vertices on face number iFace
49 // iFace is a number in the range {0, 1, ..., getNumFaces()-1}
50 static int getNumVerticesOfFace(const SMikkTSpaceContext
*pContext
, const int iFace
);
53 // returns the position/normal/texcoord of the referenced face of vertex number iVert.
54 // iVert is in the range {0,1,2} for triangles and {0,1,2,3} for quads.
55 static void getPosition(const SMikkTSpaceContext
*pContext
,
56 float fvPosOut
[], const int iFace
, const int iVert
);
58 static void getNormal(const SMikkTSpaceContext
*pContext
,
59 float fvNormOut
[], const int iFace
, const int iVert
);
61 static void getTexCoord(const SMikkTSpaceContext
*pContext
,
62 float fvTexcOut
[], const int iFace
, const int iVert
);
65 // This function is used to return tangent space results to the application.
66 // fvTangent and fvBiTangent are unit length vectors and fMagS and fMagT are their
67 // true magnitudes which can be used for relief mapping effects.
68 // fvBiTangent is the "real" bitangent and thus may not be perpendicular to fvTangent.
69 // However, both are perpendicular to the vertex normal.
70 // For normal maps it is sufficient to use the following simplified version of the bitangent which is generated at pixel/vertex level.
71 // fSign = bIsOrientationPreserving ? 1.0f : (-1.0f);
72 // bitangent = fSign * cross(vN, tangent);
73 static void setTSpace(const SMikkTSpaceContext
* pContext
, const float fvTangent
[],
74 const float fvBiTangent
[], const float fMagS
, const float fMagT
,
75 const tbool bIsOrientationPreserving
, const int iFace
, const int iVert
);
81 #endif // INCLUDED_MIKKWRAP