void ShaderShadowMapEngine::updateShadowTexChunk(SSMEngineData *data) { TextureObjChunk *bufTex = data->getShadowTexChunk(); if(bufTex == NULL) { TextureObjChunkUnrecPtr newBufTex = TextureObjChunk::createLocal(); newBufTex->setMinFilter (GL_LINEAR ); newBufTex->setMagFilter (GL_LINEAR ); newBufTex->setWrapS (GL_CLAMP_TO_EDGE ); newBufTex->setWrapT (GL_CLAMP_TO_EDGE ); newBufTex->setWrapR (GL_CLAMP_TO_EDGE ); newBufTex->setScale (false ); newBufTex->setInternalFormat(GL_DEPTH_COMPONENT24 ); newBufTex->setExternalFormat(GL_DEPTH_COMPONENT ); newBufTex->setCompareMode (GL_COMPARE_R_TO_TEXTURE); newBufTex->setCompareFunc (GL_LESS ); newBufTex->setDepthMode (GL_LUMINANCE ); data->setShadowTexChunk(newBufTex); this->setShadowTexChunk(newBufTex); } }
FrameBufferObjectTransitPtr FBOBuilder::operator()( UInt32 width, UInt32 height) const { // // Setup the FBO // FrameBufferObjectUnrecPtr fbo = FrameBufferObject::create(); // // multiple color buffers // for (UINT32 idx = 0; idx < _buffers.size(); ++idx) { // // use textures? // if (_buffers[idx].enable) { ImageUnrecPtr texImg = (_buffers[idx].image == nullptr ? Image::create() : _buffers[idx].image); TextureObjChunkUnrecPtr texObj = (_buffers[idx].texObj == nullptr ? TextureObjChunk::create() : _buffers[idx].texObj); TextureBufferUnrecPtr texBuf = TextureBuffer::create(); if (_buffers[idx].image == nullptr) texImg->set(_buffers[idx].pixel_format, width, height, 1, 1, 1, 0.f, nullptr, _buffers[idx].type, _buffers[idx].main_memory); texObj->setImage(texImg); texBuf->setTexture(texObj); fbo->setColorAttachment(texBuf, idx); } else // // no, then use simple render buffer // { RenderBufferUnrecPtr renBuf = RenderBuffer::create(); renBuf->setInternalFormat(_buffers[idx].pixel_format); fbo->setColorAttachment(renBuf, idx); } fbo->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT + idx); } // // a sole depth buffer // if (_depth && !_stencil) { // // use textures? // if (_ds_buffer.enable) { ImageUnrecPtr texImg = (_ds_buffer.image == nullptr ? Image::create() : _ds_buffer.image); TextureObjChunkUnrecPtr texObj = (_ds_buffer.texObj == nullptr ? TextureObjChunk::create() : _ds_buffer.texObj); TextureBufferUnrecPtr texBuf = TextureBuffer::create(); if (_ds_buffer.image == nullptr) texImg->set(_ds_buffer.pixel_format, width, height, 1, 1, 1, 0.f, nullptr, _ds_buffer.type, _ds_buffer.main_memory); texObj->setImage(texImg); if (_ds_buffer.texObj == nullptr) { texObj->setInternalFormat(GL_DEPTH_COMPONENT24); texObj->setExternalFormat(GL_DEPTH_COMPONENT24); } texBuf->setTexture(texObj); fbo->setDepthAttachment(texBuf); } else // // no, then use simple render buffer // { RenderBufferUnrecPtr renBuf = RenderBuffer::create(); renBuf->setInternalFormat(GL_DEPTH_COMPONENT24); fbo->setDepthAttachment(renBuf); } } else // // or a combined depth/stencil buffer // if (_depth && _stencil) { // // use textures? // if (_ds_buffer.enable) { ImageUnrecPtr texImg = (_ds_buffer.image == nullptr ? Image::create() : _ds_buffer.image); TextureObjChunkUnrecPtr texObj = (_ds_buffer.texObj == nullptr ? TextureObjChunk::create() : _ds_buffer.texObj); TextureBufferUnrecPtr texBuf = TextureBuffer::create(); if (_ds_buffer.image == nullptr) texImg->set(GL_DEPTH_STENCIL_EXT, width, height, 1, 1, 1, 0.f, nullptr, GL_UNSIGNED_INT_24_8, _ds_buffer.main_memory); texObj->setImage(texImg); texObj->setInternalFormat(GL_DEPTH24_STENCIL8_EXT); texObj->setExternalFormat(GL_DEPTH_STENCIL_EXT); texBuf->setTexture(texObj); fbo->setDepthAttachment(texBuf); fbo->setStencilAttachment(texBuf); } else // // no, then use simple render buffer // { RenderBufferUnrecPtr renBuf = RenderBuffer::create(); renBuf->setInternalFormat(GL_DEPTH24_STENCIL8); fbo->setDepthAttachment(renBuf); fbo->setStencilAttachment(renBuf); } } fbo->setWidth (width ); fbo->setHeight(height); return FrameBufferObjectTransitPtr(fbo); }
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); }