1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program 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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "nel/3d/shadow_skin.h"
20 #include "nel/3d/skeleton_model.h"
21 #include "nel/3d/ray_mesh.h"
22 #include "nel/misc/fast_mem.h"
23 #include "nel/misc/vector_2f.h"
25 using namespace NLMISC
;
36 // ***************************************************************************
37 // The number of byte to process per block
38 const uint NL_BlockByteL1
= 4096;
40 // Number of vertices per block to process For ShadowMap generation
41 uint
CShadowSkin::NumCacheVertexShadow
= NL_BlockByteL1
/ sizeof(CShadowVertex
);
44 // ***************************************************************************
45 void CShadowSkin::applySkin(CVector
*dst
, std::vector
<CMatrix3x4
> &boneMat3x4
)
49 uint numVerts
= (uint
)Vertices
.size();
50 CShadowVertex
*src
= &Vertices
[0];
55 // number of vertices to process for this block.
56 uint nBlockInf
= min(NumCacheVertexShadow
, numVerts
);
60 // cache the data in L1 cache.
61 CFastMem::precache(src
, nBlockInf
* sizeof(CShadowVertex
));
63 // for all InfluencedVertices only.
64 for(;nBlockInf
>0;nBlockInf
--, src
++, dst
++)
66 boneMat3x4
[ src
->MatrixId
].mulSetPoint( src
->Vertex
, *dst
);
72 // ***************************************************************************
73 bool CShadowSkin::getRayIntersection(const CMatrix
&toRaySpace
, CSkeletonModel
&skeleton
,
74 const std::vector
<uint32
> &matrixInfluences
, float &dist2D
, float &distZ
, bool computeDist2D
)
76 // *** render the shadow skin into a temp RAM buffer
77 // enlarge temp buffer
78 static std::vector
<CVector
> skinInRaySpace
;
79 if(Vertices
.size()>skinInRaySpace
.size())
80 skinInRaySpace
.resize(Vertices
.size());
83 static vector
<CMatrix3x4
> boneMat3x4
;
84 computeBoneMatrixes3x4PreMul(boneMat3x4
, toRaySpace
, matrixInfluences
, &skeleton
);
87 applySkin(&skinInRaySpace
[0], boneMat3x4
);
89 // *** return the distance to the ray intersection
90 return CRayMesh::getRayIntersection(skinInRaySpace
, Triangles
, dist2D
, distZ
, computeDist2D
);