Changeset 2366 for GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticReceiverRenderTechnique.cpp
- Timestamp:
- 05/12/07 14:21:03 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticReceiverRenderTechnique.cpp
r2299 r2366 11 11 SceneBlendFactor passBlendingSRC, 12 12 SceneBlendFactor passBlendingDEST, 13 bool createNewPasses, 14 int startTextureUnitID, 15 String casterCenterVariableName, 16 String attenuationVariableName, 13 17 Pass* pass, 14 18 OgreRenderable* parentRenderable, … … 23 27 this->causticVertexProgram = causticVertexProgram; 24 28 this->causticFragmentProgram = causticFragmentProgram; 25 26 //insert new passes 27 Ogre::Technique* techn = pass->getParent(); 28 Technique::PassIterator it = techn->getPassIterator(); 29 30 int index = 0; 31 while(it.hasMoreElements()) 32 { 33 if( it.getNext() == pass) 34 break; 29 this->createNewPasses = createNewPasses; 30 this->startTextureUnitID = startTextureUnitID; 31 this->casterCenterVariableName = casterCenterVariableName; 32 this->attenuationVariableName = attenuationVariableName; 33 34 if(createNewPasses) 35 { 36 //insert new passes 37 Ogre::Technique* techn = pass->getParent(); 38 Technique::PassIterator it = techn->getPassIterator(); 39 40 int index = 0; 41 while(it.hasMoreElements()) 42 { 43 if( it.getNext() == pass) 44 break; 45 index++; 46 it.moveNext(); 47 } 48 35 49 index++; 36 it.moveNext(); 37 } 38 39 index++; 40 for(int i = 0; i < maxcasters; i++) 41 { 42 int lastpass = techn->getNumPasses(); 43 Pass* newpass = techn->createPass(); 44 passes.push_back(newpass); 45 46 newpass->setVertexProgram(causticVertexProgram); 47 newpass->setFragmentProgram(causticFragmentProgram); 48 49 GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer(); 50 Vparams->setNamedAutoConstant("WorldViewProj", 51 GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); 52 Vparams->setNamedAutoConstant("World", 53 GpuProgramParameters::ACT_WORLD_MATRIX); 54 GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer(); 55 //Fparams->setNamedConstant("cubeMapCameraPosition", Vector3(0,0,0)); 56 57 TextureUnitState* st = newpass->createTextureUnitState(); 58 TextureUnitState* st2 = newpass->createTextureUnitState(); 59 60 st->setTextureFiltering(TFO_BILINEAR); 61 st2->setTextureFiltering(TFO_BILINEAR); 62 63 newpass->setSceneBlending(passBlendingSRC, passBlendingDEST); 64 newpass->setDepthBias(1); 65 66 techn->movePass(lastpass, index); 50 for(int i = 0; i < maxcasters; i++) 51 { 52 int lastpass = techn->getNumPasses(); 53 Pass* newpass = techn->createPass(); 54 passes.push_back(newpass); 55 56 newpass->setVertexProgram(causticVertexProgram); 57 newpass->setFragmentProgram(causticFragmentProgram); 58 59 GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer(); 60 Vparams->setNamedAutoConstant("WorldViewProj", 61 GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); 62 Vparams->setNamedAutoConstant("World", 63 GpuProgramParameters::ACT_WORLD_MATRIX); 64 GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer(); 65 //Fparams->setNamedConstant("cubeMapCameraPosition", Vector3(0,0,0)); 66 67 TextureUnitState* st = newpass->createTextureUnitState(); 68 TextureUnitState* st2 = newpass->createTextureUnitState(); 69 70 st->setTextureFiltering(TFO_BILINEAR); 71 st2->setTextureFiltering(TFO_BILINEAR); 72 73 newpass->setSceneBlending(passBlendingSRC, passBlendingDEST); 74 newpass->setDepthBias(1); 75 76 techn->movePass(lastpass, index); 77 } 67 78 } 68 79 … … 82 93 &causticCasters, 83 94 maxcasters); 95 84 96 //fill passes 85 for(unsigned int i = 0; i < passes.size(); i++)97 for(unsigned int i = 0; i < maxcasters; i++) 86 98 { 87 99 if(causticCasters.size() > i) 88 100 { 89 90 101 //update caustic caster 91 102 causticCasters.at(i)->updateRun(ILLUMRUN_PHOTONMAP, frameNum); … … 96 107 (OgreCausticCubeMapRenderingRun*) causticCasters.at(i)-> 97 108 getRun(ILLUMRUN_CAUSTIC_CUBEMAP)->asOgreRenderingRun(); 98 passes.at(i)->getTextureUnitState(0)->setTextureName( 109 110 Pass* passToSet = this->pass; 111 int textureUnit = startTextureUnitID + i; 112 if(createNewPasses) 113 { 114 passToSet = passes.at(i); 115 passToSet->setActive(true); 116 textureUnit = 0; 117 } 118 119 passToSet->getTextureUnitState(textureUnit)->setTextureName( 99 120 cauCubeRun->getCausticCubeMapTextureName()); 100 101 OgreCubeMapRenderingRun* distCubeRun = 102 (OgreCubeMapRenderingRun*) causticCasters.at(i)-> 103 getRun(ILLUMRUN_DISTANCE_CUBEMAP)->asOgreRenderingRun(); 104 passes.at(i)->getTextureUnitState(1)->setTextureName( 105 distCubeRun->getCubeMapTextureName()); 106 107 //set caster position 108 GpuProgramParameters* Fparams = passes.at(i)->getFragmentProgramParameters().getPointer(); 109 Fparams->setNamedConstant("cubeMapCameraPosition", 110 causticCasters.at(i)->getRootPosition(ILLUMRUN_CAUSTIC_CUBEMAP)); 111 Fparams->setNamedConstant("attenuation", cauCubeRun->getAttenuation()); 112 passes.at(i)->setActive(true); 121 122 //set caster position nad caustic attenuation 123 GpuProgramParameters* Fparams = passToSet->getFragmentProgramParameters().getPointer(); 124 String centerVarName = casterCenterVariableName; 125 String attenuationVarName = attenuationVariableName; 126 if(!createNewPasses) 127 { 128 centerVarName += String("[") + StringConverter::toString(i) + String("]"); 129 attenuationVarName += String("[") + StringConverter::toString(i) + String("]"); 130 } 131 Fparams->setNamedConstant(centerVarName, 132 causticCasters.at(i)->getRootPosition(ILLUMRUN_CAUSTIC_CUBEMAP)); 133 Fparams->setNamedConstant(attenuationVarName, 134 cauCubeRun->getAttenuation()); 113 135 } 114 else 136 else if(createNewPasses) 115 137 passes.at(i)->setActive(false); 116 117 138 } 118 139 } … … 201 222 f->passBlendingDEST = convertBlendFactor(vecparams[1]) ; 202 223 } 203 } 204 } 224 } 225 226 void parseCreateNewPasses(String& params, RenderTechniqueFactory* factory) 227 { 228 OgreCausticReceiverRenderTechniqueFactory* f = (OgreCausticReceiverRenderTechniqueFactory*) factory; 229 f->createNewPasses = StringConverter::parseBool(params); 230 } 231 232 void parseStartTexID(String& params, RenderTechniqueFactory* factory) 233 { 234 OgreCausticReceiverRenderTechniqueFactory* f = (OgreCausticReceiverRenderTechniqueFactory*) factory; 235 f->startTextureUnitID = StringConverter::parseInt(params); 236 } 237 238 void parseCenterVarName(String& params, RenderTechniqueFactory* factory) 239 { 240 OgreCausticReceiverRenderTechniqueFactory* f = (OgreCausticReceiverRenderTechniqueFactory*) factory; 241 f->casterCenterVariableName = params; 242 } 243 244 void parseAttenuationVarName(String& params, RenderTechniqueFactory* factory) 245 { 246 OgreCausticReceiverRenderTechniqueFactory* f = (OgreCausticReceiverRenderTechniqueFactory*) factory; 247 f->attenuationVariableName = params; 248 } 249 } 250 205 251 OgreCausticReceiverRenderTechniqueFactory::OgreCausticReceiverRenderTechniqueFactory() 206 252 { … … 213 259 this->attributeParsers.insert(AttribParserList::value_type("fragment_program_name", (ILLUM_ATTRIBUTE_PARSER) parseFragmentProgram)); 214 260 this->attributeParsers.insert(AttribParserList::value_type("pass_blending", (ILLUM_ATTRIBUTE_PARSER) parsePassBlending)); 215 261 this->attributeParsers.insert(AttribParserList::value_type("new_passes", (ILLUM_ATTRIBUTE_PARSER) parseCreateNewPasses)); 262 this->attributeParsers.insert(AttribParserList::value_type("start_tex_id", (ILLUM_ATTRIBUTE_PARSER) parseStartTexID)); 263 this->attributeParsers.insert(AttribParserList::value_type("center_var_name", (ILLUM_ATTRIBUTE_PARSER) parseCenterVarName)); 264 this->attributeParsers.insert(AttribParserList::value_type("attenuation_var_name", (ILLUM_ATTRIBUTE_PARSER) parseAttenuationVarName)); 216 265 } 217 266 … … 228 277 passBlendingSRC = SBF_DEST_COLOUR; 229 278 passBlendingDEST = SBF_ONE; 279 createNewPasses = true; 280 startTextureUnitID = 0; 281 casterCenterVariableName = "cubeMapCameraPosition"; 282 String attenuationVariableName = "attenuation"; 230 283 231 284 parseParams(params); … … 237 290 passBlendingSRC, 238 291 passBlendingDEST, 292 createNewPasses, 293 startTextureUnitID, 294 casterCenterVariableName, 295 attenuationVariableName, 239 296 pass, 240 297 parentRenderable,
Note: See TracChangeset
for help on using the changeset viewer.