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 |
|
---|
53 | TextureUnitState* st = newpass->createTextureUnitState();
|
---|
54 | st->setTextureFiltering(TFO_BILINEAR);
|
---|
55 | st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
|
---|
56 | st->setTextureBorderColour(ColourValue::Blue);
|
---|
57 | st->setTextureName(clusters->pathMapTextureFilename);
|
---|
58 |
|
---|
59 | //newpass->setSceneBlending(SBT_MODULATE);
|
---|
60 | newpass->setSceneBlending(SBF_ONE, SBF_ZERO);
|
---|
61 | newpass->setDepthBias(1);
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | }
|
---|
66 |
|
---|
67 | OgrePathMapRenderTechnique::~OgrePathMapRenderTechnique()
|
---|
68 | {
|
---|
69 |
|
---|
70 | }
|
---|
71 |
|
---|
72 | void OgrePathMapRenderTechnique::update(unsigned long frameNum)
|
---|
73 | {
|
---|
74 | LightList lights;
|
---|
75 | SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
|
---|
76 | sm->_populateLightList(Vector3(0,0,0), 1000, lights); //TODO
|
---|
77 | //TODO set weights
|
---|
78 | PathMapClusters* clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentOgreRenderable->getName());
|
---|
79 | float *actualWeights = new float[clusters->count];//TODO = 0
|
---|
80 | for(int i = 0 ; i < 1; i++)
|
---|
81 | {
|
---|
82 | String lightName = lights.at(0)->getName();
|
---|
83 | OgreIlluminationManager::getSingleton().createPerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP);
|
---|
84 | OgreIlluminationManager::getSingleton().updatePerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP, frameNum);
|
---|
85 | OgrePMWeightComputeRenderingRun* PMWeightRun = (OgrePMWeightComputeRenderingRun*)
|
---|
86 | OgreIlluminationManager::getSingleton().getPerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP)->asOgreRenderingRun();
|
---|
87 |
|
---|
88 | float* weights = PMWeightRun->getWeights();
|
---|
89 |
|
---|
90 | for(int j = 0; j< clusters->count; j++)
|
---|
91 | actualWeights[j] = weights[clusters->clusters[j]];
|
---|
92 |
|
---|
93 | }
|
---|
94 |
|
---|
95 | GpuProgramParameters* Fparams = pathMapPass->getFragmentProgramParameters().getPointer();
|
---|
96 | Fparams->setNamedConstant("weights", actualWeights, clusters->count);
|
---|
97 | }
|
---|
98 |
|
---|
99 | OgrePathMapRenderTechniqueFactory::OgrePathMapRenderTechniqueFactory()
|
---|
100 | {
|
---|
101 | typeName = "PathMap";
|
---|
102 | }
|
---|
103 |
|
---|
104 | OgreRenderTechnique* OgrePathMapRenderTechniqueFactory::createInstance(
|
---|
105 | IllumTechniqueParams* params,
|
---|
106 | Pass* pass,
|
---|
107 | OgreRenderable* parentRenderable,
|
---|
108 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
109 | {
|
---|
110 | parseParams(params);
|
---|
111 |
|
---|
112 | OgrePathMapRenderTechnique* result = new OgrePathMapRenderTechnique(
|
---|
113 | pass,
|
---|
114 | parentRenderable,
|
---|
115 | parentTechniqueGroup);
|
---|
116 |
|
---|
117 | return result;
|
---|
118 | }
|
---|
119 |
|
---|