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

A hack for those who want to omit, exclude, unaffect background when using color grading

Discussion in 'Image Effects' started by idchlife, Dec 1, 2017.

  1. idchlife

    idchlife

    Joined:
    Jul 25, 2016
    Posts:
    15
    Topic about Unitys Post Processing you can find for free in asset store

    I was making webgl 3d scene, not game, wanting it to be as soft with colors as possible. You know, soft shadows, not much grayness or darkness, so color grading helped very much.

    My webpage has white color. So you know what that means, yes? Post Processing Color Grading made my white background in camera - not white. More like lightgray-pink or something. Each of your color grading profiles will make one color the same, guys, so that's not point.

    The point is - I had this huge rectangly scene on my webpage, instead of floating object without (with the same as webpage background color) anything in background.

    Basically, when you first encounter this you understand that nothing can be done to affect not background with color grading but only objects.

    Well, there is a way. A hack of hacks. Quick and dirty solution.

    1) Color pick your desired background color as 1, 1, 1 value (basically make your rgb a / 255, g / 255, b / 255 or use color picker with glsl color format) and save it somewhere, like cope-paste to notes.

    2) Make your background the most unused color in the scene. I did not have any green, so I used pure green (0, 255, 0) - too, convert it to 1, 1, 1 format - (0, 1, 0). This new background color will be replaced, do not worry.

    3) Find file Assets/PostProcessing/Resources/Shaders/LutGen.shader

    4) Find line 39. This line is for function that creates let's called it new color based on your color grading profile configuration.

    5) Add these lines at the beggining of function (I included start of the function so you know where to insert if you do not know code):

    Code (CSharp):
    1.         half3 ColorGrade(half3 color)
    2.         {
    3.             // First, you will need the color you replaced your background with in step
    4.             if (
    5.                 color.r > 0.01 && color.r < 0.9  // First step
    6. //                && color.g > 0.15 && color.g < 0.3 // Second step
    7. //                && color.b > 0.045 && color.b < 0.1 // Third step
    8.             ) return half3(1, 1, 1); // Replace this with your desired color, like half3(r, g, b) but with 0-1 style values, not 0-255
    9.  
    6) Now, for the steps.
    First step - for red. Second for green. Third for blue.
    You see those values in the first step? 0.01 and 0.9. It means red color value should be greater than 0.01 and less than 0.9
    Now, if you run your game you will see that most of the scene will be replaced with your desired color.
    This is because most of colors in your scene will have value in between 0.01 and 0.9 in red. You will need to search for ideal combination for your color step by step.

    - First step - find the smallest range possible (like 0.40 and 0.46) for your replacement color (2 step) to be replaced completely with desired color (to check if completely - use color picker, values should be exactly as desired color, not near it, exactly - if you want exact color of course). Try to find precise values that will fully affect your replacement color (step 2) and less affect other objects.
    - Second step - uncomment it. (remove // from the beginning of the line) and now change values and press play game after every changing so you will see that your replacement color in background will be replaced and also there should be LESS other objects colors affected by your desired color.
    - Third step - final. Uncomment it and change values so only your replacement color will be replaced.

    Basically - done.
    You can tweak all (r, g, b) values in three lines so no objects will be affected except for background.

    If you at some point will understand that you messed up all values in all three lines - just comment 2 and 3 step and start from the beginning.
    Tip: choose bright color first instead of desired and place it in code, so it will be better seen in the scene. After finishing - replace with desired color in code.

    Hope this will help someone!
     
  2. Hamid-Gh

    Hamid-Gh

    Joined:
    Feb 16, 2018
    Posts:
    4
    Hi idchilfe, I have the same problem and want to make my background white again, after applying my post effects. I am using now 'PostProcessing-2.1.7' version.
    in this version there is no LutGen.shader.
    where should I change it ?
    the second question is, that I have 2 kind of post effect script on my GameObject.
    is there a final script that I can chage it there, after everything is done?

    thanks in advance
     
  3. xeon321

    xeon321

    Joined:
    Nov 10, 2016
    Posts:
    9
    It's kind of sad that we have all these bleeding edge features but cannot do something as basic as choosing which Post Processing effect to affect the object we want and have to resort to hack like this ...