source: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp @ 2185

Revision 2185, 2.8 KB checked in by szirmay, 17 years ago (diff)
Line 
1#include "OgrePathMapRenderTechnique.h"
2#include "OgreTechniqueGroup.h"
3#include "OgreIlluminationManager.h"
4
5
6OgrePathMapRenderTechnique::OgrePathMapRenderTechnique(                                                                                 
7                                                                                                Pass* pass,
8                                                                                                OgreRenderable* parentRenderable,
9                                                                                                OgreTechniqueGroup* parentTechniqueGroup)
10                                                        :RenderTechnique( parentRenderable, parentTechniqueGroup),
11                                                        OgreRenderTechnique(pass, parentRenderable, parentTechniqueGroup)
12{               
13        this->clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentRenderable->getName());
14       
15        //insert new pass
16        Ogre::Technique* techn = pass->getParent();
17        Technique::PassIterator it = techn->getPassIterator();
18       
19        int index = 0;
20        while(it.hasMoreElements())
21        {
22                if( it.getNext() == pass)
23                        break;
24                index++;
25                it.moveNext();
26        }
27       
28        Pass* newpass = techn->createPass();
29       
30        newpass->setVertexProgram("GTP/PathMap_VS");
31        newpass->setFragmentProgram("GTP/PathMap_PS");
32       
33        //bind vertex program parameters
34        GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer();
35        Vparams->setNamedAutoConstant("WorldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
36        //bind fragment program parameters
37        GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer();
38        int prmxres = clusters->pathMapResolution * clusters->count;
39        int prmyres = clusters->pathMapResolution;
40        while(prmxres > 4096)
41        {
42                prmxres /= 2;
43                prmyres *= 2;           
44        }
45        int prmnt[2] = {prmxres / clusters->pathMapResolution, prmyres / clusters->pathMapResolution};
46
47        float halfPixel[2] = {0.5 / prmxres, 0.5 / prmyres};
48        Fparams->setNamedConstant("prmAtlasTiles",prmnt,2);
49    Fparams->setNamedConstant("atlasHalfPixel", halfPixel, 2);
50                       
51        TextureUnitState* st = newpass->createTextureUnitState();               
52        st->setTextureFiltering(TFO_BILINEAR);
53        st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
54        st->setTextureBorderColour(ColourValue::Blue);
55        st->setTextureName(clusters->pathMapTextureFilename);
56
57        //newpass->setSceneBlending(SBT_MODULATE);
58        newpass->setSceneBlending(SBF_ONE, SBF_ZERO);
59
60        newpass->setDepthBias(1);
61}
62
63OgrePathMapRenderTechnique::~OgrePathMapRenderTechnique()
64{
65
66}
67
68void OgrePathMapRenderTechnique::update(unsigned long frameNum)
69{       
70        //TODO set weights
71}
72
73OgrePathMapRenderTechniqueFactory::OgrePathMapRenderTechniqueFactory()
74{
75        typeName = "PathMap";
76}
77
78OgreRenderTechnique* OgrePathMapRenderTechniqueFactory::createInstance(
79                                                                                IllumTechniqueParams* params,
80                                                                                Pass* pass,
81                                                                                OgreRenderable* parentRenderable,
82                                                                                OgreTechniqueGroup* parentTechniqueGroup)
83{       
84        parseParams(params);
85
86        OgrePathMapRenderTechnique* result = new OgrePathMapRenderTechnique(
87                                                                                                pass,
88                                                                                                parentRenderable,
89                                                                                                parentTechniqueGroup); 
90
91        return result;
92}
93
Note: See TracBrowser for help on using the repository browser.