Search Unity

Editing mobile shader to remove stretched tile

Discussion in '2D' started by geplourde, Jun 11, 2017.

  1. geplourde

    geplourde

    Joined:
    May 31, 2017
    Posts:
    23
    Greetings! I've been trying to find the right shader for my mobile project's assets. I want to make lighting effect tiles while also using a mobile shader. Lighting has worked fine, but any tiles that aren't a perfect square will get stretched to fit the square. I've been trying to make a custom shader but haven't found what I need to remedy the problem. I tried switching the rendering mode from Opaque to Cutout, but that did nothing. Does anyone know what the underlying issue is?
     

    Attached Files:

    Last edited: Jun 11, 2017
  2. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    Most likely it's not a shader problem but a aspect ratio problem.
    You have a couple of options. Scale your mesh to match the texture aspect ratio.
    Adjust the models uv coordinates, be careful of the wrap mode and boundary pixels.
    You can do this either with the model uv, or you should be able to get the same effect by adjusting the materials texture tiling values.

    The simplest would be to adjust your mesh or quads aspect ratio (adjust the scale to be non uniform ex: x=1 z=1.5) you won't have to worry about what's shows up outside the 0-1 uv ranges. Plus unity can still batch if you have the same material.
     
  3. geplourde

    geplourde

    Joined:
    May 31, 2017
    Posts:
    23
    Hmm that's odd. The problem doesn't persist with other shaders like sprites>default. I'll try this, although i've barely messed with mesh's such. Thank you!
     
  4. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    Without looking closer at that shader it's hard to say.
    But since that shader is made for sprites which are typically not always square. It maybe doing something to fix the ratio. But something somewhere must be giving that info. I think it's possible now with unity get info about the texture in the sampler, like it's size. So you could look at that, it might be what that shader is doing,

    Are you drawing these with unitys canvas and sprites? Or the sprite renderer?
    Or just a plane or quad with a texture?
     
  5. geplourde

    geplourde

    Joined:
    May 31, 2017
    Posts:
    23
    The sprite renderer. Im using tiled to design my maps, then import them using tiled2Unity and drag them in as a prefab from the inspector. I then try to change the shader on different pieces of the prefab, and keep getting these results.
    edit: I use the
     
    Last edited: Jun 12, 2017