1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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/>.
20 #include "nel/misc/vector.h"
21 #include "nel/misc/singleton.h"
22 #include "nel/misc/smart_ptr.h"
23 #include "nel/misc/vector_2f.h"
24 #include "nel/misc/vector_h.h"
26 #include "nel/3d/material.h"
27 #include "nel/3d/vertex_buffer.h"
28 #include "nel/3d/shadow_poly_receiver.h"
30 #include "custom_matrix.h"
42 class CShadowPolyReceiver
;
48 const uint DECAL_NUM_PRIORITIES
= 8;
50 // Helper class to display a decal on a poly receiver
51 // Default decal is a unit rectangle (0, 0) - (1, 1)
52 // TODO nico : put this in NL3D when working ? ...
53 class CDecal
: public NLMISC::CRefCount
56 typedef NLMISC::CRefPtr
<CDecal
> TRefPtr
;
57 typedef NLMISC::CSmartPtr
<CDecal
> TSmartPtr
;
60 // Set a texture from its filename. It name match a global texture in the view renderer, it will be used ,first
61 void setTexture(const std::string
&fileName
, bool clampU
= true, bool clampV
= true, bool filtered
= true);
62 NL3D::ITexture
*getTexture() { return _Material
.getTexture(0); }
63 const std::string
&getTextureFileName() const;
64 void setTextureMatrix(const NLMISC::CMatrix
&matrix
) { _TextureMatrix
= matrix
; }
65 void setDiffuse(NLMISC::CRGBA diffuse
);
66 NLMISC::CRGBA
getDiffuse() const;
67 void setEmissive(NLMISC::CRGBA emissive
);
69 void setWorldMatrix(const NLMISC::CMatrix
&matrix
);
70 void setWorldMatrixForArrow(const NLMISC::CVector2f
&start
, const NLMISC::CVector2f
&end
, float halfWidth
);
71 void setWorldMatrixForSpot(const NLMISC::CVector2f
&pos
, float radius
, float angleInRadians
= 0.f
);
72 // should be called if the decal should be made visible this frame
73 void addToRenderList(uint priority
= 0);
74 // test if a point intersect with this decal
75 bool contains(const NLMISC::CVector2f
&pos
) const;
76 // set a custom uv matrix (from world to uvs)
77 void setCustomUVMatrix(bool on
, const NLMISC::CMatrix
&matrix
= NLMISC::CMatrix::Identity
);
79 void setClipDownFacing(bool clipDownFacing
);
80 bool getClipDownFacing() const { return _ClipDownFacing
; }
82 void setBottomBlend(float zMin
, float zMax
);
83 void setTopBlend(float zMin
, float zMax
);
85 mutable NL3D::CMaterial _Material
;
86 NLMISC::CMatrix _WorldMatrix
;
87 float _WorldMatrixFlat
[16];
88 NLMISC::CVector _ClipCorners
[8];
89 NLMISC::CMatrix _InvertedWorldMatrix
;
90 NLMISC::CMatrix _TextureMatrix
;
91 CCustomMatrix _CustomUVMatrix
;
92 float _WorldToUVMatrix
[4][4];
93 NL3D::CShadowMap
*_ShadowMap
;
94 std::vector
<NL3D::CShadowPolyReceiver::CRGBAVertex
> _TriCache
;
95 NLMISC::CVector _LastCamPos
;
96 static NLMISC::CAABBox _ClipBBox
;
97 static NL3D::CVertexBuffer _VB
;
98 static bool _VBInitialized
;
99 NLMISC::CRGBA _Diffuse
;
100 NLMISC::CRGBA _Emissive
;
101 NLMISC::CVector _RefPosition
; // position for model matrix, computed near camera pos to avoid z-fight
102 // (big translation in the final MVP matrix leads to z precision problems)
104 bool _ClipDownFacing
;
106 float _BottomBlendZMin
;
107 float _BottomBlendZMax
;
111 friend class CDecalRenderList
;
112 void render(NL3D::UDriver
&drv
,
113 NL3D::CShadowPolyReceiver
&receiver
,
114 const std::vector
<NLMISC::CPlane
> &worldPyramid
,
115 const std::vector
<NLMISC::CVector
> &pyramidCorners
,
116 bool useVertexProgram
118 void renderTriCache(NL3D::IDriver
&drv
, NL3D::CShadowPolyReceiver
&receiver
, bool useVertexProgram
);
119 bool clipFront(const NLMISC::CPlane
&p
) const;
120 void setupMaterialColor();
123 // list of all decals to be rendered after the landscape
124 class CDecalRenderList
: public NLMISC::CSingleton
<CDecalRenderList
>
127 CDecalRenderList() : _Empty(true) {}
128 void renderAllDecals();
129 void clearRenderList();
132 std::vector
<CDecal::TRefPtr
> _RenderList
[DECAL_NUM_PRIORITIES
];
134 std::vector
<NLMISC::CPlane
> _WorldCamPyramid
;
135 std::vector
<NLMISC::CVector
> _WorldCamPyramidCorners
;
136 // scale / bias for color attenuation