void setupAnimation(void) { std::vector<BoostPath> _ImagePaths; _ImagePaths.push_back(BoostPath("./Data/Anim001.jpg")); _ImagePaths.push_back(BoostPath("./Data/Anim002.jpg")); _ImagePaths.push_back(BoostPath("./Data/Anim003.jpg")); _ImagePaths.push_back(BoostPath("./Data/Anim004.jpg")); _ImagePaths.push_back(BoostPath("./Data/Anim005.jpg")); //Make the textures for(UInt32 i(0) ; i<_ImagePaths.size(); ++i) { ImageUnrecPtr AnimFrameImage = ImageFileHandler::the()->read(_ImagePaths[i].string().c_str()); _Images.push_back(AnimFrameImage); } TextureObjChunkUnrecPtr AnimFrameTexture = TextureObjChunk::create(); AnimFrameTexture->setImage(_Images.front()); //Box Material MaterialChunkUnrecPtr TheMaterialChunk = MaterialChunk::create(); TheMaterialChunk->setAmbient(Color4f(0.4,0.4,0.4,1.0)); TheMaterialChunk->setDiffuse(Color4f(0.8,0.8,0.8,1.0)); TheMaterialChunk->setSpecular(Color4f(1.0,1.0,1.0,1.0)); TheBoxMaterial = ChunkMaterial::create(); TheBoxMaterial->addChunk(AnimFrameTexture); //Texture Keyframe Sequence KeyframeFCPtrSequenceUnrecPtr TextureKeyframes = KeyframeFCPtrSequenceImage::create(); for(UInt32 i(0) ; i<_Images.size(); ++i) { TextureKeyframes->addKeyframe(_Images[i],static_cast<Real32>(i)*0.5f); } //Animator TutorialTextureAnimator = KeyframeAnimator::create(); TutorialTextureAnimator->setKeyframeSequence(TextureKeyframes); //Animation TutorialTextureAnimation = FieldAnimation::create(); TutorialTextureAnimation->setAnimator(TutorialTextureAnimator); TutorialTextureAnimation->setInterpolationType(Animator::STEP_INTERPOLATION); TutorialTextureAnimation->setCycling(-1); TutorialTextureAnimation->setAnimatedField(AnimFrameTexture,TextureObjChunk::ImageFieldId); //Animation Listener TutorialTextureAnimation->addAnimationListener(&TutorialTextureAnimationListener); TutorialTextureAnimation->attachUpdateProducer(TutorialWindow->editEventProducer()); TutorialTextureAnimation->start(); }
void Graphics3DExtrude::drawQuad(const Pnt2f& p1, const Pnt2f& p2, const Pnt2f& p3, const Pnt2f& p4, const Vec2f& t1, const Vec2f& t2, const Vec2f& t3, const Vec2f& t4, const Color4f& color, const TextureObjChunkUnrecPtr Texture, const Real32& Opacity) const { Real32 Alpha( Opacity * getOpacity() * color.alpha()); if(Alpha < 1.0 || Texture->getImage()->hasAlphaChannel()) { //Setup the Blending equations properly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } if(Texture != NULL) { Texture->activate(getDrawEnv()); } glBegin(GL_QUADS); glColor4f(color.red(), color.green(), color.blue(), Alpha ); glTexCoord2fv(t1.getValues()); glVertex2fv(p1.getValues()); glTexCoord2fv(t2.getValues()); glVertex2fv(p2.getValues()); glTexCoord2fv(t3.getValues()); glVertex2fv(p3.getValues()); glTexCoord2fv(t4.getValues()); glVertex2fv(p4.getValues()); glEnd(); if(Texture != NULL) { Texture->deactivate(getDrawEnv()); } if(Alpha < 1.0 || Texture->getImage()->hasAlphaChannel()) { glDisable(GL_BLEND); } }
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); }
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); }
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); }