Tiling Problem

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
crancran
Greenskin
Posts: 138
Joined: Wed May 05, 2010 3:36 pm
x 6

Tiling Problem

Post by crancran »

I am using the following code to generate a simple plane using the v1 namespace and converting it to v2:

Code: Select all

Ogre::Plane plane( Ogre::Vector3::UNIT_Y, 0 );
Ogre::v1::MeshPtr planeMeshv1 = Ogre::v1::MeshManager::getSingleton().createPlane(
  "PlaneV1",
  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
  plane, 10, 10, 20, 20, true, 
  1, 5, 5,
  Ogre::Vector3::UNIT_Z
);

Ogre::MeshPtr planeMesh = Ogre::MeshManager::getSingleton().createManual( "Plane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
planeMesh->importV1( planeMeshv1.get(), true, true, true );

Ogre::Item* item = sceneManager_->createItem( planeMesh );
item->setDatablockOrMaterialName( "SimpleFloor", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
The problem is with the uTile & vTile parameters on the original v1 mesh call.
Selection_029.png
By changing the values (5) to a value of (1), the tile problem goes away. I assume this is due to something in the shaders that aren't compatible with how we create tiled planes?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Tiling Problem

Post by dark_sylinc »

By default samplers in 2.1 are set to CLAMP, whereas here you likely want it to set to WRAP.

In JSON materials you can set them by simply setting the samplers to wrap:

Code: Select all

"sampler_name" :
{
    "min" : "linear",
    "mag" : "linear",
    "mip" : "linear",
    "u" : "wrap",
    "v" : "wrap",
    "w" : "wrap",
    "miplodbias" : 0,
    "max_anisotropic" : 1,
    "compare_function" : "disabled",
    "border" : [1, 1, 1, 1],
    "min_lod" : -3.40282347E+38,
    "max_lod" : 3.40282347E+38
}
See that both u,v,w were set to "wrap"

If you're not using JSON materials, the old material system won't let you modify the samplers via script, so you would have to do it via C++. The PbsMaterials sample is actually doing that:

Code: Select all

//Change the addressing mode of the roughness map to wrap via code.
//Detail maps default to wrap, but the rest to clamp.
assert( dynamic_cast<Ogre::HlmsPbsDatablock*>( item->getSubItem(0)->getDatablock() ) );
Ogre::HlmsPbsDatablock *datablock = static_cast<Ogre::HlmsPbsDatablock*>( item->getSubItem(0)->getDatablock() );
//Make a hard copy of the sampler block
Ogre::HlmsSamplerblock samplerblock( *datablock->getSamplerblock( Ogre::PBSM_ROUGHNESS ) );
samplerblock.mU = Ogre::TAM_WRAP;
samplerblock.mV = Ogre::TAM_WRAP;
samplerblock.mW = Ogre::TAM_WRAP;
//Set the new samplerblock. The Hlms system will
//automatically create the API block if necessary
datablock->setSamplerblock( Ogre::PBSM_ROUGHNESS, samplerblock );
In this case it's changing the roughness map's sampler to wrap.

Cheers
Matías
crancran
Greenskin
Posts: 138
Joined: Wed May 05, 2010 3:36 pm
x 6

Re: Tiling Problem

Post by crancran »

Thanks Mattias, I totally forgot about doing it that way with the HlmsSamplerblock (doh!) :D
Post Reply