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;
|
---|
24 | TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_ALL",
|
---|
25 | "default",
|
---|
26 | TEX_TYPE_2D,
|
---|
27 | width,
|
---|
28 | height,
|
---|
29 | 0,
|
---|
30 | 0,
|
---|
31 | PF_FLOAT16_RGBA,
|
---|
32 | TU_RENDERTARGET);
|
---|
33 | allWeightsTexture = texPtr.getPointer();
|
---|
34 | //add viewport to rendertarget
|
---|
35 | HardwarePixelBuffer* hpb = (allWeightsTexture->getBuffer()).getPointer();
|
---|
36 | RenderTarget* rt = hpb->getRenderTarget();
|
---|
37 | Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_ALL_CAMERA");
|
---|
38 | Viewport* v = rt->addViewport(wc);
|
---|
39 | v->setOverlaysEnabled(false);
|
---|
40 | rt->setAutoUpdated(false);
|
---|
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,
|
---|
52 | PF_FLOAT16_RGBA,
|
---|
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);
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 | void OgrePMWeightComputeRenderingRun::updateFrame(unsigned long frameNum)
|
---|
67 | {
|
---|
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)
|
---|
75 | {
|
---|
76 | MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_ComputeWeights");
|
---|
77 |
|
---|
78 | GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
79 |
|
---|
80 | Vector3 lightPos = light->getPosition();
|
---|
81 | Vector3 lightDir = light->getDirection();
|
---|
82 | // Radian lightAngle = light->getSpotlightOuterAngle();
|
---|
83 |
|
---|
84 | //Fparams->setNamedConstant("lightTransform", lightMatrix);
|
---|
85 | Fparams->setNamedConstant("nRadionColumns", col);
|
---|
86 | Fparams->setNamedConstant("lightPos", lightPos);
|
---|
87 | Fparams->setNamedConstant("lightDir", lightDir);
|
---|
88 |
|
---|
89 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
|
---|
90 | PMEPrun->getEntryPointTextureName());
|
---|
91 |
|
---|
92 | RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget();
|
---|
93 | renderFullscreenQuad(mat->getName(), rt);
|
---|
94 |
|
---|
95 | rt->writeContentsToFile("allweights.bmp");
|
---|
96 | // rt->writeContentsToFile("allweights.dds");
|
---|
97 |
|
---|
98 |
|
---|
99 | ///////////////////DEBUG
|
---|
100 | static BillboardSet* entryPointBBSet = 0;
|
---|
101 | if(entryPointBBSet == 0)
|
---|
102 | {
|
---|
103 | SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
|
---|
104 | entryPointBBSet = sm->createBillboardSet("PATHMAP_ENTRYPOINTS", entryPointCnt);
|
---|
105 | entryPointBBSet->setBillboardType(BBT_POINT);
|
---|
106 | entryPointBBSet->setBillboardsInWorldSpace(true);
|
---|
107 | entryPointBBSet->setPointRenderingEnabled(true);
|
---|
108 | for(unsigned int i = 0; i < entryPointCnt; i++)
|
---|
109 | {
|
---|
110 | PathMapEntryPoint EP = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i);
|
---|
111 | Vector3 billboardPosition = EP.position;
|
---|
112 | float uCoord = ((float) (i % col) + 0.5f) / (float) col;
|
---|
113 | float vCoord = ((float)(i / col) + 0.5f) / 4096.0f;
|
---|
114 | entryPointBBSet->createBillboard(billboardPosition, ColourValue(uCoord, vCoord, 0, 0));
|
---|
115 | }
|
---|
116 | entryPointBBSet->setMaterialName("GTP/PM/EPBillboards");
|
---|
117 | MaterialPtr mater = MaterialManager::getSingleton().getByName("GTP/PM/EPBillboards");
|
---|
118 | mater->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(allWeightsTexture->getName());
|
---|
119 | sm->getRootSceneNode()->createChildSceneNode()->attachObject(entryPointBBSet);
|
---|
120 | }
|
---|
121 | /////////////////
|
---|
122 | }
|
---|
123 | else
|
---|
124 | {
|
---|
125 | ///not implemented
|
---|
126 | }
|
---|
127 | /*
|
---|
128 | unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
|
---|
129 |
|
---|
130 | MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_SumWeights");
|
---|
131 | GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
|
---|
132 | Fparams->setNamedConstant("nRadionColumns", col);
|
---|
133 | Fparams->setNamedConstant("clusterCount", (float) clustercount);
|
---|
134 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
|
---|
135 | PMEPrun->getEntryPointTextureName());
|
---|
136 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
|
---|
137 | PMEPrun->getClusterLengthTextureName());
|
---|
138 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName(
|
---|
139 | allWeightsTexture->getName());
|
---|
140 |
|
---|
141 | RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget();
|
---|
142 | renderFullscreenQuad(mat->getName(), rt);
|
---|
143 |
|
---|
144 | rt->writeContentsToFile("weights.bmp");
|
---|
145 | rt->writeContentsToFile("weights.dds"); */
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|