LightInfo* LightManager::getSpecialLight( LightManager::SpecialLightTypesEnum type, bool useDefault ) { if ( mSpecialLights[type] ) return mSpecialLights[type]; if ( useDefault ) return getDefaultLight(); return NULL; }
void AdvancedLightManager::setLightInfo( ProcessedMaterial *pmat, const Material *mat, const SceneData &sgData, const SceneRenderState *state, U32 pass, GFXShaderConstBuffer *shaderConsts) { // Skip this if we're rendering from the prepass bin. if ( sgData.binType == SceneData::PrePassBin ) return; PROFILE_SCOPE(AdvancedLightManager_setLightInfo); LightingShaderConstants *lsc = getLightingShaderConstants(shaderConsts); LightShadowMap *lsm = SHADOWMGR->getCurrentShadowMap(); LightInfo *light; if ( lsm ) light = lsm->getLightInfo(); else { light = sgData.lights[0]; if ( !light ) light = getDefaultLight(); } // NOTE: If you encounter a crash from this point forward // while setting a shader constant its probably because the // mConstantLookup has bad shaders/constants in it. // // This is a known crash bug that can occur if materials/shaders // are reloaded and the light manager is not reset. // // We should look to fix this by clearing the table. // Update the forward shading light constants. _update4LightConsts( sgData, lsc->mLightPositionSC, lsc->mLightDiffuseSC, lsc->mLightAmbientSC, lsc->mLightInvRadiusSqSC, lsc->mLightSpotDirSC, lsc->mLightSpotAngleSC, lsc->mLightSpotFalloffSC, shaderConsts ); if ( lsm && light->getCastShadows() ) { if ( lsc->mWorldToLightProjSC->isValid() ) shaderConsts->set( lsc->mWorldToLightProjSC, lsm->getWorldToLightProj(), lsc->mWorldToLightProjSC->getType() ); if ( lsc->mViewToLightProjSC->isValid() ) { // TODO: Should probably cache these results and // not do this mul here on every material that needs // this transform. shaderConsts->set( lsc->mViewToLightProjSC, lsm->getWorldToLightProj() * state->getCameraTransform(), lsc->mViewToLightProjSC->getType() ); } shaderConsts->setSafe( lsc->mShadowMapSizeSC, 1.0f / (F32)lsm->getTexSize() ); // Do this last so that overrides can properly override parameters previously set lsm->setShaderParameters(shaderConsts, lsc); } else { if ( lsc->mViewToLightProjSC->isValid() ) { // TODO: Should probably cache these results and // not do this mul here on every material that needs // this transform. MatrixF proj; light->getWorldToLightProj( &proj ); shaderConsts->set( lsc->mViewToLightProjSC, proj * state->getCameraTransform(), lsc->mViewToLightProjSC->getType() ); } } }