Search Unity

Rendering half the screen in negative

Discussion in 'Shaders' started by FyreDogStudios, Apr 23, 2016.

  1. FyreDogStudios

    FyreDogStudios

    Joined:
    Aug 23, 2015
    Posts:
    97
    Hello,
    I have very little experience with shaders and post processing effects and I am not even sure if this is possible.

    I have a 2D game, portrait, mobile.

    I would like the bottom half of the screen to be rendered in negative colours.

    Any suggestions to gaining this effect would be appreciated.
     
  2. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    I would use 2 camera with a custom replacement shader to invert the color for the bottom camera.
     
    FyreDogStudios likes this.
  3. FyreDogStudios

    FyreDogStudios

    Joined:
    Aug 23, 2015
    Posts:
    97
    Wouldn't that double the draw calls? Looking from a performance perspective.
     
  4. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Yes, 2 cameras will do that. Are you rendering 2 scene or the same scene just with the color inverted on the bottom half of the screen?

    Also, doubling your draw calls may be worth it if you really want this effect. Get it running and see what the performance hit is.
     
    FyreDogStudios likes this.
  5. FyreDogStudios

    FyreDogStudios

    Joined:
    Aug 23, 2015
    Posts:
    97
    I am looking at having white contrasting with black in the top half, and the opposite in the bottom.
     
  6. FyreDogStudios

    FyreDogStudios

    Joined:
    Aug 23, 2015
    Posts:
    97
    Also, how would I stitch two cameras together to make it appear as only one? I have only every used multiple camereas when displaying them via RawImage on a canvas.
     
  7. earrgames

    earrgames

    Joined:
    Jan 27, 2014
    Posts:
    168
    depending on how complex are your models you could simply duplicate each object and apply a material with the inversed colours, then put it on a separated layer, then select the culling of each camera so one renders the inversedobjectsand the other the inverse, you will have twice as much objects but if they are low poly it should not affect much, so well you have choices, just try them till one works good for you.
     
    FyreDogStudios likes this.
  8. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Another approach could be to overlay the bottom half with an UI image that is using a shader/material that inverts colors using the blend mode hardware. It's rather easy to setup and does not require additional cameras or modifying other assets.

    Maybe it works for your project. I created a small example project, download link can be found at the bottom of this post.



    Download Unity 5.3 example project:
    http://www.console-dev.de/bin/Unity5_Example_UI_InvertColor.zip
     
    FyreDogStudios likes this.
  9. FyreDogStudios

    FyreDogStudios

    Joined:
    Aug 23, 2015
    Posts:
    97
    I was thinking this could be an option, thanks for the links!
     
  10. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    You can do it with a simple image effect.
     
  11. Firas24

    Firas24

    Joined:
    Jun 18, 2015
    Posts:
    4
    Hi,
    Actually I am looking for the same effect (negative part of the screen) But the solution that Peter77 provided only works on UI elements and I need it to work on sprites outside the canvas.
    How to achieve this result? Does the shader need to be edited ?
     
  12. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    I added a Sprite version to the example project.
    The project contains two folders now, "UI" and "Sprite". In each folder you can find a scene that shows the effect.

    Download it from here:
    http://www.console-dev.de/bin/Unity5_Example_UI_InvertColor.zip
     
  13. Firas24

    Firas24

    Joined:
    Jun 18, 2015
    Posts:
    4
    Thank you for your reply
    Is there a way to use one shader to do both UI and sprites?
    Or can i overlay two UI images one of them has negative for UI and the other has negative for sprites?
    Or are those shaders functional for both?
    Thanks again