3D LUT Color Correction issue

Started by
5 comments, last by JWalsh 11 years, 8 months ago
So I decided to try to implement color correction using 3D lookup tables based on the article found here: http://http.develope..._chapter24.html

I then used the "color neutral" texture found on the UDN here: http://udn.epicgames...lorGrading.html

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
Advertisement
Have you a comparision shot, it could be a problem of swapped channels (RGBA <-> BGRA) .
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!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
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.
Here is an image of the original framebuffer.

dca436.png

Framebuffer surface format is ARGB and the LUT is ARGB
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!
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!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints

This topic is closed to new replies.

Advertisement