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/>.
18 #include "water_env_map_rdr.h"
22 #include "continent_manager.h"
23 #include "light_cycle_manager.h"
25 #include "nel/3d/viewport.h"
26 #include "nel/3d/u_driver.h"
27 #include "nel/misc/matrix.h"
28 #include "nel/misc/vectord.h"
35 using namespace NLMISC
;
38 extern CContinentManager ContinentMngr
;
39 extern CFogState RootFogState
;
41 H_AUTO_DECL(RZ_WaterEnvMapRDR
)
43 static void renderEnvMapScene(UScene
*scene
, UCamera
&cam
, const CMatrix
&camMatrix
, float znear
, float zfar
)
45 H_AUTO_USE(RZ_WaterEnvMapRDR
)
49 UCamera oldCam
= scene
->getCam();
51 cam
.setTransformMode(UTransformable::DirectMatrix
);
52 cam
.setFrustum(-znear
, znear
, -znear
, znear
, znear
, zfar
);
53 cam
.setMatrix(camMatrix
);
54 CViewport old
= scene
->getViewport();
55 scene
->setViewport(CViewport());
56 scene
->beginPartRender();
57 scene
->renderPart((UScene::TRenderPart
) (UScene::RenderOpaque
| UScene::RenderTransparent
));
58 scene
->endPartRender();
59 scene
->setViewport(old
);
60 scene
->setCam(oldCam
);
64 void CWaterEnvMapRdr::doRender(const CMatrix
&camMatrix
, TGlobalAnimationTime time
, UDriver
&drv
)
66 H_AUTO_USE(RZ_WaterEnvMapRDR
)
68 if (time
!= _LastRenderStartTime
) // begin a new rendering of the cube
70 _DateForRender
= CurrDate
;
71 _AnimationDateForRender
= AnimationDate
;
72 _WeatherForRender
= CurrWeather
;
73 _FogColorForRender
= CurrFogColor
;
74 _LastRenderStartTime
= time
;
75 _CurrCanopyCamPos
= View
.currentViewPos();
79 Sky
->setup(_DateForRender
, _AnimationDateForRender
, _WeatherForRender
, _FogColorForRender
, CVector(0.5f
, 0.f
, -0.85f
).normed(), true);
82 if (Sky
->getScene()) Sky
->getScene()->animate(CurrTime
); // this will force the elapsed time to be set to so that fx won't be animated twice
85 drv
.setCullMode(drv
.getCullMode() == UDriver::CCW
? UDriver::CW
: UDriver::CCW
);
87 ContinentMngr
.getFogState(CanopyFog
, LightCycleManager
.getLightLevel(), LightCycleManager
.getLightDesc().DuskRatio
, LightCycleManager
.getState(), CVectorD(View
.viewPos()), RootFogState
);
88 RootFogState
.setupInDriver(drv
);
89 CMatrix mat
= camMatrix
;
90 drv
.setDepthRange(0.f
, 0.5f
);
91 mat
.setPos(_CurrCanopyCamPos
);
92 renderEnvMapScene(SceneRoot
, WaterEnvMapCanopyCam
, mat
, SceneRootCameraZNear
, SceneRootCameraZFar
);
93 Driver
->enableFog(false);
97 drv
.setDepthRange(0.5f
, 1.f
); // force sky scene to appear behind canopy scene
98 mat
.setPos(CVector(0.f
, 0.f
, Sky
->getWaterEnvMapCameraHeight()));
99 renderEnvMapScene(Sky
->getScene(), WaterEnvMapSkyCam
, mat
, 0.1f
, 1000.f
);
101 drv
.setCullMode(drv
.getCullMode() == UDriver::CCW
? UDriver::CW
: UDriver::CCW
);
102 drv
.setDepthRange(0.f
, 1.f
);