Sign in to follow this  
thedigga007

3D LUT Color Correction issue

Recommended Posts

So I decided to try to implement color correction using 3D lookup tables based on the article found here: [url="http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html"]http://http.develope..._chapter24.html[/url]

I then used the "color neutral" texture found on the UDN here: [url="http://udn.epicgames.com/Three/ColorGrading.html"]http://udn.epicgames...lorGrading.html[/url]

I made sure to convert the color neautral texture from 2D to 3D, so 256x16 => 16x16x16.

Here is my shader code for sampling the texture:

[source lang="cpp"]half4 outColor;
half4 inColor = tex2D(colorMap, inUV);
half3 lutSize = half3(16.0h, 16.0h, 16.h);
half3 scale = (lutSize - 1.0h) / lutSize;
half3 offset = 1.0h / (2.0h * lutSize);
outColor.rgb = tex3D(LUTSampler, scale * inColor.rgb + offset);
outColor.a = 1.0h;

return outColor;[/source]
My results are totally weird, for example everything is either bright green and pink. I am assuming either the "color neutral" texture I am using from Epic's website isnt neatral OR I am doing something wrong. If my code is correct does anyone know how I could generate a color neutral 3D lut?

Also, I converted the 2D image to 3D by writing a little tool that would write each 16 wide section of the original texture into a new slice of the volume texture. I checked each slice manually in the d3d texture tool and it was correct. I thought maybe the slice order was wrong but that didnt change anything except make it all red and black instead of pink and green. It's almost as if it only samples from the bottom slice...

I've attached a screen shot, ignore the vignette...

Thanks Edited by thedigga007

Share this post


Link to post
Share on other sites
I agree with Ashaman. Without seeing the original, un-color corrected image it's difficult to know exactly how the transform is going badly.

What I can say is that the neutral texture from the UDN website looks good to me. Red is going across the X axis, green is going down the Y axis, and blue is presumably in the Z-axis. The implication is that RGB == XYZ.

With that said, we don't know what color format your original colorMap is in. In truth, it could be either RGBA, BGRA, or even ARGB. If they are incorrect, then when you set the Alpha to 1.0, you may very well be setting one of the color channels to 1. Or, if the Alpha channel is in the same place but the other color channels are mixed, then you could just be swapping one color for another. Also, I vaguely recall DirectX drawing a strange color background if you tried to render parts of the frame-buffer that hadn't been cleared. We could be seeing some of that debug color.

Which reminds me, if you're not actually setting the alpha channel to 1, then we could be seeing part of your clear color. What color do you clear the frame buffer to between draw calls? I assume this is in-game and not just post-processing of an image?

And finally, it's possible your Z values are backward if the textures are stacked incorrectly. This would cause low values of blue to show up as bright blue, and high values of blue to have no apparent impact, thus causing other colors to (green & red) to be more prominent. The problem is, it could be any of these, some combination of these, or all of them. And we won't be able to narrow in unless we see the source image. Preferably with information about the position of color channels.

Cheers and good luck!

Share this post


Link to post
Share on other sites
how do you declare the LUT sampler? sampler2d maybe?
enable d3d debug to check for errors like this and in case there are none, try PIX, it will allow you to inspect your resources (the LUT texture) if it's valid.

Share this post


Link to post
Share on other sites
Here is an image of the original framebuffer.

[img]http://i50.tinypic.com/dca436.png[/img]

Framebuffer surface format is ARGB and the LUT is ARGB

Share this post


Link to post
Share on other sites
I got it! After looking at the PIX capture again I noticed that the LUT was flipped in the Y. I fixed this in my conversion tool (the to 2d to 3d) and it worked.

Thanks for all the help!

Share this post


Link to post
Share on other sites
I was just going to say that! Glad you found it. Because of the flipped Y, your Green value was inverted. The black door way had low green, so it was showing up as high green. And the gray in the sky had a % of green which was being removed, leading to the purple you were seeing.

Cheers and good luck!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this