2D Toolkit Forum

2D Toolkit => Support => Topic started by: Companella on June 26, 2013, 02:08:42 pm

Title: about uv animation
Post by: Companella on June 26, 2013, 02:08:42 pm
dear any~
why i use tk2d/BlendVertexColor, but the uv animation is invalid ?
and the tk2d/LitBlendVertexColor is valid, but the image to be darken...
 :(
Title: Re: about uv animation
Post by: unikronsoftware on June 26, 2013, 02:21:49 pm
How is it invalid? Need more info, please.
Title: Re: about uv animation
Post by: Companella on June 26, 2013, 03:10:51 pm
i try modify the Main Tex.offset.x,  is invalid...
Title: Re: about uv animation
Post by: Companella on June 26, 2013, 03:33:03 pm
(http://ntu.me/di/TQPN/1.jpg)
Title: Re: about uv animation
Post by: unikronsoftware on June 26, 2013, 06:03:39 pm
You cant modify the material offset values in the default shaders, as that code is optimised out. Your textures may appear anywhere in the atlas, and may even be rotated and/or scaled, and as such its not very useful to offset/scale UVs. If you really need to do this, I suggest modifying the shader to add the one line required to enable this.
Title: Re: about uv animation
Post by: Companella on June 27, 2013, 04:12:38 am
thank you ~
if i need, use another shader is ok ! like the Unlit/Texture.
Title: Re: about uv animation
Post by: unikronsoftware on June 27, 2013, 11:40:42 am
Thats fine. You shouldn't use a lit shader, unless you also turn on normals on the sprite collection.
Title: Re: about uv animation
Post by: Companella on June 28, 2013, 03:58:38 am
i see~ thank you
Title: Re: about uv animation
Post by: semiessessi on July 09, 2013, 04:20:09 pm
You cant modify the material offset values in the default shaders, as that code is optimised out. Your textures may appear anywhere in the atlas, and may even be rotated and/or scaled, and as such its not very useful to offset/scale UVs. If you really need to do this, I suggest modifying the shader to add the one line required to enable this.

Can you share what this one line is?

I am interested in animating UVs in general... having done this from scratch and in several other contexts I find it surprising that there seems to be no 'easy' way to do this, nor any sort of functionality supporting this within Unity.

I am curious why the optimised shaders lock the texture offsets... unless you are using an atlas AND animating UVs or doing something else needing weird and wonderful tiling then I don't see any benefit to that since you can do all the work on CPU/VS/GS etc. depending on your target hardware, and prevent the overhead in the fragment shader from the parameter dependent operations.

Still... I'd still like to try and measure the performance when changing the offset - if it works it will work.
Title: Re: about uv animation
Post by: unikronsoftware on July 09, 2013, 04:42:32 pm
Its just that TRANSFORM_TEX thing that needs to be put in the VS.
            o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
instead of:
                                o.texcoord = v.texcoord;

Its just not gonna work when the texture is atlased, and its not in the default shaders, as its 1 extra instruction on VS (multiply-add) and its easy to type some random numbers in there and all of a sudden all atlases don't work any more. tk2d fits textures in any way it can, and requires geometry changes most of the time.

Title: Re: about uv animation
Post by: Companella on July 10, 2013, 03:49:47 am
So, at this situation, use another shader is the best way.
Title: Re: about uv animation
Post by: unikronsoftware on July 10, 2013, 11:13:16 am
Yes, if you need to animate UVs, use another shader or modify the built in one.