Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Sprite Sheet / Pixels Per Unit / Shader Graph woes.

Discussion in '2D' started by mrjbones, Sep 14, 2020.

  1. mrjbones

    mrjbones

    Joined:
    Aug 27, 2020
    Posts:
    5
    First test: I have a shader made with shader graph and a material using that shader. I drag a 256x256 pixel sprite into my scene, change the material on the sprite renderer, and all is well.

    Second test: Then I import a sprite sheet that is 2048x1536 and comprises 48 different 256x256 pixel sprites including the one from above. Max Size is set to 2048 and pixels per unit is set to 100 (same as the settings for the "first test" sprite above.)

    I drag one of the sprites from the sprite sheet into my scene and it looks identical to the one in the first test. But when I apply my material, it looks as if the material were applied to a smaller sprite that was then scaled up.

    Here is a screen shot of the two 256x256px sprites with the same material applied.

    I don't understand why the sprite from the sheet (the one on the right) is different somehow from the one I imported as a standalone 256x256px image.

     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    One possibility is this: https://issuetracker.unity3d.com/issues/shader-graph-uv-node-uses-whole-sprite-atlas-uvs-instead-of-individual-sprite-when-entering-the-play-mode
    The same principle should apply to spritesheets. Basically, it's the same problem as in this thread, just a different manifestation.

    If your material is dependent on per-sprite UVs, then individual sprite vs spritesheet will produce a difference. I don't in fact know what your material is doing, so perhaps my guess is wrong. If so, you may need to describe what the material is doing.
     
    mrjbones likes this.
  3. mrjbones

    mrjbones

    Joined:
    Aug 27, 2020
    Posts:
    5
    The shader graph is pretty simple... just a _MainTex property into a Sample Texture 2D's Texture(T2) input. I don't touch the UV input. The rest is a couple voronoi nodes, a few math nodes, and a color node. I can screenshot it if necessary.

    One caveat is that I created it as an "Unlit Graph" and not as a "Sprite Unlit Graph (Experimental)"... not sure if that makes a difference.
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    I can only guess without more info. My guess is that your Voronoi are using the UVs of the spritesheet. Try using a Position Node with World or Absolute World setting and plug that into your noise. This changes the effect, but advanatangeously make it relative to the World rather than UVs. If world-relativity isn't acceptable for the effect you want, another possibility is to re-scale it for the spritesheet. It looks like if you change the noise's scale it should make the "crystals" - for lack of a better term - smaller. That will compensate for a larger spritesheet, relative to the individual sprite.
     
    Last edited: Sep 14, 2020
    mrjbones likes this.
  5. mrjbones

    mrjbones

    Joined:
    Aug 27, 2020
    Posts:
    5
    Well, that was a pretty darn good guess. You nailed it.

    Thank you kindly. I don't think I would've figured that out. Much appreciated.