//----------------------------------------------------------------------- void CompositorChain::setCompositorEnabled(size_t position, bool state) { CompositorInstance* inst = getCompositor(position); if (!state && inst->getEnabled()) { // If we're disabling a 'middle' compositor in a chain, we have to be // careful about textures which might have been shared by non-adjacent // instances which have now become adjacent. CompositorInstance* nextInstance = getNextInstance(inst, true); if (nextInstance) { CompositionTechnique::TargetPassIterator tpit = nextInstance->getTechnique()->getTargetPassIterator(); while(tpit.hasMoreElements()) { CompositionTargetPass* tp = tpit.getNext(); if (tp->getInputMode() == CompositionTargetPass::IM_PREVIOUS) { if (nextInstance->getTechnique()->getTextureDefinition(tp->getOutputName())->pooled) { // recreate nextInstance->freeResources(false, true); nextInstance->createResources(false); } } } } } inst->setEnabled(state); }
void TerrainManager::fixCompositorClearColor() { // hack // now with extensive error checking if (CompositorManager::getSingleton().hasCompositorChain(gEnv->mainCamera->getViewport())) { // //CompositorManager::getSingleton().getCompositorChain(gEnv->ogreCamera->getViewport())->getCompositor(0)->getTechnique()->getOutputTargetPass()->getPass(0)->setClearColour(fade_color); CompositorInstance *co = CompositorManager::getSingleton().getCompositorChain(gEnv->mainCamera->getViewport())->_getOriginalSceneCompositor(); if (co) { CompositionTechnique *ct = co->getTechnique(); if (ct) { CompositionTargetPass *ctp = ct->getOutputTargetPass(); if (ctp) { CompositionPass *p = ctp->getPass(0); if (p) { p->setClearColour(fade_color); } } } } } }
void HDRCompositor::CalculateKey(void) { CompositionTargetPass *tp; CompositionPass *pass; CreateTextureDef("Key",1,1,PF_FLOAT16_RGB); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Key"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); if(m_AutoKeying) { pass->setMaterialName("AutoKey"); pass->setInput(0,"Luminance"); } else { pass->setIdentifier(MID_KEY); pass->setMaterialName("ManualKey"); // GpuProgramParameters::RealConstantEntry* entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("Key"); // if(entry) // entry->val[0] = m_Key; } }
//----------------------------------------------------------------------- void CompositorChain::createOriginalScene() { /// Create "default" compositor /** Compositor that is used to implicitly represent the original render in the chain. This is an identity compositor with only an output pass: compositor Ogre/Scene { technique { target_output { pass clear { /// Clear frame } pass render_scene { visibility_mask FFFFFFFF render_queues SKIES_EARLY SKIES_LATE } } } }; */ mOriginalSceneScheme = mViewport->getMaterialScheme(); String compName = "Ogre/Scene/" + mOriginalSceneScheme; CompositorPtr scene = CompositorManager::getSingleton().getByName(compName, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME); if (scene.isNull()) { scene = CompositorManager::getSingleton().create(compName, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME); CompositionTechnique *t = scene->createTechnique(); t->setSchemeName(StringUtil::BLANK); CompositionTargetPass *tp = t->getOutputTargetPass(); tp->setVisibilityMask(0xFFFFFFFF); { CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_CLEAR); } { CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERSCENE); /// Render everything, including skies pass->setFirstRenderQueue(RENDER_QUEUE_BACKGROUND); pass->setLastRenderQueue(RENDER_QUEUE_SKIES_LATE); } /// Create base "original scene" compositor scene = CompositorManager::getSingleton().load(compName, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME); } mOriginalScene = OGRE_NEW CompositorInstance(scene->getSupportedTechnique(), this); }
void HDRCompositor::Create(void) { Release(); m_Compositor = CompositorManager::getSingleton().create("HDR", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); m_HDRTechnique = m_Compositor->createTechnique(); //render scene CreateTextureDef("Scene",0,0,PF_FLOAT16_RGB); CompositionTargetPass *tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_PREVIOUS); tp->setOutputName("Scene"); RenderDownSample(); CalculateLuminance(); CalculateKey(); if(m_GlareType || m_StarType) { BrightPass(); if(m_GlareType) BuildGlare(); if(m_StarType) BuildStar(); } if(m_ToneMapper == TM_REINHARDLOCAL) BuildScales(); FinalRendering(); Viewport* const vp = m_Window->getViewport(0); Ogre::CompositorInstance* const instance = CompositorManager::getSingleton().addCompositor(vp, "HDR"); if(instance) instance->addListener(this); notifyViewportSize(vp->getActualWidth(), vp->getActualHeight()); Enable(m_Enable); }
//--------------------------------------------------------------------- bool CompositorManager::isInputPreviousTarget(CompositorInstance* inst, const Ogre::String& localName) { CompositionTechnique::TargetPassIterator tpit = inst->getTechnique()->getTargetPassIterator(); while(tpit.hasMoreElements()) { CompositionTargetPass* tp = tpit.getNext(); if (tp->getInputMode() == CompositionTargetPass::IM_PREVIOUS && tp->getOutputName() == localName) { return true; } } return false; }
//----------------------------------------------------------------------- void CompositorChain::preViewportUpdate(const RenderTargetViewportEvent& evt) { // Only set up if there is at least one compositor enabled, and it's this viewport if(evt.source != mViewport || !mAnyCompositorsEnabled) return; // set original scene details from viewport CompositionPass* pass = mOriginalScene->getTechnique()->getOutputTargetPass()->getPass(0); CompositionTargetPass* passParent = pass->getParent(); if (pass->getClearBuffers() != mViewport->getClearBuffers() || pass->getClearColour() != mViewport->getBackgroundColour() || passParent->getVisibilityMask() != mViewport->getVisibilityMask() || passParent->getMaterialScheme() != mViewport->getMaterialScheme() || passParent->getShadowsEnabled() != mViewport->getShadowsEnabled()) { // recompile if viewport settings are different pass->setClearBuffers(mViewport->getClearBuffers()); pass->setClearColour(mViewport->getBackgroundColour()); passParent->setVisibilityMask(mViewport->getVisibilityMask()); passParent->setMaterialScheme(mViewport->getMaterialScheme()); passParent->setShadowsEnabled(mViewport->getShadowsEnabled()); _compile(); } Camera *cam = mViewport->getCamera(); if (cam) { /// Prepare for output operation preTargetOperation(mOutputOperation, mViewport, cam); } }
//----------------------------------------------------------------------- void CompositorInstance::_compileTargetOperations(CompiledState &compiledState) { /// Collect targets of previous state if(mPreviousInstance) mPreviousInstance->_compileTargetOperations(compiledState); /// Texture targets CompositionTechnique::TargetPassIterator it = mTechnique->getTargetPassIterator(); while(it.hasMoreElements()) { CompositionTargetPass *target = it.getNext(); TargetOperation ts(getTargetForTex(target->getOutputName())); /// Set "only initial" flag, visibilityMask and lodBias according to CompositionTargetPass. ts.onlyInitial = target->getOnlyInitial(); ts.visibilityMask = target->getVisibilityMask(); ts.lodBias = target->getLodBias(); ts.shadowsEnabled = target->getShadowsEnabled(); /// Check for input mode previous if(target->getInputMode() == CompositionTargetPass::IM_PREVIOUS) { /// Collect target state for previous compositor /// The TargetOperation for the final target is collected seperately as it is merged /// with later operations mPreviousInstance->_compileOutputOperation(ts); } /// Collect passes of our own target collectPasses(ts, target); compiledState.push_back(ts); } }
//--------------------------------------------------------------------- bool CompositorManager::isInputToOutputTarget(CompositorInstance* inst, const Ogre::String& localName) { CompositionTargetPass* tp = inst->getTechnique()->getOutputTargetPass(); CompositionTargetPass::PassIterator pit = tp->getPassIterator(); while(pit.hasMoreElements()) { CompositionPass* p = pit.getNext(); for (size_t i = 0; i < p->getNumInputs(); ++i) { if (p->getInput(i).name == localName) return true; } } return false; }
//---------------------------------------------------------------------() bool CompositorManager::isInputToOutputTarget(CompositorInstance* inst, TexturePtr tex) { CompositionTargetPass* tp = inst->getTechnique()->getOutputTargetPass(); CompositionTargetPass::PassIterator pit = tp->getPassIterator(); while(pit.hasMoreElements()) { CompositionPass* p = pit.getNext(); for (size_t i = 0; i < p->getNumInputs(); ++i) { TexturePtr t = inst->getTextureInstance(p->getInput(i).name, 0); if (!t.isNull() && t.get() == tex.get()) return true; } } return false; }
//--------------------------------------------------------------------- bool CompositorManager::isInputPreviousTarget(CompositorInstance* inst, TexturePtr tex) { CompositionTechnique::TargetPassIterator tpit = inst->getTechnique()->getTargetPassIterator(); while(tpit.hasMoreElements()) { CompositionTargetPass* tp = tpit.getNext(); if (tp->getInputMode() == CompositionTargetPass::IM_PREVIOUS) { // Don't have to worry about an MRT, because no MRT can be input previous TexturePtr t = inst->getTextureInstance(tp->getOutputName(), 0); if (!t.isNull() && t.get() == tex.get()) return true; } } return false; }
//----------------------------------------------------------------------- void CompositorInstance::_compileOutputOperation(TargetOperation &finalState) { /// Final target CompositionTargetPass *tpass = mTechnique->getOutputTargetPass(); /// Logical-and together the visibilityMask, and multiply the lodBias finalState.visibilityMask &= tpass->getVisibilityMask(); finalState.lodBias *= tpass->getLodBias(); if(tpass->getInputMode() == CompositionTargetPass::IM_PREVIOUS) { /// Collect target state for previous compositor /// The TargetOperation for the final target is collected seperately as it is merged /// with later operations mPreviousInstance->_compileOutputOperation(finalState); } /// Collect passes collectPasses(finalState, tpass); }
//----------------------------------------------------------------------- void CompositorManager::initialise(void) { /// Create "default" compositor /** Compositor that is used to implicitly represent the original render in the chain. This is an identity compositor with only an output pass: compositor Ogre/Scene { technique { target_output { pass clear { /// Clear frame } pass render_scene { visibility_mask FFFFFFFF render_queues SKIES_EARLY SKIES_LATE } } } }; */ CompositorPtr scene = create("Ogre/Scene", ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME); CompositionTechnique *t = scene->createTechnique(); CompositionTargetPass *tp = t->getOutputTargetPass(); tp->setVisibilityMask(0xFFFFFFFF); { CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_CLEAR); } { CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERSCENE); /// Render everything, including skies pass->setFirstRenderQueue(RENDER_QUEUE_SKIES_EARLY); pass->setLastRenderQueue(RENDER_QUEUE_SKIES_LATE); } }
void HDRCompositor::RenderDownSample(void) { CompositionTargetPass* tp; CompositionPass* pass; //Downscale4 CreateTextureDef("scenedown4",m_VpWidth/4,m_VpHeight/4,PF_FLOAT16_RGB); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("scenedown4"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Down4"); pass->setInput(0,"Scene",0); pass->setIdentifier(MID_DOWN); // GpuProgramParameters::RealConstantEntry* entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("rcpScreenSize"); // entry->val[0] = 1.f/m_Window->getWidth(); // entry->val[1] = 1.f/m_Window->getHeight(); }
void _init(void) { CompositorPtr compositor = CompositorManager::getSingleton().create( _theType(), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); CompositionTechnique *t; CompositionTechnique::TextureDefinition *td; CompositionTargetPass *tp; CompositionPass *pass; t = compositor->createTechnique(); td = t->createTextureDefinition("scene"); td->width.viewport = 1; td->height.viewport = 1; td->format = PF_X8R8G8B8; td = t->createTextureDefinition("heat"); td->width.viewport = 0.5; td->height.viewport = 0.5; td->format = PF_X8R8G8B8; tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_PREVIOUS); tp->setOutputName("scene"); tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("heat"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("PostFilters/HeatVision/LightToHeat"); pass->setInput(0, "scene"); pass->setIdentifier(0xDEADBADE); tp = t->getOutputTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("PostFilters/HeatVision/Blur"); pass->setInput(0, "heat"); }
//----------------------------------------------------------------------- bool CompositionTechnique::isSupported(bool acceptTextureDegradation) { // A technique is supported if all materials referenced have a supported // technique, and the intermediate texture formats requested are supported // Material support is a cast-iron requirement, but if no texture formats // are directly supported we can let the rendersystem create the closest // match for the least demanding technique // Check output target pass is supported if (!mOutputTarget->_isSupported()) { return false; } // Check all target passes is supported TargetPasses::iterator pi, piend; piend = mTargetPasses.end(); for (pi = mTargetPasses.begin(); pi != piend; ++pi) { CompositionTargetPass* targetPass = *pi; if (!targetPass->_isSupported()) { return false; } } TextureDefinitions::iterator i, iend; iend = mTextureDefinitions.end(); TextureManager& texMgr = TextureManager::getSingleton(); for (i = mTextureDefinitions.begin(); i != iend; ++i) { TextureDefinition* td = *i; // Firstly check MRTs if (td->formatList.size() > Root::getSingleton().getRenderSystem()->getCapabilities()->getNumMultiRenderTargets()) { return false; } for (PixelFormatList::iterator pfi = td->formatList.begin(); pfi != td->formatList.end(); ++pfi) { // Check whether equivalent supported if(acceptTextureDegradation) { // Don't care about exact format so long as something is supported if(texMgr.getNativeFormat(TEX_TYPE_2D, *pfi, TU_RENDERTARGET) == PF_UNKNOWN) { return false; } } else { // Need a format which is the same number of bits to pass if (!texMgr.isEquivalentFormatSupported(TEX_TYPE_2D, *pfi, TU_RENDERTARGET)) { return false; } } } //Check all render targets have same number of bits if( !Root::getSingleton().getRenderSystem()->getCapabilities()-> hasCapability( RSC_MRT_DIFFERENT_BIT_DEPTHS ) && !td->formatList.empty() ) { PixelFormat nativeFormat = texMgr.getNativeFormat( TEX_TYPE_2D, td->formatList.front(), TU_RENDERTARGET ); size_t nativeBits = PixelUtil::getNumElemBits( nativeFormat ); for( PixelFormatList::iterator pfi = td->formatList.begin()+1; pfi != td->formatList.end(); ++pfi ) { PixelFormat nativeTmp = texMgr.getNativeFormat( TEX_TYPE_2D, *pfi, TU_RENDERTARGET ); if( PixelUtil::getNumElemBits( nativeTmp ) != nativeBits ) { return false; } } } } // Must be ok return true; }
//--------------------------------------------------------------------- void CompositorInstance::deriveTextureRenderTargetOptions( const String& texname, bool *hwGammaWrite, uint *fsaa) { // search for passes on this texture def that either include a render_scene // or use input previous bool renderingScene = false; CompositionTechnique::TargetPassIterator it = mTechnique->getTargetPassIterator(); while (it.hasMoreElements()) { CompositionTargetPass* tp = it.getNext(); if (tp->getOutputName() == texname) { if (tp->getInputMode() == CompositionTargetPass::IM_PREVIOUS) { // this may be rendering the scene implicitly // Can't check mPreviousInstance against mChain->_getOriginalSceneCompositor() // at this time, so check the position CompositorChain::InstanceIterator instit = mChain->getCompositors(); renderingScene = true; while(instit.hasMoreElements()) { CompositorInstance* inst = instit.getNext(); if (inst == this) break; else if (inst->getEnabled()) { // nope, we have another compositor before us, this will // be doing the AA renderingScene = false; } } if (renderingScene) break; } else { // look for a render_scene pass CompositionTargetPass::PassIterator pit = tp->getPassIterator(); while(pit.hasMoreElements()) { CompositionPass* pass = pit.getNext(); if (pass->getType() == CompositionPass::PT_RENDERSCENE) { renderingScene = true; break; } } } } } if (renderingScene) { // Ok, inherit settings from target RenderTarget* target = mChain->getViewport()->getTarget(); *hwGammaWrite = target->isHardwareGammaEnabled(); *fsaa = target->getFSAA(); } else { *hwGammaWrite = false; *fsaa = 0; } }
void _init(void) { CompositorPtr compositor = CompositorManager::getSingleton().create( _theType(), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); CompositionTechnique *t; CompositionTechnique::TextureDefinition *td; CompositionTargetPass *tp; CompositionPass *pass; t = compositor->createTechnique(); td = t->createTextureDefinition("scene"); td->width.viewport = 1; td->height.viewport = 1; td->format = PF_X8R8G8B8; td = t->createTextureDefinition("blur0"); td->width.viewport = 0.5; td->height.viewport = 0.5; td->format = PF_X8R8G8B8; td = t->createTextureDefinition("blur1"); td->width.viewport = 0.5; td->height.viewport = 0.5; td->format = PF_X8R8G8B8; tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_PREVIOUS); tp->setOutputName("scene"); tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("blur0"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("PostFilters/Floodlighting/DownSample"); pass->setInput(0, "scene"); tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("blur1"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("PostFilters/Floodlighting/BlurHorizontal"); pass->setInput(0, "blur0"); tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("blur1"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("PostFilters/Floodlighting/BlurVertical"); pass->setInput(0, "blur0"); tp = t->getOutputTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("PostFilters/Floodlighting/Blend"); pass->setInput(0, "scene"); pass->setInput(1, "blur1"); pass->setIdentifier(0xDEADBADE); mBlurAmount = 0.2f; mShineAmount = 0.3f; // receive default parameters from material script if (!pass->getMaterial().isNull()) { GpuProgramParametersSharedPtr parameters = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters(); #if OGRE_VERSION >= 0x010300 const GpuConstantDefinition* def; def = parameters->_findNamedConstantDefinition("blur_amount"); if (def) parameters->_readRawConstants(def->physicalIndex, 1, &mBlurAmount); def = parameters->_findNamedConstantDefinition("shine_amount"); if (def) parameters->_readRawConstants(def->physicalIndex, 1, &mShineAmount); #else GpuProgramParameters::RealConstantEntry* entry; entry = parameters->getNamedRealConstantEntry("blur_amount"); if (entry && entry->isSet) mBlurAmount = entry->val[0]; entry = parameters->getNamedRealConstantEntry("shine_amount"); if (entry && entry->isSet) mShineAmount = entry->val[0]; #endif } }
//------------------------------------------------------------------------------------- void BaseApp::recreateCompositor() { CompositorManager& cmp = CompositorManager::getSingleton(); if (!pSet->all_effects) // disable compositor { refreshCompositor(); return; } // add when needed if (!ResourceGroupManager::getSingleton().resourceGroupExists("Effects")) { std::string sPath = PATHMANAGER::Data() + "/compositor"; mRoot->addResourceLocation(sPath, "FileSystem", "Effects"); mRoot->addResourceLocation(sPath + "/gbuffer", "FileSystem", "Effects"); mRoot->addResourceLocation(sPath + "/bloom", "FileSystem", "Effects"); mRoot->addResourceLocation(sPath + "/hdr", "FileSystem", "Effects"); mRoot->addResourceLocation(sPath + "/motionblur", "FileSystem", "Effects"); //mRoot->addResourceLocation(sPath + "/camblur", "FileSystem", "Effects"); mRoot->addResourceLocation(sPath + "/ssao", "FileSystem", "Effects"); mRoot->addResourceLocation(sPath + "/softparticles", "FileSystem", "Effects"); mRoot->addResourceLocation(sPath + "/dof", "FileSystem", "Effects"); mRoot->addResourceLocation(sPath + "/godrays", "FileSystem", "Effects"); mRoot->addResourceLocation(sPath + "/filmgrain", "FileSystem", "Effects"); ResourceGroupManager::getSingleton().initialiseResourceGroup("Effects"); } // hdr has to be first in the compositor queue if (!mHDRLogic) { mHDRLogic = new HDRLogic; cmp.registerCompositorLogic("HDR", mHDRLogic); mHDRLogic->setApp(this); } if (!mSSAOLogic) { mSSAOLogic = new SSAOLogic(); mSSAOLogic->setApp(this); //if(MaterialGenerator::MRTSupported()) if (1) CompositorManager::getSingleton().registerCompositorLogic("ssao", mSSAOLogic); else cmp.registerCompositorLogic("ssaoNoMRT", mSSAOLogic); } if (!mGodRaysLogic) { mGodRaysLogic = new GodRaysLogic(); mGodRaysLogic->setApp(this); cmp.registerCompositorLogic("GodRays", mGodRaysLogic); } if (!mSoftParticlesLogic) { mSoftParticlesLogic = new SoftParticlesLogic(); mSoftParticlesLogic->setApp(this); cmp.registerCompositorLogic("SoftParticles", mSoftParticlesLogic); } if (!mDepthOfFieldLogic) { mDepthOfFieldLogic = new DepthOfFieldLogic(); mDepthOfFieldLogic->setApp(this); cmp.registerCompositorLogic("DepthOfField", mDepthOfFieldLogic); } if (!mFilmGrainLogic) { mFilmGrainLogic = new FilmGrainLogic(); mFilmGrainLogic->setApp(this); cmp.registerCompositorLogic("FilmGrain", mFilmGrainLogic); } if (!mGBufferLogic) { mGBufferLogic = new GBufferLogic(); mGBufferLogic->setApp(this); cmp.registerCompositorLogic("GBuffer", mGBufferLogic); } if (cmp.getByName("Motion Blur").isNull()) { // Motion blur has to be created in code CompositorPtr comp3 = cmp.create( "Motion Blur", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); CompositionTechnique *t = comp3->createTechnique(); t->setCompositorLogicName("Motion Blur"); { CompositionTechnique::TextureDefinition *def = t->createTextureDefinition("scene"); def->width = 0; def->height = 0; def->formatList.push_back(PF_R8G8B8); } { CompositionTechnique::TextureDefinition *def = t->createTextureDefinition("sum"); def->width = 0; def->height = 0; def->formatList.push_back(PF_R8G8B8); } { CompositionTechnique::TextureDefinition *def = t->createTextureDefinition("temp"); def->width = 0; def->height = 0; def->formatList.push_back(PF_R8G8B8); } /// Render scene { CompositionTargetPass *tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_PREVIOUS); tp->setOutputName("scene"); } /// Initialisation pass for sum texture { CompositionTargetPass *tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_PREVIOUS); tp->setOutputName("sum"); tp->setOnlyInitial(true); } /// Do the motion blur { CompositionTargetPass *tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("temp"); { CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Ogre/Compositor/Combine"); pass->setIdentifier(120); pass->setInput(0, "scene"); pass->setInput(1, "sum"); } } /// Copy back sum texture { CompositionTargetPass *tp = t->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("sum"); { CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Ogre/Compositor/Copyback"); pass->setInput(0, "temp"); } } /// Display result { CompositionTargetPass *tp = t->getOutputTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); { CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Ogre/Compositor/MotionBlur"); pass->setInput(0, "sum"); } } } if (!mMotionBlurLogic) { mMotionBlurLogic = new MotionBlurLogic(this); cmp.registerCompositorLogic("Motion Blur", mMotionBlurLogic); } /*if (!mCameraBlurLogic) { mCameraBlurLogic = new CameraBlurLogic(this); cmp.registerCompositorLogic("CamBlur", mCameraBlurLogic); }*/ for (std::list<Viewport*>::iterator it=mSplitMgr->mViewports.begin(); it!=mSplitMgr->mViewports.end(); ++it) { // remove old comp. first cmp.removeCompositorChain( (*it )); //if (MaterialGenerator::MRTSupported()) if (1) { cmp.addCompositor((*it), "gbuffer"); } cmp.addCompositor((*it), "gbufferNoMRT"); cmp.addCompositor((*it), "HDRNoMRT"); //if (MaterialGenerator::MRTSupported()) if (1) { cmp.addCompositor((*it), "ssao"); cmp.addCompositor((*it), "SoftParticles"); cmp.addCompositor((*it), "DepthOfField"); cmp.addCompositor((*it), "gbufferFinalizer"); cmp.addCompositor((*it), "HDR"); } else { cmp.addCompositor((*it), "ssaoNoMRT"); } cmp.addCompositor((*it), "GodRays"); cmp.addCompositor((*it), "Bloom"); //cmp.addCompositor((*it), "CamBlur"); cmp.addCompositor((*it), "Motion Blur"); //cmp.addCompositor((*it), "FXAA"); cmp.addCompositor((*it), "FilmGrain"); cmp.addCompositor((*it), "gbufferUIRender"); } refreshCompositor(); }
void HDRCompositor::BrightPass(void) { CompositionTargetPass* tp; CompositionPass* pass; //first do brightpass CreateTextureDef("Bright",m_VpWidth/4,m_VpHeight/4,PF_A8R8G8B8); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Bright"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("BrightPass"); pass->setInput(0,"scenedown4"); pass->setInput(1,"Luminance"); pass->setInput(2,"Key"); pass->setIdentifier(MID_BRIGHT); /*GpuProgramParameters::RealConstantEntry* entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("g_fMiddleGray"); if(entry) entry->val[0] = m_Key;*/ //downsamples of bright for glare and/or star /*if(m_GlareType != GT_NONE || m_StarType != ST_NONE) { CreateTextureDef("Bright2",m_Window->getWidth()/8,m_Window->getHeight()/8,PF_A8R8G8B8); //CreateTextureDef("Bright4",m_Window->getWidth()/16,m_Window->getHeight()/16,PF_A8R8G8B8); //CreateTextureDef("Bright8",m_Window->getWidth()/32,m_Window->getHeight()/32,PF_A8R8G8B8); //birght/2 tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Bright2"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("BrightDown_1"); pass->setInput(0,"Bright"); entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("rcpScreenSize"); if(entry) { entry->val[0] = 4.f/m_Window->getWidth(); entry->val[1] = 4.f/m_Window->getHeight(); } //birght/4 //tp = m_HDRTechnique->createTargetPass(); //tp->setInputMode(CompositionTargetPass::IM_NONE); //tp->setOutputName("Bright4"); //pass = tp->createPass(); //pass->setType(CompositionPass::PT_RENDERQUAD); //pass->setMaterialName("BrightDown_2"); //pass->setInput(0,"Bright2"); //entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("rcpScreenSize"); //if(entry) //{ // entry->val[0] = 8.f/m_Window->getWidth(); // entry->val[1] = 8.f/m_Window->getHeight(); //} //birght/8 //tp = m_HDRTechnique->createTargetPass(); //tp->setInputMode(CompositionTargetPass::IM_NONE); //tp->setOutputName("Bright8"); //pass = tp->createPass(); //pass->setType(CompositionPass::PT_RENDERQUAD); //pass->setMaterialName("BrightDown_3"); //pass->setInput(0,"Bright4"); //entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("rcpScreenSize"); //if(entry) //{ // entry->val[0] = 16.f/m_Window->getWidth(); // entry->val[1] = 16.f/m_Window->getHeight(); //} }*/ }
void HDRCompositor::CalculateLuminance(void) { CreateTextureDef("Lum64",64,64,PF_FLOAT16_R); CreateTextureDef("Lum16",16,16,PF_FLOAT16_R); CreateTextureDef("Lum4",4,4,PF_FLOAT16_R); CreateTextureDef("Luminance",1,1,PF_FLOAT16_R); CompositionTargetPass *tp; CompositionPass *pass; //intial to 64 tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Lum64"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("LuminanceInitial"); pass->setInput(0,"scenedown4"); //down to 16 tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Lum16"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Luminance1"); pass->setInput(0,"Lum64"); //down to 4 tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Lum4"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Luminance2"); pass->setInput(0,"Lum64"); //final to 1 tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Luminance"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); //if(m_ToneMapper != TM_ADAPTLOG) pass->setMaterialName("LuminanceFinalAvg"); //else // pass->setMaterialName("LuminanceFinalMax"); pass->setInput(0,"Lum4"); if(m_LumAdaption) { CreateTextureDef("AdaptedLumLast",1,1,PF_FLOAT16_R); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("AdaptedLumLast"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("CopyHDR"); pass->setInput(0,"AdaptedLum"); CreateTextureDef("AdaptedLum",1,1,PF_FLOAT16_R); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("AdaptedLum"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("AdaptLuminance"); pass->setInput(0,"Luminance"); pass->setInput(1,"AdaptedLumLast");//old pass->setIdentifier(MID_ADAPT); } }
//----------------------------------------------------------------------- void CompositorChain::createOriginalScene() { /// Create "default" compositor /** Compositor that is used to implicitly represent the original render in the chain. This is an identity compositor with only an output pass: compositor Ogre/Scene { technique { target_output { pass clear { /// Clear frame } pass render_scene { visibility_mask FFFFFFFF render_queues SKIES_EARLY SKIES_LATE } } } }; */ // If two viewports use the same scheme but differ in settings like visibility masks, shadows, etc we don't // want compositors to share their technique. Otherwise both compositors will have to recompile every time they // render. Thus we generate a unique compositor per viewport. String compName("Ogre/Scene/"); compName += StringConverter::toString((intptr_t)mViewport); mOriginalSceneScheme = mViewport->getMaterialScheme(); CompositorPtr scene = CompositorManager::getSingleton().getByName(compName, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME); if (scene.isNull()) { scene = CompositorManager::getSingleton().create(compName, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME); CompositionTechnique *t = scene->createTechnique(); t->setSchemeName(StringUtil::BLANK); CompositionTargetPass *tp = t->getOutputTargetPass(); tp->setVisibilityMask(0xFFFFFFFF); { CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_CLEAR); } { CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERSCENE); /// Render everything, including skies pass->setFirstRenderQueue(RENDER_QUEUE_BACKGROUND); pass->setLastRenderQueue(RENDER_QUEUE_SKIES_LATE); } /// Create base "original scene" compositor scene = CompositorManager::getSingleton().load(compName, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME); } mOriginalScene = OGRE_NEW CompositorInstance(scene->getSupportedTechnique(), this); }
void HDRCompositor::BuildScales(void) { CompositionTargetPass *tp; CompositionPass *pass; //first build luminacepass scales CreateTextureDef("Lumscale1",m_VpWidth,m_VpHeight,PF_FLOAT16_RGB); CreateTextureDef("Lumscale2",m_VpWidth/2,m_VpHeight/2,PF_FLOAT16_RGB); CreateTextureDef("Lumscale4",m_VpWidth/4,m_VpHeight/4,PF_FLOAT16_RGB); CreateTextureDef("Lumscale8",m_VpWidth/8,m_VpHeight/8,PF_FLOAT16_RGB); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Lumscale1"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("LuminanceScale"); pass->setInput(0,"Scene",0); if(m_LumAdaption) pass->setInput(1, "AdaptedLum"); else pass->setInput(1, "Luminance"); pass->setInput(2, "Key"); pass->setIdentifier(MID_LUMSCALE1); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Lumscale2"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Down2"); pass->setInput(0,"Lumscale1"); pass->setIdentifier(MID_LUMSCALE2); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Lumscale4"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Down2"); pass->setInput(0,"Lumscale2"); pass->setIdentifier(MID_LUMSCALE4); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Lumscale8"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Down2"); pass->setInput(0,"Lumscale4"); pass->setIdentifier(MID_LUMSCALE8); //filter downsampled scenes, each filter scale is 1.6 times larger //starting with: float s = 1.f / 2.f / sqrt(2.f); //sample scales 1, 2, 2, 4, 4, 8, 8 and build a total of 7 scales for(int i = 0; i < m_Scales; i++) { String strScale = "scale"; strScale += StringConverter::toString(i+1); int scaleSize = (1 << ((i + 1) / 2)); String strLumScale = "Lumscale"; strLumScale += StringConverter::toString(scaleSize); CreateTextureDef(strScale, m_VpWidth/scaleSize, m_VpHeight/scaleSize, PF_FLOAT16_RGB); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName(strScale); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("GaussBlur"); pass->setInput(0,strLumScale); pass->setIdentifier(MID_SCALE + i); } //build local adapt map CreateTextureDef("LocalAdaptMap", m_VpWidth, m_VpHeight, PF_FLOAT16_RGB); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("LocalAdaptMap"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("BuildLocalAdaptMap"); pass->setInput(0,"Key"); pass->setInput(1,"scale1"); pass->setInput(2,"scale2"); pass->setInput(3,"scale3"); pass->setInput(4,"scale4"); pass->setInput(5,"scale5"); pass->setInput(6,"scale6"); pass->setInput(7,"scale7"); pass->setIdentifier(MID_BUILDLOCAL); }
void HDRCompositor::FinalRendering(void) { CompositionTargetPass *tp = m_HDRTechnique->getOutputTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); CompositionPass *pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); if(m_ToneMapper == TM_NONE || m_DebugRendertarget) pass->setMaterialName("CompositorCopyback"); else if(m_ToneMapper == TM_LINEAR) pass->setMaterialName("HDRFinalLinear"); else if(m_ToneMapper == TM_REINHARDS) pass->setMaterialName("HDRFinalReinh"); else if(m_ToneMapper == TM_REINHARDSMOD) pass->setMaterialName("HDRFinalReinhMod"); else if(m_ToneMapper == TM_LOG) pass->setMaterialName("HDRFinalLog"); else if(m_ToneMapper == TM_ADAPTLOG) pass->setMaterialName("HDRFinalAdaptiveLog"); else if(m_ToneMapper == TM_REINHARDLOCAL) pass->setMaterialName("HDRFinalReinhLocal"); if(m_DebugRendertarget == 1) pass->setInput(0,"scenedown4"); else if(m_DebugRendertarget == 2) pass->setInput(0,"Lumscale1"); else if(m_DebugRendertarget == 3) pass->setInput(0,"Lumscale2"); else if(m_DebugRendertarget == 4) pass->setInput(0,"Lumscale4"); else if(m_DebugRendertarget == 5) pass->setInput(0,"scale0"); else if(m_DebugRendertarget == 6) pass->setInput(0,"scale1"); else if(m_DebugRendertarget == 7) pass->setInput(0,"scale2"); else if(m_DebugRendertarget == 8) pass->setInput(0,"scale6"); /*else if(m_DebugRendertarget == 2) pass->setInput(0,"Lum64"); else if(m_DebugRendertarget == 3) pass->setInput(0,"Lum16"); else if(m_DebugRendertarget == 4) pass->setInput(0,"Lum4"); else if(m_DebugRendertarget == 5) pass->setInput(0,"Luminance"); else if(m_DebugRendertarget == 6) pass->setInput(0,"Bright"); else if(m_DebugRendertarget == 7) pass->setInput(0,"Glare"); else if(m_DebugRendertarget == 8) pass->setInput(0,"Star");*/ else { pass->setInput(0,"Scene",0); if(m_ToneMapper != TM_NONE) { if(m_ToneMapper == TM_REINHARDLOCAL) { pass->setInput(0, "Lumscale1"); pass->setInput(1,"Key"); if(m_GlareType != GT_NONE) pass->setInput(2,"Glare"); if(m_StarType != GT_NONE) pass->setInput(3,"Star"); pass->setInput(4, "LocalAdaptMap"); } else { if(m_LumAdaption) pass->setInput(1, "AdaptedLum"); else pass->setInput(1, "Luminance"); pass->setInput(2, "Key"); } } if(m_ToneMapper != TM_REINHARDLOCAL) { if(m_GlareType != GT_NONE) pass->setInput(3,"Glare"); if(m_StarType != GT_NONE) pass->setInput(4,"Star"); } } pass->setIdentifier(MID_FINAL); }
void HDRCompositor::BuildGlare(void) { if(m_GlareType == GT_BLUR) { CompositionTargetPass *tp; CompositionPass *pass; String strDst; String strSrc = "Bright"; for(int i=0; i<m_GlarePasses; i++) { String strDst = "Glare"; if(i < m_GlarePasses-1 ) strDst += StringConverter::toString(i); CreateTextureDef(strDst,m_VpWidth/4,m_VpHeight/4,PF_A8R8G8B8); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName(strDst); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("GaussBlur"); pass->setInput(0,strSrc); pass->setIdentifier(MID_GAUSSBLUR); strSrc = strDst; } //entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("rcpScreenSize"); //if(entry) //{ // entry->val[0] = 32.f/m_Window->getWidth(); // entry->val[1] = 32.f/m_Window->getHeight(); //} /*pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("GaussBlur_2"); pass->setInput(0,"Glare"); pass->setInput(1,"Bright2"); entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("rcpScreenSize"); if(entry) { entry->val[0] = 8.f/m_Window->getWidth(); entry->val[1] = 8.f/m_Window->getHeight(); } pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("GaussBlur_3"); pass->setInput(0,"Glare"); pass->setInput(1,"Bright4"); entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("rcpScreenSize"); if(entry) { entry->val[0] = 16.f/m_Window->getWidth(); entry->val[1] = 16.f/m_Window->getHeight(); } pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("GaussBlur_4"); pass->setInput(0,"Glare"); pass->setInput(1,"Bright2"); entry = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->getNamedRealConstantEntry("rcpScreenSize"); if(entry) { entry->val[0] = 32.f/m_Window->getWidth(); entry->val[1] = 32.f/m_Window->getHeight(); }*/ } }
void HDRCompositor::BuildStar(void) { if(m_StarType == ST_PLUS) { CompositionTargetPass *tp; CompositionPass *pass; String strDstH, strDstV; String strSrcH = "Bright"; String strSrcV = "Bright"; for(int i=0; i<m_StarPasses; i++) { String strDstH = "StarH"; String strDstV = "StarV"; if(i < m_StarPasses-1 ) { strDstH += StringConverter::toString(i); strDstV += StringConverter::toString(i); } CreateTextureDef(strDstH,m_VpWidth/4,m_VpHeight/4,PF_A8R8G8B8); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName(strDstH); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("GaussBlur"); pass->setInput(0,strSrcH); pass->setIdentifier(MID_STARH); strSrcH = strDstH; CreateTextureDef(strDstV,m_VpWidth/4,m_VpHeight/4,PF_A8R8G8B8); tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName(strDstV); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("GaussBlur"); pass->setInput(0,strSrcV); pass->setIdentifier(MID_STARV); strSrcV = strDstV; } CreateTextureDef("Star",m_VpWidth/4,m_VpHeight/4,PF_A8R8G8B8); //merge horizontal and vertical blur tp = m_HDRTechnique->createTargetPass(); tp->setInputMode(CompositionTargetPass::IM_NONE); tp->setOutputName("Star"); pass = tp->createPass(); pass->setType(CompositionPass::PT_RENDERQUAD); pass->setMaterialName("Merge2"); pass->setInput(0,"StarH"); pass->setInput(1,"StarV"); } }