1 | #include "OgrePathMapRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreIlluminationManager.h"
|
---|
4 | #include "OgrePMWeightComputeRenderingRun.h"
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 | OgrePathMapRenderTechnique::OgrePathMapRenderTechnique(
|
---|
9 | Pass* pass,
|
---|
10 | OgreRenderable* parentRenderable,
|
---|
11 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
12 | :RenderTechnique( parentRenderable, parentTechniqueGroup),
|
---|
13 | OgreRenderTechnique(pass, parentRenderable, parentTechniqueGroup)
|
---|
14 | {
|
---|
15 | this->clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentRenderable->getName());
|
---|
16 |
|
---|
17 | //insert new pass
|
---|
18 | Ogre::Technique* techn = pass->getParent();
|
---|
19 | Technique::PassIterator it = techn->getPassIterator();
|
---|
20 |
|
---|
21 | int index = 0;
|
---|
22 | while(it.hasMoreElements())
|
---|
23 | {
|
---|
24 | if( it.getNext() == pass)
|
---|
25 | break;
|
---|
26 | index++;
|
---|
27 | it.moveNext();
|
---|
28 | }
|
---|
29 |
|
---|
30 | Pass* newpass = pathMapPass = techn->createPass();
|
---|
31 |
|
---|
32 | newpass->setVertexProgram("GTP/PathMap_VS");
|
---|
33 | newpass->setFragmentProgram("GTP/PathMap_PS");
|
---|
34 |
|
---|
35 | //bind vertex program parameters
|
---|
36 | GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer();
|
---|
37 | Vparams->setNamedAutoConstant("WorldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
|
---|
38 | //bind fragment program parameters
|
---|
39 | GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer();
|
---|
40 | int prmxres = clusters->pathMapResolution * clusters->count;
|
---|
41 | int prmyres = clusters->pathMapResolution;
|
---|
42 | while(prmxres > 4096)
|
---|
43 | {
|
---|
44 | prmxres /= 2;
|
---|
45 | prmyres *= 2;
|
---|
46 | }
|
---|
47 | int prmnt[2] = {prmxres / clusters->pathMapResolution, prmyres / clusters->pathMapResolution};
|
---|
48 |
|
---|
49 | float halfPixel[2] = {0.5 / prmxres, 0.5 / prmyres};
|
---|
50 | Vector4 pathMapParameters(prmnt[0],prmnt[1],halfPixel[0],halfPixel[1]);
|
---|
51 | Fparams->setNamedConstant("prmAtlasTilesHalfPixel",pathMapParameters);
|
---|
52 | unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
|
---|
53 | Fparams->setNamedConstant("allClusterCount", (float) clustercount);
|
---|
54 | PathMapClusters* clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentOgreRenderable->getName());
|
---|
55 | Fparams->setNamedConstant("clusterCount", (float) clusters->count);
|
---|
56 |
|
---|
57 | TextureUnitState* st = newpass->createTextureUnitState();
|
---|
58 | st->setTextureFiltering(TFO_BILINEAR);
|
---|
59 | st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
|
---|
60 | st->setTextureBorderColour(ColourValue::Green);
|
---|
61 | st->setTextureName(clusters->pathMapTextureFilename);
|
---|
62 |
|
---|
63 | createWeightIndexTexture();
|
---|
64 |
|
---|
65 | st = newpass->createTextureUnitState();
|
---|
66 | st->setTextureFiltering(TFO_NONE);
|
---|
67 | st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
|
---|
68 | st->setTextureBorderColour(ColourValue::Red);
|
---|
69 | st->setTextureName(weightIndexTexture->getName());
|
---|
70 |
|
---|
71 | st = newpass->createTextureUnitState();
|
---|
72 | st->setTextureFiltering(TFO_NONE);
|
---|
73 | st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
|
---|
74 | st->setTextureBorderColour(ColourValue::Blue);
|
---|
75 |
|
---|
76 | //newpass->setSceneBlending(SBT_MODULATE);
|
---|
77 | newpass->setSceneBlending(SBF_ONE, SBF_ZERO);
|
---|
78 | newpass->setDepthBias(1);
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 | }
|
---|
83 |
|
---|
84 | OgrePathMapRenderTechnique::~OgrePathMapRenderTechnique()
|
---|
85 | {
|
---|
86 |
|
---|
87 | }
|
---|
88 |
|
---|
89 | void OgrePathMapRenderTechnique::createWeightIndexTexture()
|
---|
90 | {
|
---|
91 | PathMapClusters* clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentOgreRenderable->getName());
|
---|
92 | int width = clusters->count / 4;
|
---|
93 | TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(this->parentOgreRenderable->getName() + "_PMWeightIndexTexture",
|
---|
94 | "default",
|
---|
95 | TEX_TYPE_1D,
|
---|
96 | width,
|
---|
97 | 1,
|
---|
98 | 0,
|
---|
99 | 0,
|
---|
100 | PF_FLOAT32_RGBA,
|
---|
101 | TU_DYNAMIC_WRITE_ONLY);
|
---|
102 | weightIndexTexture = texPtr.getPointer();
|
---|
103 |
|
---|
104 | float *weightIndices = new float[clusters->count];
|
---|
105 | PixelBox lockBox(width, 1, 1, PF_FLOAT32_RGBA, weightIndices);
|
---|
106 | for(int j = 0; j< clusters->count; j++)
|
---|
107 | weightIndices[j] = clusters->clusters[j];
|
---|
108 | weightIndexTexture->getBuffer()->blitFromMemory(lockBox);
|
---|
109 | delete[] weightIndices;
|
---|
110 | }
|
---|
111 |
|
---|
112 | void OgrePathMapRenderTechnique::update(unsigned long frameNum)
|
---|
113 | {
|
---|
114 | LightList lights;
|
---|
115 | SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
|
---|
116 | sm->_populateLightList(Vector3(0,0,0), 1000, lights); //TODO
|
---|
117 | //TODO set weights
|
---|
118 |
|
---|
119 |
|
---|
120 | for(int i = 0 ; i < 1; i++)
|
---|
121 | {
|
---|
122 | String lightName = lights.at(0)->getName();
|
---|
123 | OgreIlluminationManager::getSingleton().createPerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP);
|
---|
124 | OgreIlluminationManager::getSingleton().updatePerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP, frameNum);
|
---|
125 | OgrePMWeightComputeRenderingRun* PMWeightRun = (OgrePMWeightComputeRenderingRun*)
|
---|
126 | OgreIlluminationManager::getSingleton().getPerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP)->asOgreRenderingRun();
|
---|
127 |
|
---|
128 | TextureUnitState* st =pathMapPass->getTextureUnitState(2);
|
---|
129 | st->setTextureName(PMWeightRun->getPMWeightTetureName());
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | OgrePathMapRenderTechniqueFactory::OgrePathMapRenderTechniqueFactory()
|
---|
134 | {
|
---|
135 | typeName = "PathMap";
|
---|
136 | }
|
---|
137 |
|
---|
138 | OgreRenderTechnique* OgrePathMapRenderTechniqueFactory::createInstance(
|
---|
139 | IllumTechniqueParams* params,
|
---|
140 | Pass* pass,
|
---|
141 | OgreRenderable* parentRenderable,
|
---|
142 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
143 | {
|
---|
144 | parseParams(params);
|
---|
145 |
|
---|
146 | OgrePathMapRenderTechnique* result = new OgrePathMapRenderTechnique(
|
---|
147 | pass,
|
---|
148 | parentRenderable,
|
---|
149 | parentTechniqueGroup);
|
---|
150 |
|
---|
151 | return result;
|
---|
152 | }
|
---|
153 |
|
---|