#include "OgrePathMapRenderTechnique.h" #include "OgreTechniqueGroup.h" #include "OgreIlluminationManager.h" #include "OgrePMWeightComputeRenderingRun.h" OgrePathMapRenderTechnique::OgrePathMapRenderTechnique( Pass* pass, OgreRenderable* parentRenderable, OgreTechniqueGroup* parentTechniqueGroup) :RenderTechnique( parentRenderable, parentTechniqueGroup), OgreRenderTechnique(pass, parentRenderable, parentTechniqueGroup) { this->clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentRenderable->getName()); //insert new pass Ogre::Technique* techn = pass->getParent(); Technique::PassIterator it = techn->getPassIterator(); int index = 0; while(it.hasMoreElements()) { if( it.getNext() == pass) break; index++; it.moveNext(); } Pass* newpass = pathMapPass = techn->createPass(); newpass->setVertexProgram("GTP/PathMap_VS"); newpass->setFragmentProgram("GTP/PathMap_PS"); //bind vertex program parameters GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer(); Vparams->setNamedAutoConstant("WorldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); //bind fragment program parameters GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer(); int prmxres = clusters->pathMapResolution * clusters->count; int prmyres = clusters->pathMapResolution; while(prmxres > 4096) { prmxres /= 2; prmyres *= 2; } int prmnt[2] = {prmxres / clusters->pathMapResolution, prmyres / clusters->pathMapResolution}; float halfPixel[2] = {0.5 / prmxres, 0.5 / prmyres}; Vector4 pathMapParameters(prmnt[0],prmnt[1],halfPixel[0],halfPixel[1]); Fparams->setNamedConstant("prmAtlasTilesHalfPixel",pathMapParameters); unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize(); Fparams->setNamedConstant("allClusterCount", (float) clustercount); PathMapClusters* clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentOgreRenderable->getName()); Fparams->setNamedConstant("clusterCount", (float) clusters->count); TextureUnitState* st = newpass->createTextureUnitState(); st->setTextureFiltering(TFO_BILINEAR); st->setTextureAddressingMode(TextureUnitState::TAM_BORDER); st->setTextureBorderColour(ColourValue::Green); st->setTextureName(clusters->pathMapTextureFilename); createWeightIndexTexture(); st = newpass->createTextureUnitState(); st->setTextureFiltering(TFO_NONE); st->setTextureAddressingMode(TextureUnitState::TAM_BORDER); st->setTextureBorderColour(ColourValue::Red); st->setTextureName(weightIndexTexture->getName()); st = newpass->createTextureUnitState(); st->setTextureFiltering(TFO_NONE); st->setTextureAddressingMode(TextureUnitState::TAM_BORDER); st->setTextureBorderColour(ColourValue::Blue); //newpass->setSceneBlending(SBT_MODULATE); newpass->setSceneBlending(SBF_ONE, SBF_ZERO); newpass->setDepthBias(1); } OgrePathMapRenderTechnique::~OgrePathMapRenderTechnique() { } void OgrePathMapRenderTechnique::createWeightIndexTexture() { PathMapClusters* clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentOgreRenderable->getName()); int width = clusters->count / 4; TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(this->parentOgreRenderable->getName() + "_PMWeightIndexTexture", "default", TEX_TYPE_1D, width, 1, 0, 0, PF_FLOAT32_RGBA, TU_DYNAMIC_WRITE_ONLY); weightIndexTexture = texPtr.getPointer(); float *weightIndices = new float[clusters->count]; PixelBox lockBox(width, 1, 1, PF_FLOAT32_RGBA, weightIndices); for(int j = 0; j< clusters->count; j++) weightIndices[j] = clusters->clusters[j]; weightIndexTexture->getBuffer()->blitFromMemory(lockBox); delete[] weightIndices; } void OgrePathMapRenderTechnique::update(unsigned long frameNum) { LightList lights; SceneManager* sm = Root::getSingleton()._getCurrentSceneManager(); sm->_populateLightList(Vector3(0,0,0), 1000, lights); //TODO //TODO set weights for(int i = 0 ; i < 1; i++) { String lightName = lights.at(0)->getName(); OgreIlluminationManager::getSingleton().createPerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP); OgreIlluminationManager::getSingleton().updatePerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP, frameNum); OgrePMWeightComputeRenderingRun* PMWeightRun = (OgrePMWeightComputeRenderingRun*) OgreIlluminationManager::getSingleton().getPerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP)->asOgreRenderingRun(); TextureUnitState* st =pathMapPass->getTextureUnitState(2); st->setTextureName(PMWeightRun->getPMWeightTetureName()); } } OgrePathMapRenderTechniqueFactory::OgrePathMapRenderTechniqueFactory() { typeName = "PathMap"; } OgreRenderTechnique* OgrePathMapRenderTechniqueFactory::createInstance( IllumTechniqueParams* params, Pass* pass, OgreRenderable* parentRenderable, OgreTechniqueGroup* parentTechniqueGroup) { parseParams(params); OgrePathMapRenderTechnique* result = new OgrePathMapRenderTechnique( pass, parentRenderable, parentTechniqueGroup); return result; }