Hi everyone,
I am porting an app from ogre1 to ogre2.
1- Everything work fine, however, in ogre1, i was able to rotate textures with "getTextureUnitState(0)->setTextureRotate" but i cannot find an equivalent in ogre V2.
I can scale and offset uv Pbs textures with "setDetailMapOffsetScale" function but i cant find the way to make rotation texture.
2- Also, is it possible to offset uv of an Unlit texture?
Thank you.
Olivier
[2.2] Hlms texture rotation
-
- OGRE Team Member
- Posts: 5436
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1343
Re: [2.2] Hlms texture rotation
Unlit supports arbitrary UV offset, rotation and scale via HlmsUnlitDatablock::setEnableAnimationMatrix and HlmsUnlitDatablock::setAnimationMatrix (see TextureAnimationControllerValue::recalcTextureMatrix for an example).
Pbs does not support UV rotation out of the box, and supports only offset and scale on detail textures, which is the most common feature for Pbs shaders.
Extension via custom piece files could be possible i.e. by UV_DIFFUSE et. all in UvModifierMacros_piece_ps.any via:
but sadly we don't provide an example of how to add custom pieces (i.e. where to fetch that matrix rotation from). There's resources but it's not for beginners.
Cheers
Pbs does not support UV rotation out of the box, and supports only offset and scale on detail textures, which is the most common feature for Pbs shaders.
Extension via custom piece files could be possible i.e. by UV_DIFFUSE et. all in UvModifierMacros_piece_ps.any via:
Code: Select all
@undefpiece( DeclareUvModifierMacros )
@piece( DeclareUvModifierMacros )
#define UV_DIFFUSE(x) mul( matrixRotation, (x) )
...
@end
See ShadowMapDebuggingGameState::createShadowMapDebugOverlays which uses setAnimationMatrix to set an offset.2- Also, is it possible to offset uv of an Unlit texture?
Cheers
-
- Gnoblar
- Posts: 7
- Joined: Mon Jan 23, 2006 2:15 pm
- x 3
Re: [2.2] Hlms texture rotation
Sorry, i hadn't seen the animationMatrix.
Unfortunately, the matrix rotation is done around the texture corner, not around the center like in ogrev1.
So, i had to make a circle translation of "sqrt(0.5)" radius according to the angle of rotation.
Here the code if someone need to rotate texture around center:
Thank you very much for your help, now the texture rotation works perfectly.
Olivier
Unfortunately, the matrix rotation is done around the texture corner, not around the center like in ogrev1.
So, i had to make a circle translation of "sqrt(0.5)" radius according to the angle of rotation.
Here the code if someone need to rotate texture around center:
Code: Select all
Ogre::HlmsUnlitDatablock* unlitdatablock = static_cast<Ogre::HlmsUnlitDatablock*>(materialDatablock);
Ogre::Matrix4 transformMatrix;
transformMatrix.makeTransform(
Ogre::Vector3(0.5f + sqrt(0.5f) * cos(fRot + 5.0f * M_PI / 4.0f), 0.5f + sqrt(0.5f) * sin(fRot + 5.0f * M_PI / 4.0f), 0),
Ogre::Vector3(1, 1, 1),
Ogre::Quaternion(Ogre::Radian(fRot), Ogre::Vector3(0, 0, 1)));
unlitdatablock->setEnableAnimationMatrix(iDiffuseMap, true);
unlitdatablock->setAnimationMatrix(iDiffuseMap, transformMatrix);
Olivier
-
- Goblin
- Posts: 248
- Joined: Thu Aug 12, 2021 10:06 pm
- Location: San Diego, CA, USA
- x 18
Re: [2.2] Hlms texture rotation
Anyone interested in the "lit" case of texture rotation should see this topic.