Hi!
Nickak2003 wrote: ↑Wed Sep 23, 2020 3:12 pm
Code: Select all
Ogre::HlmsPbsDatablock* dataBlock = dynamic_cast<Ogre::HlmsPbsDatablock*>(Ogre::Root::getSingleton().getHlmsManager()->getHlms(Ogre::HLMS_PBS)->getDefaultDatablock());
This is wrong. You're only changing the default datablock, which is only used when we couldn't find a valid material to apply, thus this datablock is used as fallback.
If you want to grab the proper datablock, either do:
Code: Select all
Ogre::HlmsPbsDatablock* dataBlock = static_cast<Ogre::HlmsPbsDatablock*>(getHlms(Ogre::HLMS_PBS)->getDatablock( "tree1_lod_2" ));
or (if you have the leave model):
Code: Select all
Ogre::HlmsDatablock *baseDatablock = subItem->getDatablock();
assert( dynamic_cast<Ogre::HlmsPbsDatablock *>( baseDatablock ) );
Ogre::HlmsPbsDatablock* dataBlock =
static_cast<Ogre::HlmsPbsDatablock*>( baseDatablock );
Nickak2003 wrote: ↑Wed Sep 23, 2020 3:12 pm
Code: Select all
dataBlock->setTransparency(0);
dataBlock->setAlphaTest(Ogre::CMPF_LESS_EQUAL);
dataBlock->setAlphaTestThreshold(0.5f);
You're combining transparency and alpha testing; and by doing so you block transparent shadows from working. However because this code is altering the default datablock it wasn't going to work.
Nickak2003 wrote: ↑Wed Sep 23, 2020 3:12 pm
Code: Select all
hlms tree1_lod_2 pbs
{
scene_blend alpha_blend
depth_write on
diffuse_map tree1_lod_2_diffuse.png
specular_map tree1_lod_2_diffuse.png
normal_map tree1_lod_2_normal.png
}
Alpha blending and depth_write don't combine well. Depth writes should be off if alpha blending is used.
Solutions:
First, the bark wood material must be separate from the leaves.
There are two main ways to render leaves:
- Leaves use alpha testing, shadow casters also use alpha testing. This is faster, plays very well with depth order and what most games do (recommended)
- Leaves use alpha blending, shadow casters use alpha testing. This is slower but the leaves during render are softer (look better antialiased) but if leaves get rendered out of order (very difficult to control) it's going to look wrong. This is difficult to fix and hence it's rarely used in games.
To achieve the first one, just do:
Code: Select all
hlms tree1_lod_2 pbs
{
// Alternatively, 'alpha_test greater 0.5'
alpha_test less 0.5
diffuse_map tree1_lod_2_diffuse.png
specular_map tree1_lod_2_diffuse.png
normal_map tree1_lod_2_normal.png
}
0.5 is an arbitrary threshold. You may tweak that value.
Although you can alpha testing on both the bark wood and the leaf materials; using it on bark wood is going to waste a lot of GPU performance; which is why you should separate the two into different materials.
To achieve the second method, just do:
Code: Select all
hlms tree1_lod_2 pbs
{
alpha_from_textures true
// Alternatively, 'alpha_test greater 0.5 true'
alpha_test less 0.5 true
diffuse_map tree1_lod_2_diffuse.png
specular_map tree1_lod_2_diffuse.png
normal_map tree1_lod_2_normal.png
}
That's it.
Cheers