void ShadowGroup::addDirectionalLight(DirectionalLight *dirLight, enum ShadowMode mode) { int light_id = dirLight->_id; osg::Matrixf shadowView; if(mode == BASIC) { shadowView.makeLookAt(dirLight->getPosition(), dirLight->getLookAt(), osg::Vec3(0, 0, 1)); // z-up osg::Matrixf shadowMVP = shadowView * _shadowProjection; dirLight->_lightViewMatrix = shadowView; dirLight->_lightProjectionMatrix = _shadowProjection; dirLight->_lightNearDistance = _nearPlane; dirLight->_lightFarDistance = _farPlane; osg::ref_ptr<osg::TextureRectangle> depthTex = createShadowTexture(_depthTexWidth, _depthTexHeight); _dir_depthMaps.insert(std::make_pair(light_id, depthTex)); if(_isGIEnabled) { // make the only the first light gi light if(_dir_lightDir_fluxMaps.empty()) { osg::ref_ptr<osg::TextureRectangle> fluxTex = createLightDirFluxTexture(_rsmTexWidth, _rsmTexHeight);// TODO: optimization _dir_lightDir_fluxMaps.insert(std::make_pair(light_id, fluxTex)); osg::ref_ptr<osg::TextureRectangle> posTex = createLightPositionTexture(_rsmTexWidth, _rsmTexHeight); _dir_worldPos_Maps.insert(std::make_pair(light_id, posTex)); _giLight = dirLight; configRSMCamera(); } // addBasicShadowCam(depthTex, fluxTex, posTex, shadowView, shadowMVP, dirLight); // TODO: refactor addBasicShadowCam(depthTex, NULL, NULL, shadowView, shadowMVP, dirLight); addBlurCamera(depthTex); } else { addBasicShadowCam(depthTex, NULL, NULL, shadowView, shadowMVP, dirLight); addBlurCamera(depthTex); } } }
//----------------------------------------------------------------------------- //! コンストラクタ //----------------------------------------------------------------------------- CascadedShadow::CascadedShadow() : _currentShadowNum (0) , _split_weight (0.75f) , _modelMatrix (Matrix::IDENTITY) , _depthTexture (nullptr) { for( u32 i=0; i<6; ++i ) { _MinMax[i] = 0.0f; } // シャドウマップ初期化とプロジェクション行列初期化 for( u32 i=0; i<SPLIT_COUNT; ++i ) { _pShadow[i] = nullptr; // シャドウマップ初期化 SAFE_NEW(_pShadow[i]); // 視錐台初期化 /*f[i]._fov = TO_RADIAN(120.0f); f[i]._ratio = (f32)WIDTH/(f32)HEIGHT;*/ // プロジェクション行列初期化 _depthProj[i] = Matrix::IDENTITY; } // テクスチャの横幅は分割数分取る _depthTexSize = Size<s32>(DEPTH_SIZE * SPLIT_COUNT, DEPTH_SIZE); // シャドウテクスチャを作成 if( !createShadowTexture() ) { MessageBoxA(NULL, "シャドウテクスチャ作成に失敗しました", "エラー", MB_OK); } // 分割数をシェーダに渡しておく GmShader()->changeShader(SystemShader::SHADER_TEXTURE); GmShader()->setUniform1f("gSplitCount", (GLfloat)SPLIT_COUNT); GmShader()->beginPrevShader(); TaskModelX::setBiasMatrix(_biasMatrix); _isSetRender = false; }