1 | #include "OgreCausticRecieverRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreIlluminationManager.h"
|
---|
4 | #include "OgreCausticCubeMapRenderingRun.h"
|
---|
5 | #include "OgreCubeMapRenderingRun.h"
|
---|
6 |
|
---|
7 | OgreCausticRecieverRenderTechnique::OgreCausticRecieverRenderTechnique(
|
---|
8 | int maxcasters,
|
---|
9 | String causticVertexProgram,
|
---|
10 | String causticFragmentProgram,
|
---|
11 | Pass* pass,
|
---|
12 | OgreRenderable* parentRenderable,
|
---|
13 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
14 | :RenderTechnique( parentRenderable, parentTechniqueGroup),
|
---|
15 | OgreRenderTechnique(pass, parentRenderable, parentTechniqueGroup),
|
---|
16 | CausticRecieverRenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
17 | {
|
---|
18 | this->maxcasters = maxcasters;
|
---|
19 | this->causticVertexProgram = causticVertexProgram;
|
---|
20 | this->causticFragmentProgram = causticFragmentProgram;
|
---|
21 |
|
---|
22 | //insert new passes
|
---|
23 | Ogre::Technique* techn = pass->getParent();
|
---|
24 | Technique::PassIterator it = techn->getPassIterator();
|
---|
25 |
|
---|
26 | int index = 0;
|
---|
27 | while(it.hasMoreElements())
|
---|
28 | {
|
---|
29 | if( it.getNext() == pass)
|
---|
30 | break;
|
---|
31 | index++;
|
---|
32 | it.moveNext();
|
---|
33 | }
|
---|
34 |
|
---|
35 | index++;
|
---|
36 | for(int i = 0; i < maxcasters; i++)
|
---|
37 | {
|
---|
38 | int lastpass = techn->getNumPasses();
|
---|
39 | Pass* newpass = techn->createPass();
|
---|
40 | passes.push_back(newpass);
|
---|
41 |
|
---|
42 | newpass->setVertexProgram(causticVertexProgram);
|
---|
43 | newpass->setFragmentProgram(causticFragmentProgram);
|
---|
44 |
|
---|
45 | GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer();
|
---|
46 | Vparams->setNamedAutoConstant("worldViewProj",
|
---|
47 | GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
|
---|
48 | Vparams->setNamedAutoConstant("world",
|
---|
49 | GpuProgramParameters::ACT_WORLD_MATRIX);
|
---|
50 | GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer();
|
---|
51 | Fparams->setNamedConstant("cubeMapCameraPosition", Vector3(0,0,0));
|
---|
52 |
|
---|
53 | TextureUnitState* st = newpass->createTextureUnitState();
|
---|
54 | TextureUnitState* st2 = newpass->createTextureUnitState();
|
---|
55 |
|
---|
56 | st->setTextureFiltering(TFO_BILINEAR);
|
---|
57 | st2->setTextureFiltering(TFO_BILINEAR);
|
---|
58 |
|
---|
59 | newpass->setSceneBlending(SBF_DEST_COLOUR, SBF_ONE);
|
---|
60 | //newpass->setSceneBlending(SBF_ONE, SBF_ZERO);
|
---|
61 | newpass->setDepthBias(5);
|
---|
62 | //newpass->setSceneBlending(SBT_ADD);
|
---|
63 |
|
---|
64 | techn->movePass(lastpass, index);
|
---|
65 | }
|
---|
66 |
|
---|
67 | }
|
---|
68 |
|
---|
69 | OgreCausticRecieverRenderTechnique::~OgreCausticRecieverRenderTechnique()
|
---|
70 | {
|
---|
71 |
|
---|
72 | }
|
---|
73 |
|
---|
74 | void OgreCausticRecieverRenderTechnique::update(unsigned long frameNum)
|
---|
75 | {
|
---|
76 | //find nearest casters
|
---|
77 | causticCasters.clear();
|
---|
78 | OgreIlluminationManager::getSingleton().getNearestCausticCasters(
|
---|
79 | ((OgreSharedRuns*)sharedRuns)->getRootPosition(),
|
---|
80 | &causticCasters,
|
---|
81 | maxcasters);
|
---|
82 | //fill passes
|
---|
83 | for(unsigned int i = 0; i < passes.size(); i++)
|
---|
84 | {
|
---|
85 | if(causticCasters.size() > i)
|
---|
86 | {
|
---|
87 |
|
---|
88 | //update caustic caster
|
---|
89 | causticCasters.at(i)->updateRun(ILLUMRUN_PHOTONMAP, frameNum);
|
---|
90 | causticCasters.at(i)->updateRun(ILLUMRUN_CAUSTIC_CUBEMAP, frameNum);
|
---|
91 |
|
---|
92 | //set texture to pass
|
---|
93 | OgreCausticCubeMapRenderingRun* cauCubeRun =
|
---|
94 | (OgreCausticCubeMapRenderingRun*) causticCasters.at(i)->
|
---|
95 | getRun(ILLUMRUN_CAUSTIC_CUBEMAP)->asOgreRenderingRun();
|
---|
96 | passes.at(i)->getTextureUnitState(0)->setTextureName(
|
---|
97 | cauCubeRun->getCausticCubeMapTextureName());
|
---|
98 |
|
---|
99 | OgreCubeMapRenderingRun* distCubeRun =
|
---|
100 | (OgreCubeMapRenderingRun*) causticCasters.at(i)->
|
---|
101 | getRun(ILLUMRUN_DISTANCE_CUBEMAP)->asOgreRenderingRun();
|
---|
102 | passes.at(i)->getTextureUnitState(1)->setTextureName(
|
---|
103 | distCubeRun->getCubeMapTextureName());
|
---|
104 |
|
---|
105 | //set caster position
|
---|
106 | GpuProgramParameters* Fparams = passes.at(i)->getFragmentProgramParameters().getPointer();
|
---|
107 | Fparams->setNamedConstant("cubeMapCameraPosition",
|
---|
108 | causticCasters.at(i)->getRootPosition(ILLUMRUN_CAUSTIC_CUBEMAP));
|
---|
109 | Fparams->setNamedConstant("attenuation", cauCubeRun->getAttenuation());
|
---|
110 | passes.at(i)->setActive(true);
|
---|
111 | }
|
---|
112 | else
|
---|
113 | passes.at(i)->setActive(false);
|
---|
114 |
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | namespace CausticRecieverParsers
|
---|
120 | {
|
---|
121 | ///Technique parsers
|
---|
122 | void parseMaxCasters(String& params, RenderTechniqueFactory* factory)
|
---|
123 | {
|
---|
124 | OgreCausticRecieverRenderTechniqueFactory* f = (OgreCausticRecieverRenderTechniqueFactory*) factory;
|
---|
125 | f->maxcasters = StringConverter::parseInt(params);
|
---|
126 | }
|
---|
127 |
|
---|
128 | void parseVertexProgram(String& params, RenderTechniqueFactory* factory)
|
---|
129 | {
|
---|
130 | OgreCausticRecieverRenderTechniqueFactory* f = (OgreCausticRecieverRenderTechniqueFactory*) factory;
|
---|
131 | f->causticVertexProgram = params;
|
---|
132 | }
|
---|
133 |
|
---|
134 | void parseFragmentProgram(String& params, RenderTechniqueFactory* factory)
|
---|
135 | {
|
---|
136 | OgreCausticRecieverRenderTechniqueFactory* f = (OgreCausticRecieverRenderTechniqueFactory*) factory;
|
---|
137 | f->causticFragmentProgram = params;
|
---|
138 | }
|
---|
139 |
|
---|
140 | }
|
---|
141 | OgreCausticRecieverRenderTechniqueFactory::OgreCausticRecieverRenderTechniqueFactory()
|
---|
142 | {
|
---|
143 | typeName = "CausticReciever";
|
---|
144 |
|
---|
145 | using namespace CausticRecieverParsers;
|
---|
146 | //register parsers
|
---|
147 | this->attributeParsers.insert(AttribParserList::value_type("max_caster_count", (ILLUM_ATTRIBUTE_PARSER) parseMaxCasters));
|
---|
148 | this->attributeParsers.insert(AttribParserList::value_type("vertex_program_name", (ILLUM_ATTRIBUTE_PARSER) parseVertexProgram));
|
---|
149 | this->attributeParsers.insert(AttribParserList::value_type("fragment_program_name", (ILLUM_ATTRIBUTE_PARSER) parseFragmentProgram));
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 | OgreRenderTechnique* OgreCausticRecieverRenderTechniqueFactory::createInstance(
|
---|
154 | IllumTechniqueParams* params,
|
---|
155 | Pass* pass,
|
---|
156 | OgreRenderable* parentRenderable,
|
---|
157 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
158 | {
|
---|
159 | //reset parameters
|
---|
160 | maxcasters = 1;
|
---|
161 | causticVertexProgram = "GameTools/Caustic/DefaultVS";
|
---|
162 | causticFragmentProgram = "GameTools/Caustic/DefaultPS";
|
---|
163 |
|
---|
164 | parseParams(params);
|
---|
165 |
|
---|
166 | OgreCausticRecieverRenderTechnique* result = new OgreCausticRecieverRenderTechnique(
|
---|
167 | maxcasters,
|
---|
168 | causticVertexProgram,
|
---|
169 | causticFragmentProgram,
|
---|
170 | pass,
|
---|
171 | parentRenderable,
|
---|
172 | parentTechniqueGroup);
|
---|
173 |
|
---|
174 | return result;
|
---|
175 | }
|
---|