void ShaderShadowMapEngine::updateLightPassMaterial(SSMEngineData *data) { if(data->getMFLightPassMaterials()->empty() == true) { MaterialChunkUnrecPtr newMatChunk = MaterialChunk::createLocal(); newMatChunk->setLit (false ); newMatChunk->setColorMaterial(GL_NONE); ColorMaskChunkUnrecPtr newCMaskChunk = ColorMaskChunk::create(); newCMaskChunk->setMaskR(false); newCMaskChunk->setMaskG(false); newCMaskChunk->setMaskB(false); newCMaskChunk->setMaskA(false); PolygonChunkUnrecPtr newPolyChunk = PolygonChunk::createLocal(); newPolyChunk->setOffsetFill (true ); newPolyChunk->setOffsetFactor(this->getOffsetFactor()); newPolyChunk->setOffsetBias (this->getOffsetBias ()); ChunkMaterialUnrecPtr newLightPassMat = ChunkMaterial::createLocal(); newLightPassMat->addChunk(newMatChunk ); newLightPassMat->addChunk(newCMaskChunk); newLightPassMat->addChunk(newPolyChunk ); data->editMFLightPassMaterials()->push_back(newLightPassMat); } }
MaterialUnrecPtr Graphics3DExtrude::createDefaultMaterial(void) { 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(0.85,0.85,0.85,1.0)); TheMaterialChunk->setEmission(Color4f(0.0,0.0,0.0,1.0)); TheMaterialChunk->setShininess(50.0); TheMaterialChunk->setLit(true); TheMaterialChunk->setColorMaterial(true); ChunkMaterialUnrecPtr TheMaterial = ChunkMaterial::create(); TheMaterial->addChunk(TheMaterialChunk); return TheMaterial; }
void VTKPolyDataMapper::initGeometries(void) { NodeUnrecPtr pRoot = Node::create(); pRoot->setCore(Group::create()); setRoot(pRoot); for(UInt32 i = 0; i < 4; ++i) { GeometryUnrecPtr pGeo = Geometry::create(); ChunkMaterialUnrecPtr pMat = ChunkMaterial::create(); MaterialChunkUnrecPtr pMatChunk = MaterialChunk::create(); GeoPnt3fPropertyUnrecPtr pPoints = GeoPnt3fProperty ::create(); GeoUInt32PropertyUnrecPtr pLengths = GeoUInt32Property ::create(); GeoUInt8PropertyUnrecPtr pTypes = GeoUInt8Property ::create(); GeoColor4fPropertyUnrecPtr pColors = GeoColor4fProperty::create(); GeoVec3fPropertyUnrecPtr pNormals = GeoVec3fProperty ::create(); if(i < 2) { pMatChunk->setLit(false); } pMatChunk->setDiffuse (OSG::Color4f(1.0, 1.0, 1.0, 1.0)); pMatChunk->setSpecular (OSG::Color4f(0.0, 0.0, 0.0, 1.0)); pMatChunk->setShininess(10.0f); pMat->addChunk(pMatChunk); TwoSidedLightingChunkUnrecPtr pTSLChunk = TwoSidedLightingChunk::create(); pMat->addChunk(pTSLChunk); pGeo->setDlistCache(false ); pGeo->setMaterial (pMat ); pGeo->setPositions (pPoints ); pGeo->setLengths (pLengths); pGeo->setTypes (pTypes ); pGeo->setColors (pColors ); if(i > 1) { pGeo->setNormals(pNormals); } OSG::NodeUnrecPtr pGeoRoot = OSG::Node::create(); pGeoRoot->setCore (pGeo); pGeoRoot->setTravMask(0 ); pRoot->addChild(pGeoRoot); this->pushToGeometries (pGeo ); this->pushToMaterials (pMat ); this->pushToMaterialChunks(pMatChunk); this->pushToPositions (pPoints ); this->pushToLength (pLengths ); this->pushToTypes (pTypes ); this->pushToColors (pColors ); this->pushToNormals (pNormals ); this->pushToGeoRoots (pGeoRoot ); } }
HDRStageDataTransitPtr HDRStage::setupStageData(Int32 iPixelWidth, Int32 iPixelHeight) { HDRStageDataTransitPtr returnValue = HDRStageData::createLocal(); if(returnValue == NULL) return returnValue; OSG::Thread::setCurrentLocalFlags(); // Scene Target FrameBufferObjectUnrecPtr pSceneFBO = FrameBufferObject::createLocal(); RenderBufferUnrecPtr pDepthBuffer = RenderBuffer ::createLocal(); pDepthBuffer->setInternalFormat(GL_DEPTH_COMPONENT24 ); TextureObjChunkUnrecPtr pSceneTex = TextureObjChunk::createLocal(); TextureEnvChunkUnrecPtr pSceneTexEnv = TextureEnvChunk::createLocal(); ImageUnrecPtr pImg = Image ::createLocal(); pImg->set(Image::OSG_RGB_PF, iPixelWidth, iPixelHeight, 1, 1, 1, 0.0, 0, Image::OSG_FLOAT32_IMAGEDATA, false); pSceneTex ->setImage (pImg ); pSceneTex ->setMinFilter (GL_LINEAR ); pSceneTex ->setMagFilter (GL_LINEAR ); pSceneTex ->setWrapS (GL_CLAMP_TO_EDGE ); pSceneTex ->setWrapT (GL_CLAMP_TO_EDGE ); pSceneTex ->setInternalFormat(getBufferFormat()); pSceneTexEnv->setEnvMode (GL_REPLACE ); TextureBufferUnrecPtr pSceneTexBuffer = TextureBuffer::createLocal(); pSceneTexBuffer->setTexture(pSceneTex); pSceneFBO->setSize(iPixelWidth, iPixelHeight); pSceneFBO->setColorAttachment(pSceneTexBuffer, 0); pSceneFBO->setDepthAttachment(pDepthBuffer ); pSceneFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT); setRenderTarget(pSceneFBO); // Shrink Target (w/2, h/2) FrameBufferObjectUnrecPtr pShrinkFBO = FrameBufferObject::createLocal(); TextureObjChunkUnrecPtr pShrinkTex = TextureObjChunk::createLocal(); TextureEnvChunkUnrecPtr pShrinkTexEnv = TextureEnvChunk::createLocal(); pImg = Image ::createLocal(); pImg->set(Image::OSG_RGB_PF, iPixelWidth / 2, iPixelHeight / 2, 1, 1, 1, 0.0, 0, Image::OSG_FLOAT32_IMAGEDATA, false); pShrinkTex ->setImage (pImg ); pShrinkTex ->setMinFilter (GL_LINEAR ); pShrinkTex ->setMagFilter (GL_LINEAR ); pShrinkTex ->setWrapS (GL_CLAMP_TO_EDGE ); pShrinkTex ->setWrapT (GL_CLAMP_TO_EDGE ); pShrinkTex ->setInternalFormat(getBufferFormat()); pShrinkTexEnv->setEnvMode (GL_REPLACE ); TextureBufferUnrecPtr pShrinkTexBuffer = TextureBuffer::createLocal(); pShrinkTexBuffer->setTexture(pShrinkTex); pShrinkFBO->setSize(iPixelWidth / 2, iPixelHeight / 2); pShrinkFBO->setColorAttachment(pShrinkTexBuffer, 0); pShrinkFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT); returnValue->setShrinkRenderTarget(pShrinkFBO); // blur (w/4, h/4) FrameBufferObjectUnrecPtr pBlurFBO = FrameBufferObject::createLocal(); TextureObjChunkUnrecPtr pBlurTex1 = TextureObjChunk ::createLocal(); TextureEnvChunkUnrecPtr pBlurTex1Env = TextureEnvChunk ::createLocal(); pImg = Image::createLocal(); pImg->set(Image::OSG_RGB_PF, iPixelWidth / 4, iPixelHeight / 4, 1, 1, 1, 0.0, 0, Image::OSG_FLOAT32_IMAGEDATA, false); pBlurTex1 ->setImage (pImg ); pBlurTex1 ->setMinFilter (GL_LINEAR ); pBlurTex1 ->setMagFilter (GL_LINEAR ); pBlurTex1 ->setWrapS (GL_CLAMP_TO_EDGE ); pBlurTex1 ->setWrapT (GL_CLAMP_TO_EDGE ); pBlurTex1 ->setInternalFormat(getBufferFormat()); pBlurTex1Env->setEnvMode (GL_REPLACE ); TextureBufferUnrecPtr pBlurTexBuffer1 = TextureBuffer::createLocal(); pBlurTexBuffer1->setTexture(pBlurTex1); TextureObjChunkUnrecPtr pBlurTex2 = TextureObjChunk::createLocal(); TextureEnvChunkUnrecPtr pBlurTex2Env = TextureEnvChunk::createLocal(); pImg = Image::createLocal(); pImg->set(Image::OSG_RGB_PF, iPixelWidth / 4, iPixelHeight / 4, 1, 1, 1, 0.0, 0, Image::OSG_FLOAT32_IMAGEDATA, false); pBlurTex2 ->setImage (pImg ); pBlurTex2 ->setMinFilter (GL_LINEAR ); pBlurTex2 ->setMagFilter (GL_LINEAR ); pBlurTex2 ->setWrapS (GL_CLAMP_TO_EDGE ); pBlurTex2 ->setWrapT (GL_CLAMP_TO_EDGE ); pBlurTex2 ->setInternalFormat(getBufferFormat()); pBlurTex2Env->setEnvMode (GL_REPLACE ); TextureBufferUnrecPtr pBlurTexBuffer2 = TextureBuffer::createLocal(); pBlurTexBuffer2->setTexture(pBlurTex2); pBlurFBO->setSize(iPixelWidth / 4, iPixelHeight / 4); pBlurFBO->setColorAttachment(pBlurTexBuffer1, 0); pBlurFBO->setColorAttachment(pBlurTexBuffer2, 1); returnValue->setBlurRenderTarget(pBlurFBO); // general mat chunk MaterialChunkUnrecPtr pMatChunk = MaterialChunk::createLocal(); pMatChunk->setLit(false); // tone map material ChunkMaterialUnrecPtr pTonemapMat = ChunkMaterial ::createLocal(); pTonemapMat->addChunk(pMatChunk ); pTonemapMat->addChunk(pSceneTex, 0); pTonemapMat->addChunk(pSceneTexEnv, 0); pTonemapMat->addChunk(pBlurTex1, 1); pTonemapMat->addChunk(pBlurTex1Env, 1); SimpleSHLChunkUnrecPtr pTonemapShader = generateHDRFragmentProgram(); pTonemapShader->addUniformVariable("sceneTex", 0); pTonemapShader->addUniformVariable("blurTex", 1); pTonemapShader->addUniformVariable("blurAmount", getBlurAmount ()); pTonemapShader->addUniformVariable("exposure", getExposure ()); pTonemapShader->addUniformVariable("effectAmount", getEffectAmount()); pTonemapShader->addUniformVariable("gamma", getGamma ()); pTonemapMat->addChunk(pTonemapShader, 0); returnValue->setToneMappingMaterial(pTonemapMat); // Shrink material ChunkMaterialUnrecPtr pShrinkMat = ChunkMaterial::createLocal(); pShrinkMat->addChunk(pMatChunk ); pShrinkMat->addChunk(pSceneTex, 0); pShrinkMat->addChunk(pSceneTexEnv, 0); SimpleSHLChunkUnrecPtr pShrinkShader = generate2DShrinkHalfFilterFP(); pShrinkShader->addUniformVariable("inputTex", 0); pShrinkMat->addChunk(pShrinkShader, 0); returnValue->setShrinkMaterial(pShrinkMat); // Blur material ChunkMaterialUnrecPtr pBlurMat = ChunkMaterial::createLocal(); pBlurMat->addChunk(pMatChunk ); pBlurMat->addChunk(pShrinkTex, 0); pBlurMat->addChunk(pShrinkTexEnv, 0); pBlurMat->addChunk(pBlurTex1, 1); pBlurMat->addChunk(pBlurTex1Env, 1); pBlurMat->addChunk(pBlurTex2, 2); pBlurMat->addChunk(pBlurTex2Env, 2); pBlurMat->addChunk(pShrinkShader, 0); returnValue->setBlurMaterial(pBlurMat); // generate blur fragment programs SimpleSHLChunkUnrecPtr pHBlurShader = generate1DConvolutionFilterFP(getBlurWidth(), false, true, iPixelWidth / 2, iPixelHeight / 2); pHBlurShader->addUniformVariable("inputTex", 0); returnValue->setHBlurShader(pHBlurShader); // VBlur Override SimpleSHLChunkUnrecPtr pVBlurShader = generate1DConvolutionFilterFP(getBlurWidth(), true, true, iPixelWidth / 2, iPixelHeight / 2); pVBlurShader->addUniformVariable("inputTex", 1); returnValue->setVBlurShader(pVBlurShader); OSG::Thread::resetCurrentLocalFlags(); Thread::getCurrentChangeList()->commitChanges(); return returnValue; }
PostShaderStage::RenderPassData::RenderPassData(const std::string& VertexProgram, const std::string& FragmentProgram, bool isLastPass, UInt32 Index, Int32 iPixelWidth, Int32 iPixelHeight, PostShaderStageData *StageData, const Vec2f& FBOSize, TextureObjChunk* const SceneColorTex, TextureObjChunk* const SceneDepthTex, const RenderPassVector& Passes, FrameBufferObject* const SceneFBO) : _IsLassPass(isLastPass), _Index(Index), _FBOSize(FBOSize) { //If this pass is not the last if(!_IsLassPass) { _FBO = FrameBufferObject::createLocal(); _OutputTexture = TextureObjChunk::createLocal(); TextureEnvChunkUnrecPtr pTexEnv = TextureEnvChunk::createLocal(); ImageUnrecPtr pImg = Image ::createLocal(); pImg->set(Image::OSG_RGB_PF, static_cast<Real32>(iPixelWidth) * _FBOSize.x() , static_cast<Real32>(iPixelHeight) * _FBOSize.y(), 1, 1, 1, 0.0, 0, Image::OSG_UINT8_IMAGEDATA, false); _OutputTexture ->setImage (pImg ); _OutputTexture ->setMinFilter (GL_LINEAR ); _OutputTexture ->setMagFilter (GL_LINEAR ); _OutputTexture ->setWrapS (GL_CLAMP_TO_EDGE ); _OutputTexture ->setWrapT (GL_CLAMP_TO_EDGE ); _OutputTexture ->setInternalFormat(GL_RGB ); pTexEnv->setEnvMode (GL_REPLACE ); TextureBufferUnrecPtr pTexBuffer = TextureBuffer::createLocal(); pTexBuffer->setTexture(_OutputTexture); _FBO->setSize(static_cast<Real32>(iPixelWidth) * _FBOSize.x(), static_cast<Real32>(iPixelHeight) * _FBOSize.y()); _FBO->setColorAttachment(pTexBuffer, 0); _FBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT); StageData->pushToRenderTargets(_FBO); OSG_ASSERT(StageData->getMFRenderTargets()->size() == _Index+1); } else { _FBO = SceneFBO; } //Update the flags on what uniforms are present _ShaderHasSceneColorTex = ((FragmentProgram.find(PostShaderStage::ShaderSceneColorTexName) != std::string::npos) || (VertexProgram.find(PostShaderStage::ShaderSceneColorTexName) != std::string::npos)); _ShaderHasSceneDepthTex = ((FragmentProgram.find(PostShaderStage::ShaderSceneDepthTexName) != std::string::npos) || (VertexProgram.find(PostShaderStage::ShaderSceneDepthTexName) != std::string::npos)); _ShaderHasFBOWidth = ((FragmentProgram.find(PostShaderStage::ShaderFBOWidthName) != std::string::npos) || (VertexProgram.find(PostShaderStage::ShaderFBOWidthName) != std::string::npos)); _ShaderHasFBOHeight = ((FragmentProgram.find(PostShaderStage::ShaderFBOHeightName) != std::string::npos) || (VertexProgram.find(PostShaderStage::ShaderFBOHeightName) != std::string::npos)); _ShaderHasCameraNear = ((FragmentProgram.find(PostShaderStage::ShaderCameraNearName) != std::string::npos) || (VertexProgram.find(PostShaderStage::ShaderCameraNearName) != std::string::npos)); _ShaderHasCameraFar = ((FragmentProgram.find(PostShaderStage::ShaderCameraFarName) != std::string::npos) || (VertexProgram.find(PostShaderStage::ShaderCameraFarName) != std::string::npos)); //Create the material used by this pass ChunkMaterialUnrecPtr pPostShaderMat = ChunkMaterial ::createLocal(); UInt16 TextureId(0); _Shader = SimpleSHLChunk::createLocal(); TextureEnvChunkUnrecPtr pGenericTexEnv = TextureEnvChunk::createLocal(); pGenericTexEnv->setEnvMode(GL_REPLACE); //Scene Color Texture if(_ShaderHasSceneColorTex) { pPostShaderMat->addChunk(SceneColorTex, TextureId); pPostShaderMat->addChunk(pGenericTexEnv, TextureId); _Shader->addUniformVariable(PostShaderStage::ShaderSceneColorTexName.c_str(), TextureId); ++TextureId; } //Scene Depth Texture if(_ShaderHasSceneDepthTex) { pPostShaderMat->addChunk(SceneDepthTex, TextureId); pPostShaderMat->addChunk(pGenericTexEnv, TextureId); _Shader->addUniformVariable(PostShaderStage::ShaderSceneDepthTexName.c_str(), TextureId); ++TextureId; } _HeightRefs.clear(); _WidthRefs.clear(); //Preceding passes variables std::string VariableName; for(RenderPassVector::const_iterator PassItor(Passes.begin()) ; PassItor != Passes.end() ; ++PassItor) { VariableName = (*PassItor)->getOutputTextureName(); if((FragmentProgram.find(VariableName) != std::string::npos) || (VertexProgram.find(VariableName) != std::string::npos)) { pPostShaderMat->addChunk((*PassItor)->getOutputTexture(), TextureId); pPostShaderMat->addChunk(pGenericTexEnv, TextureId); _Shader->addUniformVariable(VariableName.c_str(), TextureId); ++TextureId; } VariableName = (*PassItor)->getWidthName(); if((FragmentProgram.find(VariableName) != std::string::npos) || (VertexProgram.find(VariableName) != std::string::npos)) { _Shader->addUniformVariable<Real32>(VariableName.c_str(), (*PassItor)->getOutputTexture()->getImage()->getWidth()); _WidthRefs.push_back((*PassItor)->getIndex()); } VariableName = (*PassItor)->getHeightName(); if((FragmentProgram.find(VariableName) != std::string::npos) || (VertexProgram.find(VariableName) != std::string::npos)) { _Shader->addUniformVariable<Real32>(VariableName.c_str(), (*PassItor)->getOutputTexture()->getImage()->getHeight()); _HeightRefs.push_back((*PassItor)->getIndex()); } } MaterialChunkUnrecPtr pMatChunk = MaterialChunk::createLocal(); pMatChunk->setLit(false); pPostShaderMat->addChunk(pMatChunk); _Shader->setVertexProgram(VertexProgram); _Shader->setFragmentProgram(FragmentProgram); //Add the uniform parameters _Shader->addUniformVariable(ShaderFBOWidthName.c_str(), 0.0f); _Shader->addUniformVariable(ShaderFBOHeightName.c_str(), 0.0f); _Shader->addUniformVariable(ShaderCameraNearName.c_str(), 0.0f); _Shader->addUniformVariable(ShaderCameraFarName.c_str(), 1.0f); pPostShaderMat->addChunk(_Shader, 0); StageData->pushToShaderMaterials(pPostShaderMat); OSG_ASSERT(StageData->getMFShaderMaterials()->size() == _Index+1); }