Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Color Correction LUT, bigger neutral look up texture?

Discussion in 'Shaders' started by mitchtheriault, Oct 23, 2014.

  1. mitchtheriault

    mitchtheriault

    Joined:
    Aug 4, 2013
    Posts:
    24
    In the documentation for the Color Correction LUT image effect, it mentions:

    The image shows a texture of the dimension 256x16, yielding a 16x16x16 color lookup texture (lut). If the resulting quality is too low, a 1024x32 texture might yield better results (at the cost of memory).

    I've been going off of the included 256x16 neutral texture, but there isn't a 1024x32 neutral look up texture included with Image Effects. I can't seem to find one anywhere, and I'm not sure how to make one. Does anybody have one?
     
  2. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,452
  3. mitchtheriault

    mitchtheriault

    Joined:
    Aug 4, 2013
    Posts:
    24
    Hmm. Thank you! But it didn't seem to work properly. Maybe I have to modify the script somehow to accept the bigger LUT?
     
  4. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,452
    You are right, it does not work properly.

    After seeing the source of the image manipulation, the reason it does not work is not related to the image size.
    Indeed, the image size is specified as "needs to be of the format w * h, where h is the 'depth' (or 3d dimension 'dim') and w = dim * dim". Usable dimensions are 16x256, 32x1024, 64x4096. ( Obviously, a developer could offer support for other image dimensions, see colourful using a square texture here http://www.thomashourdel.com/colorful/doc/lut.html ).

    The problem with the image seems to be in the jpeg encoding, which obviously alters the image colors.

    I couldn't find a neutral lut file in these dimensions, I have noticed that there is an app, http://3dlutcreator.com/ which has some output capabilities. You could contact the developers and ask if they can provide the output you need.

    Kind regards
    -Ippokratis
     
    Last edited: Oct 24, 2014
  5. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    536
    It is quite easy to make your own in photoshop. Just examine how the 256x16 was made and translate that over to a 1024x32 texture... or use the one below.
    The one Ippokratis posted was not made for Unity ImageEffects in mind I guess. Probably for Unreal Engine. LUT32_Neutral.png
     
    Last edited: Oct 24, 2014
  6. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,452
    [Edit]
    See the post below for correct code and textures
     
    Last edited: Oct 24, 2014
  7. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    536
    Nice Ippo, that code might come in handy some time in the future - though the output seems to be different. If you take a look at the LUT in the documentation you'll notice that your code swizzled the green and blue channel and your green channel starts with zero at the bottom instead of on top.
     
  8. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,452
    Try it.
     
  9. mitchtheriault

    mitchtheriault

    Joined:
    Aug 4, 2013
    Posts:
    24
    Thank's a lot, guys! Hope this helps other people who stumble across this with the same problem
     
  10. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    536
    @Ippokratis:
    Yours is giving me a result that differs a little more from the original photoshop tweak. May depend on what function one uses to color grade the scene. But here's the result:
    LUT_comparison.jpg
     
  11. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,452
    Marco : You are right, it is not correct.
    Corrected code :
    Code (JavaScript):
    1. #pragma strict
    2. import System.IO;
    3. var tex2D : Texture2D;
    4. var dims:int;
    5.  
    6. function Start ()
    7. {
    8.     CreateIdentityLut(dims);
    9. }
    10.  
    11. function CreateIdentityLut (dim : int)
    12. {
    13.   var newC : Color[] = new Color[dim * dim * dim];
    14.   var oneOverDim : float = 1.0f / (1.0f * dim - 1.0f);
    15.   for(var i : int = 0; i < dim; i++)
    16.   {
    17.     for(var j : int = 0; j < dim; j++)
    18.     {
    19.       for(var k : int = 0; k < dim; k++)
    20.       {
    21.         newC[i + (j*dim) + (k*dim*dim)] = new Color((i*1.0f)*oneOverDim, Mathf.Abs( ((k*1.0f)*oneOverDim) - 1.0f ), (j*1.0f)*oneOverDim, 1.0f);
    22.       }
    23.     }
    24.   }
    25.  
    26.   tex2D = new Texture2D (dim*dim,dim, TextureFormat.RGB24, false);
    27.   tex2D.SetPixels(newC);
    28.   tex2D.Apply();
    29.   var bytes = tex2D.EncodeToPNG();
    30.   File.WriteAllBytes(Application.dataPath + "/../3DLUT" + (dim*dim).ToString()+"ll" + ".png", bytes);
    31. }
    32.  
    Corrected textures :
    3DLUT256ll.png 3DLUT1024ll.png 3DLUT4096ll.png
     
    Last edited: Oct 24, 2014
  12. Matty_Matty_Matty

    Matty_Matty_Matty

    Joined:
    Sep 8, 2014
    Posts:
    1
    Does this code work in 5? Having some trouble with it but I may also just be dumb..

    Thanks.