Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Shader graph garbled texture

Discussion in 'Shader Graph' started by jmo_jon, Feb 1, 2020.

  1. jmo_jon

    jmo_jon

    Joined:
    Feb 25, 2017
    Posts:
    3
    Hi,

    I have a world map for a strategy game, what I want to achieve is that when the user clicks on a country, said country will highlight and I'll display a menu. My solution is that I have two planes, one with the visible map, and then in front of it a transparent object with every country filled with a unique colour. I can then lookup what country is clicked and display the needed information from the ray cast.

    What I'm struggling with is highlighting the country. I thought it'd be simple, and it very well might be but I can't wrap my head around it. What I've tried is creating a shader graph:
    garbled.png

    My idea is that my script will input the clicked colour to the shader, and the shader will replace the colour with my highlight colour, which feels pretty basic. All the countries are using the G and B channels only and then I convert the selected colour to R. To get the alpha I channel mask on red, mask it, invert that and put it into the alpha.

    But my output gets completely garbled from the start and the inverted mask thus ends up broken, and the end result is as you can see pretty out of whack with what I'm trying to achieve. If I instead take the alpha channel directly from the original "Sample texture 2d" (even if it looks garbled) the end result is correct (apart from the alpha not adjusted like the other track is trying to achieve).
    ungarbled.png


    Anyone got an idea why this might happen?