#include "OgrePMEntryPointMapRenderingRun.h" #include "OgreIlluminationManager.h" OgrePMEntryPointMapRenderingRun::OgrePMEntryPointMapRenderingRun(String name) : OgreRenderingRun(1, 1) , RenderingRun(1, 1) { this->name = name; createEntryPointMap(); } void OgrePMEntryPointMapRenderingRun::createEntryPointMap() { unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size(); int width = entryPointCnt / 4096 * 2; int height = 4096; TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name, "default", TEX_TYPE_2D, width, height, 0, 0, PF_FLOAT32_RGBA, TU_DEFAULT); entryPointTexture = texPtr.getPointer(); struct TMR { float pos[4]; float dir[4]; }; TMR* tm = new TMR[entryPointCnt]; for(int i=0; iposition.x; tm[i].pos[1] = EP->position.y; tm[i].pos[2] = EP->position.z; tm[i].pos[3] = 1.0; tm[i].dir[0] = EP->normal.x; tm[i].dir[1] = EP->normal.y; tm[i].dir[2] = EP->normal.z; tm[i].dir[3] = EP->prob; } PixelBox lockBox(width, height, 1, PF_FLOAT32_RGBA, tm); entryPointTexture->getBuffer()->blitFromMemory(lockBox); delete[] tm; int clusterCount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize(); width = clusterCount; height = 2; texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_CL", "default", TEX_TYPE_2D, width, height, 0, 0, PF_FLOAT32_R, TU_RENDERTARGET); clusterLengthTexture = texPtr.getPointer(); float* data = new float[clusterCount * 2]; unsigned int clusterStartEntryPoint = 0; for(int i = 0; i < clusterCount; i++) { unsigned int clusterSize = OgreIlluminationManager::getSingleton().getPathMapClusterLength(i); data[i] = clusterSize;//clustercount data[clusterCount + i] = clusterStartEntryPoint; for(int j = 0; j < clusterSize; j++) { PathMapEntryPoint* EP = &OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(clusterStartEntryPoint + j); EP->clusterID = i; } clusterStartEntryPoint += clusterSize; } PixelBox lockBox2(width, height, 1, PF_FLOAT32_R, data); clusterLengthTexture->getBuffer()->blitFromMemory(lockBox2); delete[] data; if(false) { SceneManager* sm = Root::getSingleton()._getCurrentSceneManager(); BillboardSet* bbs = sm->createBillboardSet("WEIGHT_DEBUG", 4096); bbs->setDefaultDimensions(0.1, 0.1); for(int i= 0; i < entryPointCnt;i++) { PathMapEntryPoint* EP = &OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i); int r = i / 256; int g = i - r * 256; float rr = (float) r / 256.0; float gg = (float) g / 256.0; ColourValue c; c = ColourValue(rr, gg, 0); /*c = ColourValue( Math::Ceil(Math::Floor(EP->position.x)), Math::Ceil(Math::Floor(EP->position.y)), Math::Ceil(Math::Floor(EP->position.z)));*/ //c = ColourValue(0,0,1,0); bbs->createBillboard(Vector3(EP->position.x, i, EP->position.z), c); } bbs->setPointRenderingEnabled(true); bbs->setMaterialName("GTP/PM/EPBillboards"); sm->getRootSceneNode()->createChildSceneNode("WEIGHT_DEBUG_SN")->attachObject(bbs); } } void OgrePMEntryPointMapRenderingRun::updateFrame(unsigned long frameNum) { } void OgrePMEntryPointMapRenderingRun::freeAllResources() { this->entryPointTexture = 0; this->clusterLengthTexture = 0; TextureManager::getSingleton().remove(name); TextureManager::getSingleton().remove(name + "_CL"); }