Dynamic terrain material

Pieron

16-09-2008 21:44:02

Hello. I'm totally newbie in OGRE and 3d graphics programming

For now, I making editor and i get texture issue, when the terrain material is created dinamically
My render is OpenGL, Linux, OGRE 1.6.0RC1.

If i'm using pre-existing material (ETTerrain) material showed correctly.
I'm guess, this is not texture loading issue - if i'm using single texture for material (without splatting manager) - everything is fine.
My code is:


mSplattingManager = new ET::SplattingManager("ETSplatting","ET",128,128,3);
mSplattingManager->setNumTextures(6);

Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName("TerrainMaterial");
material->removeAllTechniques();
Ogre::Technique * mainTech = material->createTechnique();
Ogre::Pass * pass = mainTech->createPass();
pass->setLightingEnabled(false);
pass->setVertexProgram("ET/Programs/VSLodMorph2");
pass->setFragmentProgram("ET/Programs/PSSplat2");
pass->_load();
pass->getFragmentProgram()->setParameter("splatScaleX","20");
pass->getFragmentProgram()->setParameter("splatScaleZ","20");

Ogre::TextureUnitState * texture_unit = pass->createTextureUnitState();
texture_unit->setTextureName("ETSplatting0");
texture_unit = pass->createTextureUnitState();
texture_unit->setTextureName("ETSplatting1");
texture_unit = pass->createTextureUnitState();
texture_unit->setTextureName("splatting0.png");
texture_unit = pass->createTextureUnitState();
texture_unit->setTextureName("splatting1.png");
texture_unit = pass->createTextureUnitState();
texture_unit->setTextureName("splatting2.png");
texture_unit = pass->createTextureUnitState();
texture_unit->setTextureName("splatting3.png");
texture_unit = pass->createTextureUnitState();
texture_unit->setTextureName("splatting4.png");
texture_unit = pass->createTextureUnitState();
texture_unit->setTextureName("splatting5.png");

mTerrainManager->setMaterial(material);

Just trying create demo material, but dynamically, nothing more.

Screen:


Ogre.log is clean (no errors)

Thanks for any help and sorry for my bad english ^_^

CABAListic

16-09-2008 23:03:15

What you see is the splatting textures being stretched over the whole terrain, i. e. your scale parameters for the fragment program are not working.

That's because the "setParameter" function for GpuPrograms are not what you think they are, they're just some generic functions from an internal Ogre context. What you really need to do is delete those two lines:

pass->getFragmentProgram()->setParameter("splatScaleX","20");
pass->getFragmentProgram()->setParameter("splatScaleZ","20");

and replace them with

pass->getFragmentProgramParameters()->setNamedConstant("splatScaleX", 20);
pass->getFragmentProgramParameters()->setNamedConstant("splatScaleZ", 20);

Pieron

16-09-2008 23:25:42

with

pass->getFragmentProgramParameters()->setNamedConstant("splatScaleX", Ogre::Real(20));
pass->getFragmentProgramParameters()->setNamedConstant("splatScaleZ", Ogre::Real(20));

working!!
thanks for help

uzik

06-03-2012 23:21:24


delete those two lines:

pass->getFragmentProgram()->setParameter("splatScaleX","20");
pass->getFragmentProgram()->setParameter("splatScaleZ","20");

and replace them with

pass->getFragmentProgramParameters()->setNamedConstant("splatScaleX", 20);
pass->getFragmentProgramParameters()->setNamedConstant("splatScaleZ", 20);


I think that should probably be:

pass->getFragmentProgramParameters()->setNamedConstant("splatScaleX", 20.0f);
pass->getFragmentProgramParameters()->setNamedConstant("splatScaleZ", 20.0f);


The overloaded setNamedConstant method with an integer parameter will assert because the list of integer parameters in the object is empty.
You need to call the method with float parameters since the fragment program has float parameters.