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/>.
22 #include "dir_light_setup.h"
23 #include "georges_helper.h"
24 #include "nel/georges/u_form_elm.h"
27 //-----------------------------------------------
28 CDirLightSetup::CDirLightSetup() :
30 Diffuse(255, 255, 255),
32 Direction(1.f
, 0.f
, 0.f
)
36 //-----------------------------------------------
37 void CDirLightSetup::blend(const CDirLightSetup
&setup0
, const CDirLightSetup
&setup1
, float blendFactor
)
39 uint uiFactor
= (uint
) (256.f
* blendFactor
);
40 Ambiant
.blendFromui(setup0
.Ambiant
, setup1
.Ambiant
, uiFactor
);
41 Diffuse
.blendFromui(setup0
.Diffuse
, setup1
.Diffuse
, uiFactor
);
42 Specular
.blendFromui(setup0
.Specular
, setup1
.Specular
, uiFactor
);
43 Direction
= (blendFactor
* setup0
.Direction
+ (1.f
- blendFactor
) * setup1
.Direction
).normed();
46 //-----------------------------------------------
47 void CDirLightSetup::modulate(float level
)
49 uint uiLevel
= (uint
) (256.f
* level
);
50 Ambiant
.modulateFromui(Ambiant
, uiLevel
);
51 Diffuse
.modulateFromui(Diffuse
, uiLevel
);
52 Specular
.modulateFromui(Specular
, uiLevel
);
55 //-----------------------------------------------
56 bool CDirLightSetup::build(const NLGEORGES::UFormElm
&item
)
58 NLMISC::CRGBA amb
, dif
, spe
;
61 const NLGEORGES::UFormElm
*pElt
;
63 if (item
.getNodeByName (&pElt
, ".Direction") && pElt
)
65 if (!CGeorgesHelper::convert(dir
, *pElt
)) return false;
68 if (item
.getNodeByName (&pElt
, ".Ambiant") && pElt
)
70 if (!CGeorgesHelper::convert(amb
, *pElt
)) return false;
74 if (item
.getNodeByName (&pElt
, ".Diffuse") && pElt
)
76 if (!CGeorgesHelper::convert(dif
, *pElt
)) return false;
80 if (item
.getNodeByName (&pElt
, ".Specular") && pElt
)
82 if (!CGeorgesHelper::convert(spe
, *pElt
)) return false;