[2189] | 1 | #include "OgrePMWeightComputeRenderingRun.h"
|
---|
| 2 | #include "OgreIlluminationManager.h"
|
---|
| 3 | #include "OgrePMEntryPointMapRenderingRun.h"
|
---|
| 4 |
|
---|
| 5 | OgrePMWeightComputeRenderingRun::OgrePMWeightComputeRenderingRun(String name, String LightName)
|
---|
| 6 | : OgreRenderingRun(1, 1)
|
---|
| 7 | , RenderingRun(1, 1)
|
---|
| 8 | {
|
---|
| 9 | this->name = name;
|
---|
| 10 | weights = 0;
|
---|
| 11 |
|
---|
| 12 | this->light = Root::getSingleton()._getCurrentSceneManager()->getLight(LightName);
|
---|
| 13 | createWeightMap();
|
---|
| 14 |
|
---|
| 15 | OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP);
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | void OgrePMWeightComputeRenderingRun::createWeightMap()
|
---|
| 19 | {
|
---|
| 20 |
|
---|
| 21 | unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
|
---|
| 22 | int width = entryPointCnt / 4096;
|
---|
| 23 | int height = 4096;
|
---|
[2200] | 24 | TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_ALL",
|
---|
[2189] | 25 | "default",
|
---|
| 26 | TEX_TYPE_2D,
|
---|
| 27 | width,
|
---|
| 28 | height,
|
---|
| 29 | 0,
|
---|
| 30 | 0,
|
---|
[2214] | 31 | PF_FLOAT32_R,
|
---|
[2189] | 32 | TU_RENDERTARGET);
|
---|
[2200] | 33 | allWeightsTexture = texPtr.getPointer();
|
---|
[2189] | 34 | //add viewport to rendertarget
|
---|
[2200] | 35 | HardwarePixelBuffer* hpb = (allWeightsTexture->getBuffer()).getPointer();
|
---|
[2189] | 36 | RenderTarget* rt = hpb->getRenderTarget();
|
---|
[2200] | 37 | Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_ALL_CAMERA");
|
---|
[2189] | 38 | Viewport* v = rt->addViewport(wc);
|
---|
| 39 | v->setOverlaysEnabled(false);
|
---|
| 40 | rt->setAutoUpdated(false);
|
---|
[2200] | 41 |
|
---|
| 42 | unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
|
---|
| 43 | width = clustercount;
|
---|
| 44 | height = 1;
|
---|
| 45 | texPtr = Ogre::TextureManager::getSingleton().createManual(name,
|
---|
| 46 | "default",
|
---|
| 47 | TEX_TYPE_2D,
|
---|
| 48 | width,
|
---|
| 49 | height,
|
---|
| 50 | 0,
|
---|
| 51 | 0,
|
---|
[2214] | 52 | PF_FLOAT32_R,
|
---|
[2200] | 53 | TU_RENDERTARGET);
|
---|
| 54 | weightTexture = texPtr.getPointer();
|
---|
| 55 | //add viewport to rendertarget
|
---|
| 56 | hpb = (weightTexture->getBuffer()).getPointer();
|
---|
| 57 | rt = hpb->getRenderTarget();
|
---|
| 58 | wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA");
|
---|
| 59 | v = rt->addViewport(wc);
|
---|
| 60 | v->setOverlaysEnabled(false);
|
---|
| 61 | rt->setAutoUpdated(false);
|
---|
[2189] | 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | void OgrePMWeightComputeRenderingRun::updateFrame(unsigned long frameNum)
|
---|
| 67 | {
|
---|
[2200] | 68 | OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP, frameNum);
|
---|
| 69 | OgrePMEntryPointMapRenderingRun* PMEPrun = (OgrePMEntryPointMapRenderingRun*)
|
---|
| 70 | OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP)->asOgreRenderingRun();
|
---|
| 71 | unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
|
---|
| 72 | int col = entryPointCnt / 4096;
|
---|
| 73 |
|
---|
| 74 | if(light->getType() == Light::LT_SPOTLIGHT)
|
---|
[2189] | 75 | {
|
---|
[2200] | 76 | MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_ComputeWeights");
|
---|
[2189] | 77 |
|
---|
[2200] | 78 | GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
[2189] | 79 |
|
---|
| 80 | Vector3 lightPos = light->getPosition();
|
---|
| 81 | Vector3 lightDir = light->getDirection();
|
---|
| 82 | // Radian lightAngle = light->getSpotlightOuterAngle();
|
---|
[2200] | 83 |
|
---|
[2189] | 84 | //Fparams->setNamedConstant("lightTransform", lightMatrix);
|
---|
| 85 | Fparams->setNamedConstant("nRadionColumns", col);
|
---|
| 86 | Fparams->setNamedConstant("lightPos", lightPos);
|
---|
| 87 | Fparams->setNamedConstant("lightDir", lightDir);
|
---|
[2200] | 88 |
|
---|
[2189] | 89 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
|
---|
| 90 | PMEPrun->getEntryPointTextureName());
|
---|
| 91 |
|
---|
[2200] | 92 | RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget();
|
---|
[2189] | 93 | renderFullscreenQuad(mat->getName(), rt);
|
---|
| 94 |
|
---|
[2214] | 95 | rt->writeContentsToFile("allweights.bmp");
|
---|
[2209] | 96 | // rt->writeContentsToFile("allweights.dds");
|
---|
[2214] | 97 |
|
---|
| 98 | float* allweights = new float[entryPointCnt / 4096 * 4096];
|
---|
| 99 | PixelBox lockBox(entryPointCnt / 4096, 4096, 1, PF_FLOAT32_R, allweights);
|
---|
| 100 | allWeightsTexture->getBuffer()->blitToMemory(lockBox);
|
---|
[2209] | 101 |
|
---|
[2214] | 102 | ///////////////////DEBUG
|
---|
[2209] | 103 | static BillboardSet* entryPointBBSet = 0;
|
---|
| 104 | if(entryPointBBSet == 0)
|
---|
| 105 | {
|
---|
| 106 | SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
|
---|
| 107 | entryPointBBSet = sm->createBillboardSet("PATHMAP_ENTRYPOINTS", entryPointCnt);
|
---|
| 108 | entryPointBBSet->setBillboardType(BBT_POINT);
|
---|
| 109 | entryPointBBSet->setBillboardsInWorldSpace(true);
|
---|
| 110 | entryPointBBSet->setPointRenderingEnabled(true);
|
---|
| 111 | for(unsigned int i = 0; i < entryPointCnt; i++)
|
---|
| 112 | {
|
---|
| 113 | PathMapEntryPoint EP = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i);
|
---|
| 114 | Vector3 billboardPosition = EP.position;
|
---|
[2214] | 115 |
|
---|
| 116 | float uCoord = allweights[i];
|
---|
| 117 | float vCoord = 0;
|
---|
| 118 | //float uCoord = ((float) (i % col) + 0.5f) / (float) col;
|
---|
| 119 | //float vCoord = ((float)(i / col) + 0.5f) / 4096.0f;
|
---|
[2209] | 120 | entryPointBBSet->createBillboard(billboardPosition, ColourValue(uCoord, vCoord, 0, 0));
|
---|
| 121 | }
|
---|
| 122 | entryPointBBSet->setMaterialName("GTP/PM/EPBillboards");
|
---|
| 123 | MaterialPtr mater = MaterialManager::getSingleton().getByName("GTP/PM/EPBillboards");
|
---|
| 124 | mater->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(allWeightsTexture->getName());
|
---|
| 125 | sm->getRootSceneNode()->createChildSceneNode()->attachObject(entryPointBBSet);
|
---|
| 126 | }
|
---|
[2214] | 127 |
|
---|
| 128 | delete[] allweights;
|
---|
| 129 |
|
---|
[2209] | 130 | /////////////////
|
---|
[2189] | 131 | }
|
---|
[2200] | 132 | else
|
---|
| 133 | {
|
---|
| 134 | ///not implemented
|
---|
| 135 | }
|
---|
[2214] | 136 |
|
---|
[2189] | 137 | unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
|
---|
[2200] | 138 |
|
---|
| 139 | MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_SumWeights");
|
---|
| 140 | GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
| 141 | Fparams->setNamedConstant("nRadionColumns", col);
|
---|
| 142 | Fparams->setNamedConstant("clusterCount", (float) clustercount);
|
---|
| 143 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
|
---|
| 144 | PMEPrun->getEntryPointTextureName());
|
---|
| 145 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
|
---|
| 146 | PMEPrun->getClusterLengthTextureName());
|
---|
| 147 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName(
|
---|
| 148 | allWeightsTexture->getName());
|
---|
[2189] | 149 |
|
---|
[2200] | 150 | RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget();
|
---|
| 151 | renderFullscreenQuad(mat->getName(), rt);
|
---|
[2189] | 152 |
|
---|
[2214] | 153 | //rt->writeContentsToFile("weights.bmp");
|
---|
| 154 | //rt->writeContentsToFile("weights.dds");
|
---|
| 155 |
|
---|
| 156 | float* weights = new float[clustercount];
|
---|
| 157 | PixelBox lockBox(clustercount, 1, 1, PF_FLOAT32_R, weights);
|
---|
| 158 | allWeightsTexture->getBuffer()->blitToMemory(lockBox);
|
---|
| 159 |
|
---|
| 160 | delete[] weights;
|
---|
[2189] | 161 | }
|
---|
| 162 |
|
---|
| 163 |
|
---|