Hi all, so I have a texture that is 16x64 and what I’m trying to do is animate the UV coordinates such that the texture flows across the v-coordinate space over a set amount of time to give the illusion that the texture is flowing.
So far I defined the geometry’s vertex buffer such that the uv coordinates are within the 16x16 coordinate space so where u goes from 0…1 and v goes from 0…0.25 (which is 1 / 4). Next I defined the value animation as follows:
auto *animation = new ValueAnimation( context_ );
animation->SetKeyFrame( 0.f, Vector4( 0.f, 0.00f, 0.f, 1.f ) );
animation->SetKeyFrame( 2.f, Vector4( 0.f, 0.25f, 0.f, 1.f ) );
animation->SetKeyFrame( 4.f, Vector4( 0.f, 0.50f, 0.f, 1.f ) );
animation->SetKeyFrame( 8.f, Vector4( 0.f, 0.75f, 0.f, 1.f ) );
My understanding is then after 8 seconds, the texture will have flowed from the first 16x16 portion to the last 16x16 portion and will then loop to the first 16x16 frame portion.
Next I defined my material as follows and assigned the animation:
auto *mat = new Material( context_ );
mat->SetTechnique( 0, GetResource<Material>( "Techniques/DiffUnlitAlpha.xml" ) );
mat->SetTexture( TU_DIFFUSE, GetResource<Texture2D>( "Textures/WaterFlow.png" ) );
mat->SetVertexShaderDefines( "DIFFMAP VERTEXCOLOR" );
mat->SetPixelShaderDefines( "DIFFMAP VERTEXCOLOR" );
mat->SetScene( scene_ );
mat->SetShaderParameterAnimation( "VOffset", animation );
It’s my understanding that both cUOffset
and cVOffset
are built-in animation uniforms and are applied when the VS calls GetTexCoord
on the incoming UV coordinates and so there shouldn’t be any other code necessary to get this to work afaict.
If I don’t apply the animation, I get the first frame, first 16x16 portion of the water flow strip. But when I apply the animation, I don’t see anything being animated nor can I make out any portion of the texture that looks like any of the 16x16 frames.
So after some debugging, I found that the value for the offset needs to be provided as a Vector4 and not as a Vector2 as I originally thought. Making that change, I now see the animations; however they are not transitioning as I would have thought. Instead it appears it transitions as if no uvs are set, the blue water vertex color and then the texture animates in 1 pixel per frame until the original 16x16 texture is there if I were not applying any uv animations and then loops.
What I actually wanted here is to take my 16x64 texture, initially render the bottom part of the strip at 16x16 and then adjust the uv coordinates so that I move down the strip with each key frame until I reach the final 16x16 portion at the other end before I repeat.
This is clearly a UV keyframe issue now but I’m not sure what I did wrong.