Hello Guest

Author Topic: tile sprite uvs in shader  (Read 3861 times)

nachobeard

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 28
    • View Profile
tile sprite uvs in shader
« on: January 14, 2016, 01:11:26 am »
Hi

I'm working on a small shader effect for a tiled sprite where I wobble the v coordinate to simulate rippling water.
I just added this to wobble the v-coordinate:

Code: [Select]
i.texcoord.y += sin(i.worldpos.y + _Time.z) * 0.009f;(worldpos is the world position of the pixel we're rendering)


the problem is that when I push the v coordinate beyond the edge of the sprite in the sprite collection it reads whatever happens to be next to it.
the desired behaviour here would be to tile the v coordinate so if it goes off the top edge of the sprite in the sprite collection it'll warp back to the bottom instead of reading outside the sprite.
note that this is a tiled sprite with a sprite animator.

I've attached a wobblyWater.GIF where you can see what it actually looks like.  at the bottom the v coordinate goes outside the sprite in the sprite collection so I get empty space and some garbage.  if the v coordinate would loop back at the top it'd look perfect.
noWobble.GIF is the same thing without wobbling.

what would be the best way to tile the v coordinate so it always stays within the currently visible frame of the sprite?

my suspicion is, if I get the current frame's bounds within the spritesheet I can probably do the tiling in the shader.
but I don't know how to get the current frame's bounds.

thanks!





« Last Edit: January 14, 2016, 01:33:32 am by nachobeard »

nachobeard

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: tile sprite uvs in shader
« Reply #1 on: January 23, 2016, 12:10:42 am »
bump!  :o

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tile sprite uvs in shader
« Reply #2 on: February 02, 2016, 10:27:27 pm »
Hi there.

Sorry for the late reply. I implemented something like this on top of the TileX / Y pad mode but since I never had any use for it, it never went in to 2D Toolkit properly. Email support and I'll send you a patch to try out, if it works it can go in the next version :)