Action::ResultE ShadingCallbacks::pointlightRenderEnter(CNodePtr &pNode, Action *action) { PointLight *pPl = dynamic_cast<PointLight *>(pNode.getCPtr()); if(pPl->getOn() == false) return Action::Continue; DrawActionBase *da = dynamic_cast<DrawActionBase *>(action); da->getStatistics()->getElem(PointLight::statNPointLights)->inc(); return lightRenderEnter(pPl, action); }
void VRShadowEngine::doFinalPass(Light *pLight, RenderAction *pAction, EngineDataPtr pEngineData) { this->pushPartition(pAction, (RenderPartition::CopyViewing | RenderPartition::CopyProjection | RenderPartition::CopyWindow | RenderPartition::CopyViewportSize | RenderPartition::CopyFrustum | RenderPartition::CopyNearFar )); FrameBufferObject *pTarget = pEngineData->getRenderTarget(); if(pTarget == NULL) { FrameBufferObjectUnrecPtr pFBO = FrameBufferObject::createLocal(); pFBO->setWidth (this->getWidth ()); pFBO->setHeight(this->getHeight()); pEngineData->setRenderTarget(pFBO); pTarget = pFBO; } BlendChunkUnrecPtr pBlender = pEngineData->getBlendChunk(); if(pBlender == NULL) { pBlender = BlendChunk::createLocal(); pBlender->setSrcFactor(GL_ONE); pBlender->setDestFactor(GL_ONE); pBlender->setAlphaFunc(GL_GEQUAL); pBlender->setAlphaValue(0.99f); pEngineData->setBlendChunk(pBlender); } Matrix4f projectionMatrix, viewMatrix, biasMatrix; biasMatrix.setIdentity(); biasMatrix.setScale(0.5); biasMatrix.setTranslate(0.5,0.5,0.5); MatrixCamera *pCam = dynamic_cast<MatrixCamera *>(pEngineData->getCamera()); pCam->getProjection(projectionMatrix, this->getWidth (), this->getHeight()); pCam->getViewing(viewMatrix, this->getWidth (), this->getHeight()); Matrix textureMatrix = biasMatrix; textureMatrix.mult(projectionMatrix); textureMatrix.mult(viewMatrix); textureMatrix.transpose(); Vec4f ps = textureMatrix[0]; Vec4f pt = textureMatrix[1]; Vec4f pr = textureMatrix[2]; Vec4f pq = textureMatrix[3]; TexGenChunkUnrecPtr pTexGen = pEngineData->getTexGenChunk(); if(pTexGen == NULL) { pTexGen = TexGenChunk::createLocal(); pEngineData->setTexGenChunk(pTexGen); pTexGen->setEyeModelViewMode(TexGenChunk::EyeModelViewCamera); pTexGen->setGenFuncS(GL_EYE_LINEAR); pTexGen->setGenFuncT(GL_EYE_LINEAR); pTexGen->setGenFuncR(GL_EYE_LINEAR); pTexGen->setGenFuncQ(GL_EYE_LINEAR); } pTexGen->setGenFuncSPlane(ps); pTexGen->setGenFuncTPlane(pt); pTexGen->setGenFuncRPlane(pr); pTexGen->setGenFuncQPlane(pq); TextureObjChunkUnrecPtr pTexChunk = pEngineData->getTexChunk(); if(pTexChunk == NULL) { pTexChunk = TextureObjChunk::createLocal(); pEngineData->setTexChunk(pTexChunk); ImageUnrecPtr pImage = Image::createLocal(); // creates a image without allocating main memory. pImage->set(Image::OSG_L_PF, pTarget->getWidth (), pTarget->getHeight(), 1, 1, 1, 0, NULL, Image::OSG_UINT8_IMAGEDATA, false); pTexChunk->setImage (pImage); pTexChunk->setInternalFormat(GL_DEPTH_COMPONENT32); pTexChunk->setExternalFormat(GL_DEPTH_COMPONENT); pTexChunk->setMinFilter (GL_LINEAR); // tried GL_LINEAR_MIPMAP_LINEAR pTexChunk->setMagFilter (GL_LINEAR); pTexChunk->setWrapS (GL_CLAMP_TO_EDGE); // was GL_CLAMP_TO_BORDER pTexChunk->setWrapT (GL_CLAMP_TO_EDGE); // was GL_CLAMP_TO_BORDER // pTexChunk->setEnvMode (GL_MODULATE); pTexChunk->setTarget (GL_TEXTURE_2D); pTexChunk->setCompareMode(GL_COMPARE_R_TO_TEXTURE); pTexChunk->setCompareFunc(GL_LEQUAL); pTexChunk->setDepthMode (GL_INTENSITY); } pAction->pushState(); UInt32 uiBlendSlot = pBlender ->getClassId(); UInt32 uiTexSlot = pTexChunk->getClassId(); UInt32 uiTexGenSlot = pTexGen ->getClassId(); if(this->getForceTextureUnit() != -1) { uiTexSlot += this->getForceTextureUnit(); uiTexGenSlot += this->getForceTextureUnit(); } else { uiTexSlot += 3; uiTexGenSlot += 3; } pAction->addOverride(uiBlendSlot, pBlender ); pAction->addOverride(uiTexSlot, pTexChunk); pAction->addOverride(uiTexGenSlot, pTexGen ); lightRenderEnter(pLight, pAction); pAction->useNodeList(false); this->recurseFrom(pAction, pLight); pAction->popState(); this->popPartition(pAction); }