Hello Guest

Author Topic: Global Tiling Position  (Read 9450 times)

stuntboots

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Global Tiling Position
« on: March 07, 2014, 04:55:07 am »
Hi there,

I'm wondering if it's possible to set up objects that all use the same tiling coordinates? So basically I move an object, and the tile stays in position while the object moves around? Basically so that wherever I move an object, when it touches another object with the same tile, the tiles will match perfectly?

Any and all help appreciated!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Global Tiling Position
« Reply #1 on: March 07, 2014, 09:39:25 am »
The easiest (and most efficient) way to do this is to modify the shader so instead of using internal texture co-ordinates it uses world coordinates. You also probably don't want this texture to be atlased as it won't be trivial to tile it then.

stuntboots

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Global Tiling Position
« Reply #2 on: March 07, 2014, 10:14:57 am »
Thanks for the reply! I don't suppose you have any direction on the modified shader? Also what does it not being trivial mean?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Global Tiling Position
« Reply #3 on: March 07, 2014, 10:20:14 am »
It should be straightforward with the shader - just take one of the tk2d shaders, and do replace it like this maybe -
            o.texcoord = mul(_Object2World, v.vertex).xy * 0.1;
You'll have to tweak the multiplier in the end to get it to tile the way you want.

If you want to do this from an atlased texture, then you'll have to manually tile which is considerably more complicated.

stuntboots

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Global Tiling Position
« Reply #4 on: March 07, 2014, 10:01:34 pm »
It's definitely creating the effect I'm after, in that when I move the game object around it just scrolls through the tile, but the tiling is behaving very strangely no matter what I change the multiplier to.



That's the tile in the top right corner, and the result below (One to illustrate the actual tiles.) I copied the BlendVertexColor shader because that's what I was using for the initial tiling result.

Thanks again for the help!

stuntboots

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Global Tiling Position
« Reply #5 on: March 07, 2014, 10:10:23 pm »
Additionally when I press 'Play', the material switches back out to BlendVertexColor for some reason. Obviously user error, but I'm not sure what my error is, hehe.

stuntboots

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Global Tiling Position
« Reply #6 on: March 10, 2014, 03:06:26 am »
Hi again, sorry for the little bump. I tried our old friend Google for some global position shader help to no avail, was just hoping you could help me out? Also let me know whether I need to edit the 2dTK shaders directly, as it seems to change the shader at run time.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Global Tiling Position
« Reply #7 on: March 10, 2014, 10:59:32 am »
You need to create a new shader. You also need to assign the shader to the atlas material, not just the sprite.
About the position thing - you'll probably have to change the scales for it to work better. Try 0.01, then 10, and keep decreasing and increasing to work out whats best.

stuntboots

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Global Tiling Position
« Reply #8 on: March 11, 2014, 02:23:11 am »
Excellent, got it! Thanks for your help. I'm also having an issue where if I have a 128x128 sprite, and try to put it into a 128x128 atlas, it tells me it can't fit. I had a look at the tutorial and it told me to either increase the atlas or dice the sprite, but it's just the one sprite (for the aforementioned tiling), and it should technically fit perfectly, what am I missing?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Global Tiling Position
« Reply #9 on: March 11, 2014, 01:32:54 pm »
Its adding padding. If you only  have one sprite, you don't need an atlas. You can simply use sprite from texture - http://2dtoolkit.com/docs/latest/reference/sprite_from_selected_texture.html

stuntboots

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Global Tiling Position
« Reply #10 on: March 12, 2014, 05:27:09 am »
Ah great. I'd noticed the error when trying to get four sprites on a large atlas as well. Can I ask what the reasoning is for padding when you're dealing with absolute pixel values?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Global Tiling Position
« Reply #11 on: March 12, 2014, 11:44:35 am »
You need padding for filtering. You get weird edge bleeding artefacts, shimmering edge lines, otherwise.

stuntboots

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Global Tiling Position
« Reply #12 on: March 13, 2014, 09:53:59 pm »
Ah, excellent! Thanks for all your help!

stuntboots

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Global Tiling Position
« Reply #13 on: March 14, 2014, 06:30:37 am »
Hi again!

So I'm trying to use the iTween FadeTo tween, and with my version of the BlendVertexColor shader it's telling me there's no color property '_Color'. Obviously this is because it doesn't exist, but I'm wondering if there's a way to add alpha/the _Color property to the shader?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Global Tiling Position
« Reply #14 on: March 14, 2014, 10:23:37 am »
You will have to add that in manually to the shader. Refer to the unity shader source (https://unity3d.com/unity/download/archive) for examples on how to do it.
In most cases you don't really want to do that that - I'm guessing you want to change the colour of one sprite, and not all sprites using that atlas? If so, have a look at this thread (http://2dtoolkit.com/forum/index.php/topic,1164.msg5545.html#msg5545) - it uses hotween to do that. I don't use iTween so I can't give you any advice on how you'd achieve the same with that.