[790] | 1 | #include "OgreCausticRecieverRenderTechnique.h"
|
---|
| 2 | #include "OgreTechniqueGroup.h"
|
---|
| 3 | #include "OgreIlluminationManager.h"
|
---|
| 4 | #include "OgreCausticCubeMapRenderingRun.h"
|
---|
| 5 | #include "OgreDistanceCubeMapRenderingRun.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 |
|
---|
[808] | 59 | newpass->setSceneBlending(SBF_DEST_COLOUR, SBF_ONE);
|
---|
[949] | 60 | newpass->setDepthBias(5);
|
---|
[808] | 61 | //newpass->setSceneBlending(SBT_ADD);
|
---|
[790] | 62 |
|
---|
| 63 | techn->movePass(lastpass, index);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | OgreCausticRecieverRenderTechnique::~OgreCausticRecieverRenderTechnique()
|
---|
| 69 | {
|
---|
| 70 |
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | void OgreCausticRecieverRenderTechnique::update(unsigned long frameNum)
|
---|
| 74 | {
|
---|
| 75 | //find nearest casters
|
---|
| 76 | causticCasters.clear();
|
---|
| 77 | OgreIlluminationManager::getSingleton().getNearestCausticCasters(
|
---|
| 78 | ((OgreSharedRuns*)sharedRuns)->getRootPosition(),
|
---|
| 79 | &causticCasters,
|
---|
| 80 | maxcasters);
|
---|
| 81 | //fill passes
|
---|
| 82 | for(unsigned int i = 0; i < passes.size(); i++)
|
---|
| 83 | {
|
---|
| 84 | if(causticCasters.size() > i)
|
---|
| 85 | {
|
---|
| 86 |
|
---|
| 87 | //update caustic caster
|
---|
| 88 | causticCasters.at(i)->updateRun(ILLUMRUN_PHOTONMAP, frameNum);
|
---|
| 89 | causticCasters.at(i)->updateRun(ILLUMRUN_CAUSTIC_CUBEMAP, frameNum);
|
---|
| 90 |
|
---|
| 91 | //set texture to pass
|
---|
| 92 | OgreCausticCubeMapRenderingRun* cauCubeRun =
|
---|
| 93 | (OgreCausticCubeMapRenderingRun*) causticCasters.at(i)->
|
---|
| 94 | getRun(ILLUMRUN_CAUSTIC_CUBEMAP)->asOgreRenderingRun();
|
---|
| 95 | passes.at(i)->getTextureUnitState(0)->setTextureName(
|
---|
| 96 | cauCubeRun->getCausticCubeMapTextureName());
|
---|
| 97 |
|
---|
| 98 | OgreDistanceCubeMapRenderingRun* cauPhotonRun =
|
---|
| 99 | (OgreDistanceCubeMapRenderingRun*) causticCasters.at(i)->
|
---|
| 100 | getRun(ILLUMRUN_DISTANCE_CUBEMAP)->asOgreRenderingRun();
|
---|
| 101 | passes.at(i)->getTextureUnitState(1)->setTextureName(
|
---|
| 102 | cauPhotonRun->getDistanceCubeMapTextureName());
|
---|
| 103 |
|
---|
| 104 | //set caster position
|
---|
| 105 | GpuProgramParameters* Fparams = passes.at(i)->getFragmentProgramParameters().getPointer();
|
---|
| 106 | Fparams->setNamedConstant("cubeMapCameraPosition",
|
---|
| 107 | causticCasters.at(i)->getRootPosition(ILLUMRUN_CAUSTIC_CUBEMAP));
|
---|
| 108 | passes.at(i)->setActive(true);
|
---|
| 109 | }
|
---|
| 110 | else
|
---|
| 111 | passes.at(i)->setActive(false);
|
---|
| 112 |
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[836] | 116 |
|
---|
| 117 | namespace CausticRecieverParsers
|
---|
| 118 | {
|
---|
| 119 | ///Technique parsers
|
---|
| 120 | void parseMaxCasters(String& params, RenderTechniqueFactory* factory)
|
---|
| 121 | {
|
---|
| 122 | OgreCausticRecieverRenderTechniqueFactory* f = (OgreCausticRecieverRenderTechniqueFactory*) factory;
|
---|
| 123 | f->maxcasters = StringConverter::parseInt(params);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | void parseVertexProgram(String& params, RenderTechniqueFactory* factory)
|
---|
| 127 | {
|
---|
| 128 | OgreCausticRecieverRenderTechniqueFactory* f = (OgreCausticRecieverRenderTechniqueFactory*) factory;
|
---|
| 129 | f->causticVertexProgram = params;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | void parseFragmentProgram(String& params, RenderTechniqueFactory* factory)
|
---|
| 133 | {
|
---|
| 134 | OgreCausticRecieverRenderTechniqueFactory* f = (OgreCausticRecieverRenderTechniqueFactory*) factory;
|
---|
| 135 | f->causticFragmentProgram = params;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 | OgreCausticRecieverRenderTechniqueFactory::OgreCausticRecieverRenderTechniqueFactory()
|
---|
| 139 | {
|
---|
| 140 | typeName = "CausticReciever";
|
---|
| 141 |
|
---|
| 142 | using namespace CausticRecieverParsers;
|
---|
| 143 | //register parsers
|
---|
| 144 | this->attributeParsers.insert(AttribParserList::value_type("max_caster_count", (ILLUM_ATTRIBUTE_PARSER) parseMaxCasters));
|
---|
| 145 | this->attributeParsers.insert(AttribParserList::value_type("vertex_program_name", (ILLUM_ATTRIBUTE_PARSER) parseVertexProgram));
|
---|
| 146 | this->attributeParsers.insert(AttribParserList::value_type("fragment_program_name", (ILLUM_ATTRIBUTE_PARSER) parseFragmentProgram));
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | OgreRenderTechnique* OgreCausticRecieverRenderTechniqueFactory::createInstance(
|
---|
| 150 | IllumTechniqueParams* params,
|
---|
| 151 | Pass* pass,
|
---|
| 152 | OgreRenderable* parentRenderable,
|
---|
| 153 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
| 154 | {
|
---|
| 155 | //reset parameters
|
---|
| 156 | maxcasters = 1;
|
---|
| 157 | causticVertexProgram = "GameTools/Caustic/DefaultVS";
|
---|
| 158 | causticFragmentProgram = "GameTools/Caustic/DefaultPS";
|
---|
| 159 |
|
---|
| 160 | parseParams(params);
|
---|
| 161 |
|
---|
| 162 | OgreCausticRecieverRenderTechnique* result = new OgreCausticRecieverRenderTechnique(
|
---|
| 163 | maxcasters,
|
---|
| 164 | causticVertexProgram,
|
---|
| 165 | causticFragmentProgram,
|
---|
| 166 | pass,
|
---|
| 167 | parentRenderable,
|
---|
| 168 | parentTechniqueGroup);
|
---|
| 169 |
|
---|
| 170 | return result;
|
---|
| 171 | }
|
---|