sprite aspect ratio

I’ll try to describe this as best I can, since showing code won’t help and will just confuse the issue.

I have some sprites that I’m lerping in shadergraph from one state to another. I change the sprites in the shadergraph texture by getting the sprites from a dictionary. That’s fine and works the way I want. However, the sprite sizes are distorted unless I put an image in the sprite renderer of the correct size of the sprite beforehand. I have to do this every time I change the sprites in the shadergraph if the sprites I’m using are different sizes.

I could make all the sprites the same size and put an image in the sprite renderer of a fixed size and leave it at that, but that’s too restrictive. I could get the size of the sprite before I put it in the shadergraph and change the sprite renderer image to one with the right size, which is what I’ve been doing but it’s too much messing around when there must be a simpler way of dealing with the problem.

If I don’t put a blank image in the sprite renderer the sprite in the shadergraph won’t show up.

I think you are changing the underlying texture of a sprite in runtime with a shader and it ends up being not in the correct aspect ratio.

Sprites are essentially UV coordinates on a texture, you can change the underlying texture and it’ll still display the same area of the new texture. If your texture has different width/height ratio, it’ll of course show a squeezed or stretched texture.

no UV’s = no texture area displayed. If you put a “mesh type = tight” sprite that covers a unique cut out part of the texture it’ll keep showing that area in the new texture. For this problem you should use “mesh type = full rect” for your sprites so they cover the entire area of the texture

You just need to scale the x,y of the sprite renderer’s gameobject according to the new texture’s width&height / old texture’s width&height. Perhaps you could use a plane but I am not sure if it’ll fix anything, you’ll have to scale the x,y of the plane too if I am not mistaken.

Cheers

1 Like

Thanks for trying to help. I don’t know enough about uv in shader to fix this. So what I had to do is just put the sprite image in the spriterenderer when I put it in the texture part of the shader. Doesn’t cause any delay that I can notice so I can live with it for now, but I’m not sure if it means I’m actually overlaying the same sprite on top of eachother.