[SOLVED] Texture animation problem with shader

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
havokentity
Halfling
Posts: 71
Joined: Tue Mar 31, 2009 8:01 am

[SOLVED] Texture animation problem with shader

Post by havokentity » Tue Mar 16, 2010 2:32 pm

Hi all,

After much googling and much debugging I am still unable to get texture animation working with texture matrix in my shader.

I have a a vertex shader with a

a float4x4 textureMatrix

and in its program definition for ogre I have textureMatrix linked to its relevant auto parameter like so,

param_named_auto textureMatrix texture_matrix 1

my texture unit is the 2nd texture unit, so 1 is the right extra_param

my texture unit has scroll_anim 0.1 0.001

In fixed function this animates fine, but in my shader it doesn't work, I've tried in both the fragment program and in the vertex program, both don't work somehow.

I transform my texture coord with my texture matrix in shader, like so, (using Cg)

op.uv.xy = mul(textureMatrix, float4(uv.xy, 0, 1)).xy;

Should work technically right?

thanks.
Last edited by havokentity on Sun Mar 21, 2010 5:43 am, edited 1 time in total.
0 x

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4291
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: Texture animation problem with shader

Post by spacegaier » Tue Mar 16, 2010 3:24 pm

Asked something similar as well: http://www.ogre3d.org/forums/viewtopic.php?f=3&t=56295

I only tried rotate_anim and scroll_anim though...
0 x
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...

User avatar
havokentity
Halfling
Posts: 71
Joined: Tue Mar 31, 2009 8:01 am

Re: Texture animation problem with shader

Post by havokentity » Tue Mar 16, 2010 5:15 pm

Hi spacegaier,

Thanks for the reply, guess it has to be done manually as scroll_anim and rotate_anim don't seem to work with shaders. I had assumed they would work.

I wonder if you or anyone knows whats the purpose of texture_matrix auto parameter (refer: http://www.ogre3d.org/docs/manual/manual_23.html#SEC128)

I could have sworn its for passing the texture matrix to the programmable pipeline.

Anyone know how to affect this matrix to produce texture animations via script?

Thanks
0 x

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Re: Texture animation problem with shader

Post by sinbad » Wed Mar 17, 2010 5:49 pm

The texture_matrix autoparam should give you the same base texture matrix, see the TextureUnitState implementation - the same common texture matrix is used in all cases.
0 x

User avatar
havokentity
Halfling
Posts: 71
Joined: Tue Mar 31, 2009 8:01 am

Re: Texture animation problem with shader

Post by havokentity » Fri Mar 19, 2010 3:45 pm

Thanks for the reply sinbad,

But, when when I bind to the texture_matrix auto param, I transform my texture coord by that matrix, but there is nothing rendered (looks like a null matrix).
Shouldn't the default TextureUnitState pass atleast an Identity ?

Thanks.
0 x

User avatar
havokentity
Halfling
Posts: 71
Joined: Tue Mar 31, 2009 8:01 am

Re: Texture animation problem with shader

Post by havokentity » Sat Mar 20, 2010 8:02 pm

const Radian& Ogre::TextureUnitState::getTextureRotate ( void ) const
const Matrix4& Ogre::TextureUnitState::getTextureTransform ( void ) const

Gets the current texture transformation matrix.

Remarks:
Causes a reclaculation of the matrix if any parameters have been changed via setTextureScroll, setTextureScale and setTextureRotate.

Note:
Has no effect in the programmable pipeline.

Thats from the docs, so I guess that texture_matrix is null in programmable pipeline unless explicitly set in C++

Edit: I took a look at the implementation and I think that recalcTextureMatrix, doesn't get called when there is a vertex/fragment program.
Why is that? Wouldn't it be useful to have the texture matrix automations work with the programmable pipeline?

Thanks
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7147
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 16

Re: Texture animation problem with shader

Post by Kojack » Sun Mar 21, 2010 2:40 am

I just tested using the texture matrix auto param in a vertex shader in ogre 1.7, works fine. Scrolling animation works, identity is passed to the shader if no texture commands are used, etc.

material:

Code: Select all

vertex_program kojackvp cg
{
	source kojack.cg
	entry_point kojack_vp
	profiles vs_1_1 arbvp1
}

material kojack
{
    technique
    {

		pass
		{

			vertex_program_ref kojackvp
			{
				param_named_auto worldViewProj worldviewproj_matrix
				param_named_auto texturemat texture_matrix 0
				param_named ambient float4 1 1 1 1
			}

			texture_unit
			{
				texture beachstones.jpg
				scroll_anim 0.0 0.1
			}
		}
	}
}
cg file:

Code: Select all

void kojack_vp(float4 position : POSITION,
						  float2 uv		  : TEXCOORD0,
						  
						  out float4 oPosition : POSITION,
						  out float2 oUv	   : TEXCOORD0,
						  out float4 colour    : COLOR,

						  uniform float4x4 worldViewProj,
						  uniform float4x4 texturemat,
						  uniform float4 ambient)
{
	oPosition = mul(worldViewProj, position);
	oUv = mul(texturemat,float4(uv,0,1)).xy;
	colour = ambient;
}
I also tried binding the texture matrix to a second texture unit using the value 1 in the auto param line like you did, and that worked fine too.
0 x

User avatar
havokentity
Halfling
Posts: 71
Joined: Tue Mar 31, 2009 8:01 am

Re: Texture animation problem with shader

Post by havokentity » Sun Mar 21, 2010 5:43 am

Hi Kojack,

Thanks for the reply and the confirmation that this does indeed work. I seem to have found out why it didn't work for me.


I noticed in your program, you specified the auto param for texture_matrix in the vertex_program_ref, where as I was specifying it in
default params for the vertex_program (I was also using pass inheritance).

When I moved the texture_matrix auto param to the vertex_program_ref, it works fine! Scroll also works.
Luckily you and sinbad replied to this thread, otherwise, I'd have been lead to believe this won't work and implemented UV animation manually with custom
parameters. This saves a lot of time/energy.

So for anyone encountering this problem in the future: Put the texture_matrix auto param in the vertex_program_ref.

EDIT: @spacegaier, it works!!

EDIT2: Is this intended behaviour for material scripts ?

Thanks a lot Kojack.

PS: I'm curious to know why the other matrices worked with auto param in the default_params list with the vertex_program.
0 x

Post Reply