#include "OgrePMWeightComputeRenderingRun.h" #include "OgreIlluminationManager.h" #include "OgrePMEntryPointMapRenderingRun.h" OgrePMWeightComputeRenderingRun::OgrePMWeightComputeRenderingRun(String name, String LightName) : OgreRenderingRun(1, 1) , RenderingRun(1, 1) { this->name = name; weights = 0; this->light = Root::getSingleton()._getCurrentSceneManager()->getLight(LightName); createWeightMap(); OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP); } void OgrePMWeightComputeRenderingRun::createWeightMap() { unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size(); int width = entryPointCnt / 4096; int height = 4096; TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_ALL", "default", TEX_TYPE_2D, width, height, 0, 0, PF_FLOAT32_R, TU_RENDERTARGET); allWeightsTexture = texPtr.getPointer(); //add viewport to rendertarget HardwarePixelBuffer* hpb = (allWeightsTexture->getBuffer()).getPointer(); RenderTarget* rt = hpb->getRenderTarget(); Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_ALL_CAMERA"); Viewport* v = rt->addViewport(wc); v->setOverlaysEnabled(false); rt->setAutoUpdated(false); unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize(); width = clustercount; height = 1; texPtr = Ogre::TextureManager::getSingleton().createManual(name, "default", TEX_TYPE_2D, width, height, 0, 0, PF_FLOAT32_R, TU_RENDERTARGET); weightTexture = texPtr.getPointer(); //add viewport to rendertarget hpb = (weightTexture->getBuffer()).getPointer(); rt = hpb->getRenderTarget(); wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA"); v = rt->addViewport(wc); v->setOverlaysEnabled(false); rt->setAutoUpdated(false); } void OgrePMWeightComputeRenderingRun::updateFrame(unsigned long frameNum) { OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP, frameNum); OgrePMEntryPointMapRenderingRun* PMEPrun = (OgrePMEntryPointMapRenderingRun*) OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP)->asOgreRenderingRun(); unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size(); int col = entryPointCnt / 4096; if(light->getType() == Light::LT_SPOTLIGHT) { MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_ComputeWeights"); GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer(); Vector3 lightPos = light->getPosition(); Vector3 lightDir = light->getDirection(); // Radian lightAngle = light->getSpotlightOuterAngle(); //Fparams->setNamedConstant("lightTransform", lightMatrix); Fparams->setNamedConstant("nRadionColumns", col); Fparams->setNamedConstant("lightPos", lightPos); Fparams->setNamedConstant("lightDir", lightDir); mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName( PMEPrun->getEntryPointTextureName()); RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget(); renderFullscreenQuad(mat->getName(), rt); rt->writeContentsToFile("allweights.bmp"); // rt->writeContentsToFile("allweights.dds"); float* allweights = new float[entryPointCnt / 4096 * 4096]; PixelBox lockBox(entryPointCnt / 4096, 4096, 1, PF_FLOAT32_R, allweights); allWeightsTexture->getBuffer()->blitToMemory(lockBox); ///////////////////DEBUG static BillboardSet* entryPointBBSet = 0; if(entryPointBBSet == 0) { SceneManager* sm = Root::getSingleton()._getCurrentSceneManager(); entryPointBBSet = sm->createBillboardSet("PATHMAP_ENTRYPOINTS", entryPointCnt); entryPointBBSet->setBillboardType(BBT_POINT); entryPointBBSet->setBillboardsInWorldSpace(true); entryPointBBSet->setPointRenderingEnabled(true); for(unsigned int i = 0; i < entryPointCnt; i++) { PathMapEntryPoint EP = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i); Vector3 billboardPosition = EP.position; float uCoord = allweights[i]; float vCoord = 0; //float uCoord = ((float) (i % col) + 0.5f) / (float) col; //float vCoord = ((float)(i / col) + 0.5f) / 4096.0f; entryPointBBSet->createBillboard(billboardPosition, ColourValue(uCoord, vCoord, 0, 0)); } entryPointBBSet->setMaterialName("GTP/PM/EPBillboards"); MaterialPtr mater = MaterialManager::getSingleton().getByName("GTP/PM/EPBillboards"); mater->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(allWeightsTexture->getName()); sm->getRootSceneNode()->createChildSceneNode()->attachObject(entryPointBBSet); } delete[] allweights; ///////////////// } else { ///not implemented } unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize(); MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_SumWeights"); GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer(); Fparams->setNamedConstant("nRadionColumns", col); Fparams->setNamedConstant("clusterCount", (float) clustercount); mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName( PMEPrun->getEntryPointTextureName()); mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName( PMEPrun->getClusterLengthTextureName()); mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName( allWeightsTexture->getName()); RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget(); renderFullscreenQuad(mat->getName(), rt); //rt->writeContentsToFile("weights.bmp"); //rt->writeContentsToFile("weights.dds"); float* weights = new float[clustercount]; PixelBox lockBox(clustercount, 1, 1, PF_FLOAT32_R, weights); allWeightsTexture->getBuffer()->blitToMemory(lockBox); delete[] weights; }