[1493] | 1 | #include <OgreLight.h>
|
---|
| 2 | #include "windows.h"
|
---|
| 3 | //#include <imdebug.h>
|
---|
| 4 | #include <OgreHardwarePixelBuffer.h>
|
---|
| 5 | #include <OgrePixelFormat.h>
|
---|
| 6 |
|
---|
| 7 | # define MAX(A,B) ((A)>(B)?(A):(B)) /* Definición macro de Max */
|
---|
| 8 | # define MIN(A,B) ((A)>(B)?(B):(A)) /* Definición macro de Min */
|
---|
| 9 |
|
---|
| 10 | class LightComposite
|
---|
| 11 | {
|
---|
| 12 | protected:
|
---|
| 13 | std::vector<Light*> mLightList;
|
---|
| 14 | bool mShadowMapOverlayEnabled;
|
---|
| 15 | Overlay* mShadowMapOverlay;
|
---|
| 16 | Overlay* mLightingInfo;
|
---|
| 17 | Light *mCurrentLight;
|
---|
| 18 | unsigned int idCurrentLight;
|
---|
| 19 | bool mShadowsEnabled;
|
---|
| 20 | SceneManager *mSceneMgr;
|
---|
| 21 | Real exposure;
|
---|
| 22 | Camera *mCamera;
|
---|
| 23 | ColourValue mDayLight;
|
---|
| 24 | ColourValue mNightLight;
|
---|
| 25 | ColourValue mFactorLight;
|
---|
| 26 | ColourValue mRangeLight;
|
---|
| 27 |
|
---|
| 28 | public:
|
---|
| 29 |
|
---|
| 30 | ColourValue getDayLight()
|
---|
| 31 | {
|
---|
| 32 | return mDayLight;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | ColourValue getNightLight()
|
---|
| 36 | {
|
---|
| 37 | return mNightLight;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | void init(SceneManager *sceneMgr, Camera *camera)
|
---|
| 41 | {
|
---|
| 42 | mShadowMapOverlay = OverlayManager::getSingleton().getByName("shadowMapMain");
|
---|
| 43 | mLightingInfo = OverlayManager::getSingleton().getByName("lightOptions");
|
---|
| 44 | mCurrentLight = 0;
|
---|
| 45 | mShadowMapOverlayEnabled = true;
|
---|
| 46 |
|
---|
| 47 | Ogre::String shadowsEnabled;
|
---|
| 48 | Ogre::ConfigFile config;
|
---|
| 49 | config.load("configScene.cfg");
|
---|
| 50 | Ogre::String sShadowsEnabled = config.getSetting("ShadowsEnabled");
|
---|
| 51 | mShadowsEnabled = Ogre::StringConverter::parseBool(sShadowsEnabled);
|
---|
| 52 |
|
---|
| 53 | idCurrentLight = 0;
|
---|
| 54 | exposure = 4.5;
|
---|
| 55 | mSceneMgr = sceneMgr;
|
---|
| 56 | if (mShadowsEnabled)
|
---|
| 57 | {
|
---|
| 58 | mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
|
---|
| 59 |
|
---|
| 60 | mSceneMgr->setShadowDirectionalLightExtrusionDistance(10000.0);
|
---|
| 61 | mSceneMgr->setShadowFarDistance(2000);
|
---|
| 62 | mSceneMgr->setShadowTextureFadeStart(0.8);
|
---|
| 63 | mSceneMgr->setShadowTextureFadeEnd(0.9);
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | {
|
---|
| 67 | Camera* pTextureCam = mSceneMgr->getCamera("Ogre/ShadowTextureCam0");
|
---|
| 68 | pTextureCam->setNearClipDistance(5.0);
|
---|
| 69 | pTextureCam->setFarClipDistance(12000);
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | mCamera = camera;
|
---|
| 73 | mFactorLight = (mDayLight - mNightLight) / 1000.0;
|
---|
| 74 | mCamera->getViewport()->setBackgroundColour(mSceneMgr->getAmbientLight() * mDayLight);
|
---|
| 75 | mRangeLight = mDayLight - mNightLight;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | ColourValue getRangeLight()
|
---|
| 79 | {
|
---|
| 80 | return mRangeLight;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | void showDebugShadowMap(int idShadowMap)
|
---|
| 84 | {
|
---|
| 85 | TexturePtr tex = TextureManager::getSingleton().getByName("Ogre/ShadowTexture" + StringConverter::toString(idShadowMap));
|
---|
| 86 | HardwarePixelBufferSharedPtr hpb = tex->getBuffer(0,0);
|
---|
| 87 | LogManager::getSingleton().logMessage(" -- WIDTH = " + StringConverter::toString(hpb->getWidth()));
|
---|
| 88 | LogManager::getSingleton().logMessage(" -- HEIGHT = " + StringConverter::toString(hpb->getHeight()));
|
---|
| 89 | LogManager::getSingleton().logMessage(" -- DEPTH = " + StringConverter::toString(hpb->getDepth()));
|
---|
| 90 | LogManager::getSingleton().logMessage(" -- FORMAT = " + StringConverter::toString(hpb->getFormat()));
|
---|
| 91 | LogManager::getSingleton().logMessage(" -- SIZE = " + StringConverter::toString(hpb->getSizeInBytes()));
|
---|
| 92 | float *tex01 = new float[tex->getHeight()*tex->getWidth()*4];
|
---|
| 93 | PixelBox pBox(tex->getWidth(),tex->getHeight(),tex->getDepth(),PF_FLOAT32_RGBA,tex01);
|
---|
| 94 | LogManager::getSingleton().logMessage(" --PBOX WIDTH = " + StringConverter::toString(pBox.getWidth()));
|
---|
| 95 | LogManager::getSingleton().logMessage(" --PBOX HEIGHT = " + StringConverter::toString(pBox.getHeight()));
|
---|
| 96 | hpb->blitToMemory(pBox);
|
---|
| 97 | //imdebug("rgba w=%d h=%d %p b=32f",pBox.getWidth(),pBox.getHeight(),pBox.data);
|
---|
| 98 | delete tex01;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | void setDayLight(ColourValue dayLight)
|
---|
| 102 | {
|
---|
| 103 | mDayLight = dayLight;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | void setNightLight(ColourValue nightLight)
|
---|
| 107 | {
|
---|
| 108 | mNightLight = nightLight;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | void setAmbientColour(ColourValue colour)
|
---|
| 112 | {
|
---|
| 113 | mSceneMgr->setAmbientLight(colour);
|
---|
| 114 | MaterialPtr materialSky = MaterialManager::getSingleton().getByName("Examples/SpaceSkyPlaneNight");
|
---|
| 115 | if (!materialSky.isNull())
|
---|
| 116 | {
|
---|
| 117 | if (materialSky->getTechnique(0)->getPass(0)->isProgrammable())
|
---|
| 118 | {
|
---|
| 119 | GpuProgramParametersSharedPtr fragParams = materialSky->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
|
---|
| 120 | ColourValue ambientColour = mSceneMgr->getAmbientLight();
|
---|
| 121 | fragParams->setNamedConstant("ambientlight",Vector4(ambientColour.val[0],ambientColour.val[1],ambientColour.val[2],ambientColour.val[3]));
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | mCamera->getViewport()->setBackgroundColour(mSceneMgr->getAmbientLight() * ColourValue(0.85,0.88,0.96));
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | void setCurrentLight(unsigned int idLight)
|
---|
| 128 | {
|
---|
| 129 | mCurrentLight = mLightList[idLight];
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | void update(InputReader *input)
|
---|
| 133 | {
|
---|
| 134 | /*
|
---|
| 135 | if (input->isKeyDown(KC_RETURN))
|
---|
| 136 | {
|
---|
| 137 | if (!mShadowsEnabled)
|
---|
| 138 | {
|
---|
| 139 | mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
|
---|
| 140 | mShadowsEnabled = true;
|
---|
| 141 | }
|
---|
| 142 | else
|
---|
| 143 | {
|
---|
| 144 | mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
|
---|
| 145 | mShadowsEnabled = false;
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | if (input->isKeyDown(KC_SPACE))
|
---|
| 150 | {
|
---|
| 151 | idCurrentLight++;
|
---|
| 152 | if (idCurrentLight == mLightList.size())
|
---|
| 153 | {
|
---|
| 154 | idCurrentLight = 0;
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | if (input->isKeyDown(KC_Q))
|
---|
| 159 | {
|
---|
| 160 | exposure = MIN(exposure+0.05,10.0);
|
---|
| 161 | OverlayElement *oInfo = OverlayManager::getSingleton().getOverlayElement("ObscuranceExposure");
|
---|
| 162 | oInfo->setCaption("Obscurance Exposure: " + StringConverter::toString(exposure));
|
---|
| 163 | }
|
---|
| 164 | if (input->isKeyDown(KC_E))
|
---|
| 165 | {
|
---|
| 166 | exposure = MAX(exposure-0.05,-10.0);
|
---|
| 167 | OverlayElement *oInfo = OverlayManager::getSingleton().getOverlayElement("ObscuranceExposure");
|
---|
| 168 | oInfo->setCaption("Obscurance Exposure: " + StringConverter::toString(exposure));
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | if (input->isKeyDown(KC_F1))
|
---|
| 172 | {
|
---|
| 173 | mCurrentLight->setDiffuseColour(MIN(mCurrentLight->getDiffuseColour().r+0.05,1.0),MIN(mCurrentLight->getDiffuseColour().g,1.0),MIN(mCurrentLight->getDiffuseColour().b,1.0));
|
---|
| 174 | OverlayElement *dInfo = OverlayManager::getSingleton().getOverlayElement("LightDiffuseColour");
|
---|
| 175 | dInfo->setCaption("Diffuse Col.: " + StringConverter::toString(mCurrentLight->getDiffuseColour()));
|
---|
| 176 | }
|
---|
| 177 | if (input->isKeyDown(KC_F2))
|
---|
| 178 | {
|
---|
| 179 | mCurrentLight->setDiffuseColour(MIN(mCurrentLight->getDiffuseColour().r,1.0),MIN(mCurrentLight->getDiffuseColour().g+0.05,1.0),MIN(mCurrentLight->getDiffuseColour().b,1.0));
|
---|
| 180 | OverlayElement *dInfo = OverlayManager::getSingleton().getOverlayElement("LightDiffuseColour");
|
---|
| 181 | dInfo->setCaption("Diffuse Col.: " + StringConverter::toString(mCurrentLight->getDiffuseColour()));
|
---|
| 182 | }
|
---|
| 183 | if (input->isKeyDown(KC_F3))
|
---|
| 184 | {
|
---|
| 185 | mCurrentLight->setDiffuseColour(MIN(mCurrentLight->getDiffuseColour().r,1.0),MIN(mCurrentLight->getDiffuseColour().g,1.0),MIN(mCurrentLight->getDiffuseColour().b+0.05,1.0));
|
---|
| 186 | OverlayElement *dInfo = OverlayManager::getSingleton().getOverlayElement("LightDiffuseColour");
|
---|
| 187 | dInfo->setCaption("Diffuse Col.: " + StringConverter::toString(mCurrentLight->getDiffuseColour()));
|
---|
| 188 | }
|
---|
| 189 | if (input->isKeyDown(KC_F4))
|
---|
| 190 | {
|
---|
| 191 | mCurrentLight->setDiffuseColour(MAX(mCurrentLight->getDiffuseColour().r-0.05,0.0),MAX(mCurrentLight->getDiffuseColour().g,0.0),MAX(mCurrentLight->getDiffuseColour().b,0.0));
|
---|
| 192 | OverlayElement *dInfo = OverlayManager::getSingleton().getOverlayElement("LightDiffuseColour");
|
---|
| 193 | dInfo->setCaption("Diffuse Col.: " + StringConverter::toString(mCurrentLight->getDiffuseColour()));
|
---|
| 194 | }
|
---|
| 195 | if (input->isKeyDown(KC_F5))
|
---|
| 196 | {
|
---|
| 197 | mCurrentLight->setDiffuseColour(MAX(mCurrentLight->getDiffuseColour().r,0.0),MAX(mCurrentLight->getDiffuseColour().g-0.05,0.0),MAX(mCurrentLight->getDiffuseColour().b,0.0));
|
---|
| 198 | OverlayElement *dInfo = OverlayManager::getSingleton().getOverlayElement("LightDiffuseColour");
|
---|
| 199 | dInfo->setCaption("Diffuse Col.: " + StringConverter::toString(mCurrentLight->getDiffuseColour()));
|
---|
| 200 | }
|
---|
| 201 | if (input->isKeyDown(KC_F6))
|
---|
| 202 | {
|
---|
| 203 | mCurrentLight->setDiffuseColour(MAX(mCurrentLight->getDiffuseColour().r,0.0),MAX(mCurrentLight->getDiffuseColour().g,0.0),MAX(mCurrentLight->getDiffuseColour().b-0.05,0.0));
|
---|
| 204 | OverlayElement *dInfo = OverlayManager::getSingleton().getOverlayElement("LightDiffuseColour");
|
---|
| 205 | dInfo->setCaption("Diffuse Col.: " + StringConverter::toString(mCurrentLight->getDiffuseColour()));
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | if (input->isKeyDown(KC_F7))
|
---|
| 211 | {
|
---|
| 212 | mSceneMgr->setShadowColour(ColourValue(MIN(mSceneMgr->getShadowColour().r+0.05,1.0),MIN(mSceneMgr->getShadowColour().g,1.0),MIN(mSceneMgr->getShadowColour().b,1.0)));
|
---|
| 213 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightShadowColour");
|
---|
| 214 | sInfo->setCaption("Shadow Col.: " + StringConverter::toString(mSceneMgr->getShadowColour()));
|
---|
| 215 | }
|
---|
| 216 | if (input->isKeyDown(KC_F8))
|
---|
| 217 | {
|
---|
| 218 | mSceneMgr->setShadowColour(ColourValue(MIN(mSceneMgr->getShadowColour().r,1.0),MIN(mSceneMgr->getShadowColour().g+0.05,1.0),MIN(mSceneMgr->getShadowColour().b,1.0)));
|
---|
| 219 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightShadowColour");
|
---|
| 220 | sInfo->setCaption("Shadow Col.: " + StringConverter::toString(mSceneMgr->getShadowColour()));
|
---|
| 221 | }
|
---|
| 222 | if (input->isKeyDown(KC_F9))
|
---|
| 223 | {
|
---|
| 224 | mSceneMgr->setShadowColour(ColourValue(MIN(mSceneMgr->getShadowColour().r,1.0),MIN(mSceneMgr->getShadowColour().g,1.0),MIN(mSceneMgr->getShadowColour().b+0.05,1.0)));
|
---|
| 225 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightShadowColour");
|
---|
| 226 | sInfo->setCaption("Shadow Col.: " + StringConverter::toString(mSceneMgr->getShadowColour()));
|
---|
| 227 | }
|
---|
| 228 | if (input->isKeyDown(KC_F10))
|
---|
| 229 | {
|
---|
| 230 | mSceneMgr->setShadowColour(ColourValue(MAX(mSceneMgr->getShadowColour().r-0.05,0.0),MAX(mSceneMgr->getShadowColour().g,0.0),MAX(mSceneMgr->getShadowColour().b,0.0)));
|
---|
| 231 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightShadowColour");
|
---|
| 232 | sInfo->setCaption("Shadow Col.: " + StringConverter::toString(mSceneMgr->getShadowColour()));
|
---|
| 233 | }
|
---|
| 234 | if (input->isKeyDown(KC_F11))
|
---|
| 235 | {
|
---|
| 236 | mSceneMgr->setShadowColour(ColourValue(MAX(mSceneMgr->getShadowColour().r,0.0),MAX(mSceneMgr->getShadowColour().g-0.05,0.0),MAX(mSceneMgr->getShadowColour().b,0.0)));
|
---|
| 237 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightShadowColour");
|
---|
| 238 | sInfo->setCaption("Shadow Col.: " + StringConverter::toString(mSceneMgr->getShadowColour()));
|
---|
| 239 | }
|
---|
| 240 | if (input->isKeyDown(KC_F12))
|
---|
| 241 | {
|
---|
| 242 | mSceneMgr->setShadowColour(ColourValue(MAX(mSceneMgr->getShadowColour().r,0.0),MAX(mSceneMgr->getShadowColour().g,0.0),MAX(mSceneMgr->getShadowColour().b-0.05,0.0)));
|
---|
| 243 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightShadowColour");
|
---|
| 244 | sInfo->setCaption("Shadow Col.: " + StringConverter::toString(mSceneMgr->getShadowColour()));
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | if (input->isKeyDown(KC_1))
|
---|
| 248 | {
|
---|
| 249 | mCurrentLight->setSpecularColour(MIN(mCurrentLight->getSpecularColour().r+0.05,1.0),MIN(mCurrentLight->getSpecularColour().g,1.0),MIN(mCurrentLight->getSpecularColour().b,1.0));
|
---|
| 250 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightSpecularColour");
|
---|
| 251 | sInfo->setCaption("Specular Col.: " + StringConverter::toString(mCurrentLight->getSpecularColour()));
|
---|
| 252 | }
|
---|
| 253 | if (input->isKeyDown(KC_2))
|
---|
| 254 | {
|
---|
| 255 | mCurrentLight->setSpecularColour(MIN(mCurrentLight->getSpecularColour().r,1.0),MIN(mCurrentLight->getSpecularColour().g+0.05,1.0),MIN(mCurrentLight->getSpecularColour().b,1.0));
|
---|
| 256 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightSpecularColour");
|
---|
| 257 | sInfo->setCaption("Specular Col.: " + StringConverter::toString(mCurrentLight->getSpecularColour()));
|
---|
| 258 | }
|
---|
| 259 | if (input->isKeyDown(KC_3))
|
---|
| 260 | {
|
---|
| 261 | mCurrentLight->setSpecularColour(MIN(mCurrentLight->getSpecularColour().r,1.0),MIN(mCurrentLight->getSpecularColour().g,1.0),MIN(mCurrentLight->getSpecularColour().b+0.05,1.0));
|
---|
| 262 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightSpecularColour");
|
---|
| 263 | sInfo->setCaption("Specular Col.: " + StringConverter::toString(mCurrentLight->getSpecularColour()));
|
---|
| 264 | }
|
---|
| 265 | if (input->isKeyDown(KC_4))
|
---|
| 266 | {
|
---|
| 267 | mCurrentLight->setSpecularColour(MAX(mCurrentLight->getSpecularColour().r-0.05,0.0),MAX(mCurrentLight->getSpecularColour().g,0.0),MAX(mCurrentLight->getSpecularColour().b,0.0));
|
---|
| 268 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightSpecularColour");
|
---|
| 269 | sInfo->setCaption("Specular Col.: " + StringConverter::toString(mCurrentLight->getSpecularColour()));
|
---|
| 270 | }
|
---|
| 271 | if (input->isKeyDown(KC_5))
|
---|
| 272 | {
|
---|
| 273 | mCurrentLight->setSpecularColour(MAX(mCurrentLight->getSpecularColour().r,0.0),MAX(mCurrentLight->getSpecularColour().g-0.05,0.0),MAX(mCurrentLight->getSpecularColour().b,0.0));
|
---|
| 274 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightSpecularColour");
|
---|
| 275 | sInfo->setCaption("Specular Col.: " + StringConverter::toString(mCurrentLight->getSpecularColour()));
|
---|
| 276 | }
|
---|
| 277 | if (input->isKeyDown(KC_6))
|
---|
| 278 | {
|
---|
| 279 | mCurrentLight->setSpecularColour(MAX(mCurrentLight->getSpecularColour().r,0.0),MAX(mCurrentLight->getSpecularColour().g,0.0),MAX(mCurrentLight->getSpecularColour().b-0.05,0.0));
|
---|
| 280 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("LightSpecularColour");
|
---|
| 281 | sInfo->setCaption("Specular Col.: " + StringConverter::toString(mCurrentLight->getSpecularColour()));
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | if (input->isKeyDown(KC_Z))
|
---|
| 285 | {
|
---|
| 286 | mSceneMgr->setAmbientLight(ColourValue(MIN(mSceneMgr->getAmbientLight().r+0.05,1.0),MIN(mSceneMgr->getAmbientLight().g,1.0),MIN(mSceneMgr->getAmbientLight().b,1.0)));
|
---|
| 287 | mCamera->getViewport()->setBackgroundColour(mSceneMgr->getAmbientLight() * mDayLight);
|
---|
| 288 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("AmbientLight");
|
---|
| 289 | sInfo->setCaption("Ambient Col.: " + StringConverter::toString(mSceneMgr->getAmbientLight()));
|
---|
| 290 | MaterialPtr materialSky = MaterialManager::getSingleton().getByName("Examples/SpaceSkyPlaneNight");
|
---|
| 291 | if (!materialSky.isNull())
|
---|
| 292 | {
|
---|
| 293 | if (materialSky->getTechnique(0)->getPass(0)->isProgrammable())
|
---|
| 294 | {
|
---|
| 295 | GpuProgramParametersSharedPtr fragParams = materialSky->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
|
---|
| 296 | ColourValue ambientColour = mSceneMgr->getAmbientLight();
|
---|
| 297 | fragParams->setNamedConstant("ambientlight",Vector4(ambientColour.val[0],ambientColour.val[1],ambientColour.val[2],ambientColour.val[3]));
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 | }
|
---|
| 301 | if (input->isKeyDown(KC_X))
|
---|
| 302 | {
|
---|
| 303 | mSceneMgr->setAmbientLight(ColourValue(MIN(mSceneMgr->getAmbientLight().r,1.0),MIN(mSceneMgr->getAmbientLight().g+0.05,1.0),MIN(mSceneMgr->getAmbientLight().b,1.0)));
|
---|
| 304 | mCamera->getViewport()->setBackgroundColour(mSceneMgr->getAmbientLight() * mDayLight);
|
---|
| 305 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("AmbientLight");
|
---|
| 306 | sInfo->setCaption("Ambient Col.: " + StringConverter::toString(mSceneMgr->getAmbientLight()));
|
---|
| 307 | MaterialPtr materialSky = MaterialManager::getSingleton().getByName("Examples/SpaceSkyPlaneNight");
|
---|
| 308 | if (!materialSky.isNull())
|
---|
| 309 | {
|
---|
| 310 | if (materialSky->getTechnique(0)->getPass(0)->isProgrammable())
|
---|
| 311 | {
|
---|
| 312 | GpuProgramParametersSharedPtr fragParams = materialSky->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
|
---|
| 313 | ColourValue ambientColour = mSceneMgr->getAmbientLight();
|
---|
| 314 | fragParams->setNamedConstant("ambientlight",Vector4(ambientColour.val[0],ambientColour.val[1],ambientColour.val[2],ambientColour.val[3]));
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 | if (input->isKeyDown(KC_C))
|
---|
| 319 | {
|
---|
| 320 | mSceneMgr->setAmbientLight(ColourValue(MIN(mSceneMgr->getAmbientLight().r,1.0),MIN(mSceneMgr->getAmbientLight().g,1.0),MIN(mSceneMgr->getAmbientLight().b+0.05,1.0)));
|
---|
| 321 | mCamera->getViewport()->setBackgroundColour(mSceneMgr->getAmbientLight() * mDayLight);
|
---|
| 322 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("AmbientLight");
|
---|
| 323 | sInfo->setCaption("Ambient Col.: " + StringConverter::toString(mSceneMgr->getAmbientLight()));
|
---|
| 324 | MaterialPtr materialSky = MaterialManager::getSingleton().getByName("Examples/SpaceSkyPlaneNight");
|
---|
| 325 | if (!materialSky.isNull())
|
---|
| 326 | {
|
---|
| 327 | if (materialSky->getTechnique(0)->getPass(0)->isProgrammable())
|
---|
| 328 | {
|
---|
| 329 | GpuProgramParametersSharedPtr fragParams = materialSky->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
|
---|
| 330 | ColourValue ambientColour = mSceneMgr->getAmbientLight();
|
---|
| 331 | fragParams->setNamedConstant("ambientlight",Vector4(ambientColour.val[0],ambientColour.val[1],ambientColour.val[2],ambientColour.val[3]));
|
---|
| 332 | }
|
---|
| 333 | }
|
---|
| 334 | }
|
---|
| 335 | if (input->isKeyDown(KC_V))
|
---|
| 336 | {
|
---|
| 337 | mSceneMgr->setAmbientLight(ColourValue(MAX(mSceneMgr->getAmbientLight().r-0.05,0.0),MAX(mSceneMgr->getAmbientLight().g,0.0),MAX(mSceneMgr->getAmbientLight().b,0.0)));
|
---|
| 338 | mCamera->getViewport()->setBackgroundColour(mSceneMgr->getAmbientLight() * mDayLight);
|
---|
| 339 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("AmbientLight");
|
---|
| 340 | sInfo->setCaption("Ambient Col.: " + StringConverter::toString(mSceneMgr->getAmbientLight()));
|
---|
| 341 | MaterialPtr materialSky = MaterialManager::getSingleton().getByName("Examples/SpaceSkyPlaneNight");
|
---|
| 342 | if (!materialSky.isNull())
|
---|
| 343 | {
|
---|
| 344 | if (materialSky->getTechnique(0)->getPass(0)->isProgrammable())
|
---|
| 345 | {
|
---|
| 346 | GpuProgramParametersSharedPtr fragParams = materialSky->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
|
---|
| 347 | ColourValue ambientColour = mSceneMgr->getAmbientLight();
|
---|
| 348 | fragParams->setNamedConstant("ambientlight",Vector4(ambientColour.val[0],ambientColour.val[1],ambientColour.val[2],ambientColour.val[3]));
|
---|
| 349 | }
|
---|
| 350 | }
|
---|
| 351 | }
|
---|
| 352 | if (input->isKeyDown(KC_B))
|
---|
| 353 | {
|
---|
| 354 | mSceneMgr->setAmbientLight(ColourValue(MAX(mSceneMgr->getAmbientLight().r,0.0),MAX(mSceneMgr->getAmbientLight().g-0.05,0.0),MAX(mSceneMgr->getAmbientLight().b,0.0)));
|
---|
| 355 | mCamera->getViewport()->setBackgroundColour(mSceneMgr->getAmbientLight() * mDayLight);
|
---|
| 356 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("AmbientLight");
|
---|
| 357 | sInfo->setCaption("Ambient Col.: " + StringConverter::toString(mSceneMgr->getAmbientLight()));
|
---|
| 358 | MaterialPtr materialSky = MaterialManager::getSingleton().getByName("Examples/SpaceSkyPlaneNight");
|
---|
| 359 | if (!materialSky.isNull())
|
---|
| 360 | {
|
---|
| 361 | if (materialSky->getTechnique(0)->getPass(0)->isProgrammable())
|
---|
| 362 | {
|
---|
| 363 | GpuProgramParametersSharedPtr fragParams = materialSky->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
|
---|
| 364 | ColourValue ambientColour = mSceneMgr->getAmbientLight();
|
---|
| 365 | fragParams->setNamedConstant("ambientlight",Vector4(ambientColour.val[0],ambientColour.val[1],ambientColour.val[2],ambientColour.val[3]));
|
---|
| 366 | }
|
---|
| 367 | }
|
---|
| 368 | }
|
---|
| 369 | if (input->isKeyDown(KC_N))
|
---|
| 370 | {
|
---|
| 371 | mSceneMgr->setAmbientLight(ColourValue(MAX(mSceneMgr->getAmbientLight().r,0.0),MAX(mSceneMgr->getAmbientLight().g,0.0),MAX(mSceneMgr->getAmbientLight().b-0.05,0.0)));
|
---|
| 372 | mCamera->getViewport()->setBackgroundColour(mSceneMgr->getAmbientLight() * mDayLight);
|
---|
| 373 | OverlayElement *sInfo = OverlayManager::getSingleton().getOverlayElement("AmbientLight");
|
---|
| 374 | sInfo->setCaption("Ambient Col.: " + StringConverter::toString(mSceneMgr->getAmbientLight()));
|
---|
| 375 | MaterialPtr materialSky = MaterialManager::getSingleton().getByName("Examples/SpaceSkyPlaneNight");
|
---|
| 376 | if (!materialSky.isNull())
|
---|
| 377 | {
|
---|
| 378 | if (materialSky->getTechnique(0)->getPass(0)->isProgrammable())
|
---|
| 379 | {
|
---|
| 380 | GpuProgramParametersSharedPtr fragParams = materialSky->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
|
---|
| 381 | ColourValue ambientColour = mSceneMgr->getAmbientLight();
|
---|
| 382 | fragParams->setNamedConstant("ambientlight",Vector4(ambientColour.val[0],ambientColour.val[1],ambientColour.val[2],ambientColour.val[3]));
|
---|
| 383 | }
|
---|
| 384 | }
|
---|
| 385 | }
|
---|
| 386 | */
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | void createShadowMapOverlay(unsigned int idShadowMap)
|
---|
| 390 | {
|
---|
| 391 | MaterialPtr matShadowImage = MaterialManager::getSingleton().getByName("shadoMapImage");
|
---|
| 392 | matShadowImage->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
|
---|
| 393 | matShadowImage->getTechnique(0)->getPass(0)->createTextureUnitState("Ogre/ShadowTexture" + StringConverter::toString(idShadowMap));
|
---|
| 394 | }
|
---|
| 395 |
|
---|
| 396 | void showShadowMapOverlay(bool show)
|
---|
| 397 | {
|
---|
| 398 | if (show)
|
---|
| 399 | {
|
---|
| 400 | mShadowMapOverlay->show();
|
---|
| 401 | mLightingInfo->show();
|
---|
| 402 | mShadowMapOverlayEnabled = true;
|
---|
| 403 | }
|
---|
| 404 | else
|
---|
| 405 | {
|
---|
| 406 | mShadowMapOverlay->hide();
|
---|
| 407 | mLightingInfo->hide();
|
---|
| 408 | mShadowMapOverlayEnabled = false;
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 | void addLight(Light *light)
|
---|
| 412 | {
|
---|
| 413 | mLightList.push_back(light);
|
---|
| 414 |
|
---|
| 415 | if (mShadowsEnabled)
|
---|
| 416 | {
|
---|
| 417 | mSceneMgr->setShadowTextureCount(mLightList.size());
|
---|
| 418 | }
|
---|
| 419 | }
|
---|
| 420 |
|
---|
| 421 | void setShadowTexturePixelFormat(PixelFormat fmt)
|
---|
| 422 | {
|
---|
| 423 | mSceneMgr->setShadowTexturePixelFormat(fmt);
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | void setShadowColour(ColourValue colour)
|
---|
| 427 | {
|
---|
| 428 | mSceneMgr->setShadowColour(colour);
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | ColourValue getShadowColour()
|
---|
| 432 | {
|
---|
| 433 | return mSceneMgr->getShadowColour();
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | void setShadowTextureSize(ushort size)
|
---|
| 437 | {
|
---|
| 438 | mSceneMgr->setShadowTextureSize(size);
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | Light* getLight(int idLight)
|
---|
| 442 | {
|
---|
| 443 | return mLightList[idLight];
|
---|
| 444 | }
|
---|
| 445 | }; |
---|