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

Can someone quickly check my theory on a blend shader?

Discussion in 'Shaders' started by LawrieCo, Nov 24, 2014.

  1. LawrieCo

    LawrieCo

    Joined:
    Nov 9, 2012
    Posts:
    16
    Hey everyone, I'm 90% sure I know how to solve my task but I get that gut feeling that there might be a simpler way. My scene has a bunch of 2D rectangles and I need to mix the colours where they overlap with each other only, but not any other objects like background and foreground elements, player, etc. Also the resulting colour needs to be set to a particular colour that isn't a natural blend result. So how I thought this should be handled is to make a new camera that renders only my rectangles to a render texture, then render my rectangles with a shader that fetches my render target to work out which rectangles and colours it's overlapping with.

    I'm pretty sure this will work but converting the coordinates from world into the awkward 0-1 of shaders seems like I'm missing a simpler solution. Is there maybe a way when rendering the rectangles in the other camera (for the RT) that I could just calculate the mixed colour then and render the RT in the main camera instead? I thought I wouldn't be able to as you can't query the dest colour when using blend, right? I need to be able to say red and orange will mix to a colour I choose like something unatural like purple and I think that means normal blending is out of the question.
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    You could have a palette texture.. sort of a lookup table of what you want to remap from/to... then if you're rendering to a rendertexture, when you then process that texture with the second pass shader use the palette to change the colors.