TextureBufferTransitPtr DeferredShadingStage::createGBuffer( UInt32 index, Int32 width, Int32 height) { TextureBufferTransitPtr buf = TextureBuffer ::createLocal(); TextureObjChunkUnrecPtr bufTex = TextureObjChunk::createLocal(); ImageUnrecPtr bufImg = Image ::createLocal(); bufImg->set(_mfPixelFormats[index], width, height, 1, 1, 1, 0.0f, NULL, _mfPixelTypes[index], false, 1); bufTex->setImage (bufImg ); bufTex->setTarget (GL_TEXTURE_RECTANGLE_ARB); bufTex->setMinFilter(GL_NEAREST ); bufTex->setMagFilter(GL_NEAREST ); bufTex->setWrapS (GL_CLAMP ); bufTex->setWrapT (GL_CLAMP ); bufTex->setScale (false ); buf ->setTexture (bufTex ); // START DEBUG GLenum internalFormat; GLenum externalFormat; bufTex->determineFormats(internalFormat, externalFormat); FLOG(("DSStage::createGBuffer: IF [%s] EF [%s]\n", GLDefineMapper::the()->toString(internalFormat).c_str(), GLDefineMapper::the()->toString(externalFormat).c_str() )); // END DEBUG return buf; }
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); } }
void ColorDisplayFilter::process(DisplayFilterStageData *pData) { SimpleSHLChunk *pShader = pData->getColorFilterShader(); if(pShader == NULL || this->getFilterShader() != pShader) { pShader = this->getFilterShader(); OSG_ASSERT(pShader != NULL); ChunkMaterial *pCMat = pData->getBaseMaterial(); OSG_ASSERT(pCMat != NULL); pCMat->addChunk(pShader); commitChanges(); pData->setColorFilterShader(pShader); } TextureObjChunk *pColTex = pData->getColorFilterTexture(); if(pData->getInitColTableFrom() != this) { if(pColTex == NULL) { TextureObjChunkUnrecPtr pTex = TextureObjChunk::createLocal(); pTex->setMinFilter(GL_LINEAR ); pTex->setMagFilter(GL_LINEAR ); pTex->setWrapS (GL_CLAMP_TO_EDGE ); pTex->setWrapT (GL_CLAMP_TO_EDGE ); pTex->setWrapR (GL_CLAMP_TO_EDGE ); pData->setColorFilterTexture(pTex); ChunkMaterial *pCMat = pData->getBaseMaterial(); OSG_ASSERT(pCMat != NULL); pCMat->addChunk(pTex, 1); pColTex = pTex; } pData->setInitColTableFrom(this); pColTex->setImage(this->getTableImage()); commitChanges(); } OSG_ASSERT(pShader != NULL); OSG_ASSERT(pColTex != NULL); pShader->setIgnore(false); pColTex->setIgnore(false); }
DepthPeelingStageDataTransitPtr DepthPeelingStage::setupStageData(Int32 iPixelWidth, Int32 iPixelHeight) { DepthPeelingStageDataTransitPtr returnValue = DepthPeelingStageData::createLocal(); if(returnValue == NULL) return returnValue; OSG::Thread::setCurrentLocalFlags(); //Depth, Blend chunks and Background in Data? DepthChunkUnrecPtr pDepthOffChunk = DepthChunk::createLocal(); pDepthOffChunk->setEnable(false); DepthChunkUnrecPtr pDepthOnChunk = DepthChunk::createLocal(); pDepthOnChunk->setEnable(true); returnValue->setDepthChunk(pDepthOnChunk); ShaderProgramVariableChunkUnrecPtr pSPVChunk1 = ShaderProgramVariableChunk::createLocal(); pSPVChunk1->addUniformVariable("uIsPeelPass", true); returnValue->setSpvIsPeelChunk(pSPVChunk1); ShaderProgramVariableChunkUnrecPtr pSPVChunk2 = ShaderProgramVariableChunk::createLocal(); pSPVChunk2->addUniformVariable("uIsPeelPass", false); returnValue->setSpvIsInitialChunk(pSPVChunk2); BlendChunkUnrecPtr pBlendChunk = BlendChunk::createLocal(); pBlendChunk->setSrcFactor(GL_DST_ALPHA); pBlendChunk->setDestFactor(GL_ONE); pBlendChunk->setAlphaSrcFactor(GL_ZERO); pBlendChunk->setAlphaDestFactor(GL_ONE_MINUS_SRC_ALPHA); pBlendChunk->setEquation(GL_FUNC_ADD); SolidBackgroundUnrecPtr pSolidBackground = SolidBackground::createLocal(); pSolidBackground->setColor(Color3f(0.f, 0.f, 0.f)); pSolidBackground->setAlpha(0.f); returnValue->setBackground(pSolidBackground); SimpleSHLChunkUnrecPtr pQuadShader = SimpleSHLChunk::createLocal(); pQuadShader->setFragmentProgram(std::string(blendFS)); pQuadShader->addUniformVariable("uSampler", 0); //2 FBOs (Ping-Pong) FrameBufferObjectUnrecPtr pPeelFBOs[2]; TextureBufferUnrecPtr pPeelColorTexBuffers[2]; TextureBufferUnrecPtr pPeelDepthTexBuffers[2]; TextureObjChunkUnrecPtr pColorTexs[2]; ImageUnrecPtr pColorImgs[2]; TextureObjChunkUnrecPtr pDepthTexs[2]; ImageUnrecPtr pDepthImgs[2]; for (int i=0; i<2; ++i) { //Color textures pColorTexs[i] = TextureObjChunk::createLocal(); pColorImgs[i] = Image ::createLocal(); pColorImgs[i]->set(Image::OSG_RGBA_PF, iPixelWidth, iPixelHeight, 1, 1, 1, 0.0, 0, Image::OSG_FLOAT32_IMAGEDATA, false); pColorTexs[i] ->setImage (pColorImgs[i] ); pColorTexs[i] ->setMinFilter (GL_NEAREST ); pColorTexs[i] ->setMagFilter (GL_NEAREST ); pColorTexs[i] ->setWrapS (GL_CLAMP_TO_EDGE ); pColorTexs[i] ->setWrapT (GL_CLAMP_TO_EDGE ); pColorTexs[i] ->setInternalFormat(GL_RGBA8); pPeelColorTexBuffers[i] = TextureBuffer::createLocal(); pPeelColorTexBuffers[i]->setTexture(pColorTexs[i]); //Depth textures pDepthTexs[i] = TextureObjChunk::createLocal(); pDepthImgs[i] = Image ::createLocal(); pDepthImgs[i]->set(Image::OSG_DEPTH_PF, iPixelWidth, iPixelHeight, 1, 1, 1, 0.0, 0, Image::OSG_FLOAT32_IMAGEDATA, false); pDepthTexs[i] ->setImage (pDepthImgs[i] ); pDepthTexs[i] ->setMinFilter (GL_NEAREST ); pDepthTexs[i] ->setMagFilter (GL_NEAREST ); pDepthTexs[i] ->setWrapS (GL_CLAMP_TO_EDGE ); pDepthTexs[i] ->setWrapT (GL_CLAMP_TO_EDGE ); pDepthTexs[i] ->setInternalFormat(GL_DEPTH_COMPONENT32F); pDepthTexs[i] ->setExternalFormat(GL_DEPTH_COMPONENT); pPeelDepthTexBuffers[i] = TextureBuffer::createLocal(); pPeelDepthTexBuffers[i]->setTexture(pDepthTexs[i]); pPeelFBOs[i] = FrameBufferObject::createLocal(); pPeelFBOs[i]->setSize(iPixelWidth, iPixelHeight); pPeelFBOs[i]->setColorAttachment(pPeelColorTexBuffers[i], 0); pPeelFBOs[i]->setDepthAttachment(pPeelDepthTexBuffers[i]); pPeelFBOs[i]->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT); //Peel material for Quad (!) ChunkMaterialUnrecPtr pPeelMat = ChunkMaterial ::createLocal(); pPeelMat->addChunk(pQuadShader, 0); pPeelMat->addChunk(pColorTexs[i], 0); pPeelMat->addChunk(pDepthOffChunk); pPeelMat->addChunk(pBlendChunk); if (i == 0) { returnValue->setPeelPingFBO(pPeelFBOs[i]); returnValue->setPeelPingMaterial(pPeelMat); } else { returnValue->setPeelPongFBO(pPeelFBOs[i]); returnValue->setPeelPongMaterial(pPeelMat); } } // The final color blend target FrameBufferObjectUnrecPtr pBlendFBO = FrameBufferObject::createLocal(); //Color texture TextureObjChunkUnrecPtr pBlendColorTex = TextureObjChunk::createLocal(); ImageUnrecPtr pBlendColorImg = Image ::createLocal(); pBlendColorImg->set(Image::OSG_RGBA_PF, iPixelWidth, iPixelHeight, 1, 1, 1, 0.0, 0, Image::OSG_FLOAT32_IMAGEDATA, false); pBlendColorTex->setImage (pBlendColorImg ); pBlendColorTex->setMinFilter (GL_NEAREST ); pBlendColorTex->setMagFilter (GL_NEAREST ); pBlendColorTex->setWrapS (GL_CLAMP_TO_EDGE ); pBlendColorTex->setWrapT (GL_CLAMP_TO_EDGE ); pBlendColorTex->setInternalFormat(GL_RGBA8); TextureBufferUnrecPtr pBlendColorTexBuffer = TextureBuffer::createLocal(); pBlendColorTexBuffer->setTexture(pBlendColorTex); TextureBufferUnrecPtr pBlendDepthTexBuffer = TextureBuffer::createLocal(); pBlendDepthTexBuffer->setTexture(pDepthTexs[0]); pBlendFBO->setSize(iPixelWidth, iPixelHeight); pBlendFBO->setColorAttachment(pBlendColorTexBuffer, 0); pBlendFBO->setDepthAttachment(pBlendDepthTexBuffer); pBlendFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT); returnValue->setBlendFBO(pBlendFBO); // Blend Final Material ChunkMaterialUnrecPtr pBlendFinalMat = ChunkMaterial::createLocal(); pBlendFinalMat->addChunk(pDepthOffChunk); pBlendFinalMat->addChunk(pBlendColorTex, 0); SimpleSHLChunkUnrecPtr pBlendFinalShader = SimpleSHLChunk::createLocal(); pBlendFinalShader->setFragmentProgram(std::string(blendFinalFS)); pBlendFinalShader->addUniformVariable("uSampler", 0); pBlendFinalMat->addChunk(pBlendFinalShader, 0); returnValue->setBlendFinalMaterial(pBlendFinalMat); OSG::Thread::resetCurrentLocalFlags(); Thread::getCurrentChangeList()->commitChanges(); return returnValue; }
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); }