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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question 2D vertex shader on multiple sprite renderers

Discussion in '2D' started by microbrewer, Jan 29, 2022.

  1. microbrewer

    microbrewer

    Joined:
    Jun 6, 2020
    Posts:
    12
    Hi everyone,
    I am very new to shaders and I am trying to use the shader graph tool to skew a 2d sprite texture to create a shadow effect. In principle, I got it working:
    Screenshot from 2022-01-29 01-35-38.png
    The bottom sprite is using the standard sprite material, the top one is using a material with my shader. Both are using the exact same sprite asset.

    However, weird things happen when I use the shader on two or more sprites. Suddenly it seems like the skew is applied from the world space origin:
    Screenshot from 2022-01-29 01-32-27.png
    Note that the two sprites are located exactly above each other in terms of world space coordinates, at (0,0,0) and (0,4,0), respectively - just as in the picture above.

    Here is the part of my shader graph that produces the skew effect:
    Screenshot from 2022-01-29 01-42-03.png

    Everything works fine as long as I only attach the shader material to single sprite renderer - or if I create a new material for each renderer such that no material is used by more than one renderer. I originally came at this issue from here: https://www.sector12games.com/skewshear-vertex-shader/ and the shader code posted there produces the exact same effect as far as I can tell. I feel like I am missing something fundamental here about how shaders work. So if anyone could help, I'd much appreciate it. :)
    Thanks!
     
    Last edited: Jan 29, 2022
  2. LoveraSantiago

    LoveraSantiago

    Joined:
    Nov 20, 2017
    Posts:
    18
    Any solution?
     
  3. microbrewer

    microbrewer

    Joined:
    Jun 6, 2020
    Posts:
    12
    Yes, actually. Sorry for the late reply.

    The solution was to use the texture UV instead of the position node. Although I still don't fully understand the nature of the effect described above.
     
  4. LoveraSantiago

    LoveraSantiago

    Joined:
    Nov 20, 2017
    Posts:
    18
    ok. Thanks I'm gonna give a try.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,546
    This has to be the longest conversation delay I've ever seen on these forums. :)
     
    MousePods, Ted_Wikman and Kurt-Dekker like this.
  6. LoveraSantiago

    LoveraSantiago

    Joined:
    Nov 20, 2017
    Posts:
    18
    yeah! I have to agree......
     
    TKDR and MelvMay like this.
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,546
    I see what you did there! :)
     
  8. LoveraSantiago

    LoveraSantiago

    Joined:
    Nov 20, 2017
    Posts:
    18
    I could not resist
     
    TKDR and MelvMay like this.