#include "OgreDistanceCubeMapRenderTechnique.h" #include "OgreTechniqueGroup.h" #include "OgreDistanceCubeMapRenderingRun.h" OgreDistanceCubeMapRenderTechnique::OgreDistanceCubeMapRenderTechnique(unsigned long startFrame, unsigned long cubeMapUpdateInterval, unsigned int cubeMapResolution, unsigned char texID, bool useDistCalc, bool useFaceAngleCalc, float distTolerance, float angleTolerance, bool updateAllFace, Pass* pass, OgreRenderable* parentRenderable, OgreTechniqueGroup* parentTechniqueGroup) :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup), DistanceCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, parentRenderable, parentTechniqueGroup), RenderTechnique(parentRenderable, parentTechniqueGroup) { this->texID = texID; if(sharedRuns->getRun(ILLUMRUN_DISTANCE_CUBEMAP) == 0) sharedRuns->addRun(ILLUMRUN_DISTANCE_CUBEMAP, createDistanceCubeMapRun()); distanceCubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_DISTANCE_CUBEMAP)); } OgreDistanceCubeMapRenderTechnique::~OgreDistanceCubeMapRenderTechnique() { } void OgreDistanceCubeMapRenderTechnique::update(unsigned long frameNum) { DistanceCubeMapRenderTechnique::update(frameNum); } void OgreDistanceCubeMapRenderTechnique::distanceCubeMapRunChanged(RenderingRun* run) { OgreDistanceCubeMapRenderingRun* cuberun =(OgreDistanceCubeMapRenderingRun*) (run->asOgreRenderingRun()); String cubemapname = cuberun->getDistanceCubeMapTextureName(); pass->getTextureUnitState(texID)->setTextureName(cubemapname); } void OgreDistanceCubeMapRenderTechnique::distanceCubeMapRunUpdated(RenderingRun* run) { GpuProgramParametersSharedPtr fpParams = pass->getFragmentProgramParameters(); Vector3 center = ((OgreSharedRuns*) sharedRuns)->getRootPosition(ILLUMRUN_DISTANCE_CUBEMAP); fpParams->setNamedConstant("lastCenter",center); } RenderingRun* OgreDistanceCubeMapRenderTechnique::createDistanceCubeMapRun() { return new OgreDistanceCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(), parentOgreRenderable->getName() + "_DISTANCECUBEMAP", startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace); } ///Technique Parsers namespace CausticCubemapParsers { void parseStartFrame(String& params, RenderTechniqueFactory* factory) { OgreDistanceCubeMapRenderTechniqueFactory* f = (OgreDistanceCubeMapRenderTechniqueFactory*) factory; f->startFrame = StringConverter::parseUnsignedLong(params); } void parseCubeMapUpdateInterval(String& params, RenderTechniqueFactory* factory) { OgreDistanceCubeMapRenderTechniqueFactory* f = (OgreDistanceCubeMapRenderTechniqueFactory*) factory; f->cubeMapUpdateInterval = StringConverter::parseUnsignedLong(params); } void parseCubeMapResolution(String& params, RenderTechniqueFactory* factory) { OgreDistanceCubeMapRenderTechniqueFactory* f = (OgreDistanceCubeMapRenderTechniqueFactory*) factory; f->cubeMapResolution = StringConverter::parseUnsignedInt(params); } void parseTexID(String& params, RenderTechniqueFactory* factory) { OgreDistanceCubeMapRenderTechniqueFactory* f = (OgreDistanceCubeMapRenderTechniqueFactory*) factory; f->texID = StringConverter::parseUnsignedInt(params); } void parseUseDistCalc(String& params, RenderTechniqueFactory* factory) { OgreDistanceCubeMapRenderTechniqueFactory* f = (OgreDistanceCubeMapRenderTechniqueFactory*) factory; // format: on/off tolerance(float) StringVector vecparams = StringUtil::split(params, " \t"); if(StringConverter::parseBool(vecparams[0]))//on { f->useDistCalc = true; if(vecparams.size()>1) { f->distTolerance = StringConverter::parseReal(vecparams[1]); } } else { f->useDistCalc = false; } } void parseUseFaceAngleCalc(String& params, RenderTechniqueFactory* factory) { OgreDistanceCubeMapRenderTechniqueFactory* f = (OgreDistanceCubeMapRenderTechniqueFactory*) factory; // format: on/off tolerance(float) StringVector vecparams = StringUtil::split(params, " \t"); if(StringConverter::parseBool(vecparams[0]))//on { f->useFaceAngleCalc = true; if(vecparams.size()>1) { f->angleTolerance = StringConverter::parseReal(vecparams[1]); } } else { f->useFaceAngleCalc = false; } } void parseUpdateAllFace(String& params, RenderTechniqueFactory* factory) { OgreDistanceCubeMapRenderTechniqueFactory* f = (OgreDistanceCubeMapRenderTechniqueFactory*) factory; f->updateAllFace = StringConverter::parseBool(params); } } ///Technique factory OgreDistanceCubeMapRenderTechniqueFactory::OgreDistanceCubeMapRenderTechniqueFactory() { typeName = "DistanceCubeMap"; using namespace CausticCubemapParsers; //register parsers this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame)); this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapUpdateInterval)); this->attributeParsers.insert(AttribParserList::value_type("resolution", (ILLUM_ATTRIBUTE_PARSER) parseCubeMapResolution)); this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseTexID)); this->attributeParsers.insert(AttribParserList::value_type("distance_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseDistCalc)); this->attributeParsers.insert(AttribParserList::value_type("face_angle_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseFaceAngleCalc)); this->attributeParsers.insert(AttribParserList::value_type("update_all_face", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace)); } OgreRenderTechnique* OgreDistanceCubeMapRenderTechniqueFactory::createInstance( IllumTechniqueParams* params, Pass* pass, OgreRenderable* parentRenderable, OgreTechniqueGroup* parentTechniqueGroup) { //reset parameters startFrame = 1; cubeMapUpdateInterval = 1; cubeMapResolution = 256; texID = 1; useDistCalc = 1; useFaceAngleCalc = false; distTolerance = 2.0; angleTolerance = 2.0; updateAllFace = false; parseParams(params); OgreDistanceCubeMapRenderTechnique* result = new OgreDistanceCubeMapRenderTechnique( startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, pass, parentRenderable, parentTechniqueGroup); return result; }