[2.2] Hlms texture rotation

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
pmobr
Gnoblar
Posts: 7
Joined: Mon Jan 23, 2006 2:15 pm
x 3

[2.2] Hlms texture rotation

Post by pmobr »

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
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4830
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1097
Contact:

Re: [2.2] Hlms texture rotation

Post by dark_sylinc »

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:

Code: Select all

@undefpiece( DeclareUvModifierMacros )
@piece( DeclareUvModifierMacros )
   #define UV_DIFFUSE(x) mul( matrixRotation, (x) )
   ...
@end
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.
2- Also, is it possible to offset uv of an Unlit texture?
See ShadowMapDebuggingGameState::createShadowMapDebugOverlays which uses setAnimationMatrix to set an offset.

Cheers
pmobr
Gnoblar
Posts: 7
Joined: Mon Jan 23, 2006 2:15 pm
x 3

Re: [2.2] Hlms texture rotation

Post by pmobr »

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:

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);
Thank you very much for your help, now the texture rotation works perfectly. :D

Olivier
jwwalker
Halfling
Posts: 68
Joined: Thu Aug 12, 2021 10:06 pm
x 3

Re: [2.2] Hlms texture rotation

Post by jwwalker »

Anyone interested in the "lit" case of texture rotation should see this topic.
Post Reply