Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Invert Color Shader (without see-through)

Discussion in 'Shaders' started by S0ULART, Sep 29, 2014.

  1. S0ULART

    S0ULART

    Joined:
    Jun 14, 2011
    Posts:
    129
    Hello Community!

    I'm wondering how it's possible to achieve a Shader that inverts an objects color that it touches.
    Something like in the following video


    I already found this shader:
    http://forum.unity3d.com/threads/invert-colors-shader.205244/

    the problem with this one is, that the object (e.g. an Cube) where the shader is applied to acts like a mirror and inverts everything you look at. I want the object with the shader to be invisible and is just inverting the color of the objects thats inside it.

    My Intention is to get a similar result like in the image:
    http://www.androidshock.com/wp-content/uploads/2013/10/Paper-Sorcerer-1.jpg

    regards
    Soulart
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,704
    You need to make a shader which has a Blend function of something like GL_ONE_MINUS_DST_COLOR, GL_ZERO ... which will multiply the existing backbuffer's color values by whatever is in your source image... if your source image is white, it'll just flip the colors.
     
  3. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,445
    In Unity syntax:
    Code (csharp):
    1.  
    2. Blend OneMinusDstColor Zero
    3.  
    The output of the shader needs to be pure white for a complete inversion.
     
    Last edited: Oct 6, 2014
  4. S0ULART

    S0ULART

    Joined:
    Jun 14, 2011
    Posts:
    129
    Thanks for the help

    I tried jvo3dc's Method:

    Code (CSharp):
    1. Shader "custom/Invert" {
    2.     Properties
    3.         {
    4.             _Color ("Tint Color", Color) = (1,1,1,1)
    5.         }
    6.      
    7.         SubShader
    8.         {
    9.             Tags { "Queue"="Transparent" }
    10.    
    11.             Pass
    12.             {
    13.                ZWrite On
    14.                ColorMask 0
    15.             }
    16.             Pass
    17.             {
    18.                 Blend OneMinusDstColor Zero
    19.  
    20.             }
    21.          
    22.          }
    23. }

    The Shader doesnt work. To be honest I dont habe any knowledge in programming and shader.
     
    Last edited: Oct 16, 2014
  5. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,445
    This part is breaking things:
    Code (csharp):
    1.  
    2. ColorMask 0
    3.  
    That actually disables any change to the color buffer. Also, you probably want the ZWrite to be Off.
     
unityunity