Search Unity

Make translucent meshes ONLY mix additive colors when colliding

Discussion in 'Shaders' started by Czar-Man, Mar 27, 2019.

  1. Czar-Man

    Czar-Man

    Joined:
    May 10, 2013
    Posts:
    20
    I'm working on a project in which players mix transparent colored meshes together in the RGB sense.

    Here's a screenshot:
    upload_2019-3-27_10-14-24.png

    What you see here are red and green pillars mixing to form yellow as planned. On the left are the settings for the red and green materials using the standard shader as Transparent.

    Unfortunately, the colors that don't intersect still add to each other, as shown here.
    upload_2019-3-27_10-17-44.png
    The blue and red meshes do not physically intersect, but look like they do. This causes a lot of confusion for players.

    Is there a way to make a shader that builds on the standard settings but allows only for intersecting objects to provide additive color?

    P.S. I'd also like to add functionality that lets you see the material while the camera is inside of the mesh.
     
  2. tmcthee

    tmcthee

    Joined:
    Mar 8, 2013
    Posts:
    119
    Maybe use two cameras?
    Have all the mixing done using a separate camera to a render texture, then you can blend that texture with the rest of your scene using a different form of (non additive) transparency.
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    This is a non-trivial task. Knowing if two transparent meshes are intersecting alone is basically impossible. This requires true transparency sorting using an a buffer or linked list rendering, neither of which are supported out of the box by Unity (and may not even be plausible to implement within the existing confines of Unity’s c# graphics APIs). The only real option is to use in shader raytracing/raymarching and analytical shapes so you just draw all of the transparent objects as a full screen image effect.
     
  4. Czar-Man

    Czar-Man

    Joined:
    May 10, 2013
    Posts:
    20
    These are advanced for my experience. What are some good tutorials I can look up?
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352