Unreal Engine 4 Color Grading

  • Posts: 292
5 years 1 month ago - 5 years 1 month ago #1 by matsilagi
Would it be possible to do this? docs.unrealengine.com/latest/INT/Engine/...orGrading/index.html

I really like how it looks on Unreal Engine and i think it would be a nice addition to the framework.

I kinda wanted to get the colors close to this using the currently available tonemapping formulas (Spent an afternoon on it): but no avail, i think that if that gets added, i may be able to somehow "rip" the LUT from UT4 myself.

EDIT:Ah, didnt knew the fixed post was about the same shader :P , still, ME's lut still doesnt give me the results like the screenshot.

Please Log in or Create an account to join the conversation.

  • Posts: 261
5 years 1 month ago - 4 years 8 months ago #2 by Kleio420

matsilagi wrote: Would it be possible to do this? docs.unrealengine.com/latest/INT/Engine/...orGrading/index.html

I really like how it looks on Unreal Engine and i think it would be a nice addition to the framework.

I kinda wanted to get the colors close to this using the currently available tonemapping formulas (Spent an afternoon on it):

but no avail, i think that if that gets added, i may be able to somehow "rip" the LUT from UT4 myself.

EDIT:Ah, didnt knew the fixed post was about the same shader :P , still, ME's lut still doesnt give me the results like the screenshot.


you can try to edit it , or if nothing comes close and have some suggestions to make it better shoot marty a msg here reshade.me/forum/shader-presentation/161...born-official-thread

Please Log in or Create an account to join the conversation.

  • Posts: 292
5 years 1 month ago #3 by matsilagi
I tried to, spent an afternoon playing around with LUTs and nothing, i dont think ME's LUT + SweetFX tonemapping stuff can get close to UE4's one.

Please Log in or Create an account to join the conversation.

  • Posts: 177
5 years 1 month ago - 5 years 1 month ago #4 by kingeric1992
UE page is referring to 16x16x16 3D LUT,
http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html

ME is using 1D per channel.
The main difference is that 3D LUT is color to color, while the latter one is channel to channel.

Please Log in or Create an account to join the conversation.

  • Posts: 118
5 years 1 month ago - 5 years 1 month ago #5 by vfxninjaeditor
I posted about this month ago actually but didn't really get a straight answer. I am a developer at Druid Gameworks and I can honestly say that using the 16x16x16 LUT is far easier than using the one in ME.

All you have to do is load a screenshot without any effects on it into photoshop, copy the LUT file over the screenshot, make your adjustments to both the screenshot and the LUT, crop to the LUT, save it and load it into UE4. Voila! The results you see in UE4 are identical to the ones you just made in photoshop.

I really wish this could be implemented into the Framework. It really allows you to get more creative.

Please Log in or Create an account to join the conversation.

  • Posts: 3740
5 years 1 month ago #6 by crosire

kingeric1992 wrote: 16x16x16 3D LUT

This is the problem however. ReShade only supports native 2D textures, so 3D textures would need to be emulated in shader code.
The following user(s) said Thank You: W S

Please Log in or Create an account to join the conversation.

  • Posts: 177
5 years 1 month ago #7 by kingeric1992
This should be fine, UE is also doing that , 16x16x16 3D --> 256x16 2D with some offset + lerp.
// LUT Scale =  256x16, left side is .b == 0, 
color.rgb = tex2D(OriginalColor, coord.xy).rgb;
color.b  *= 15;
float shift = floor(color.b);
color.r = (color.r + shift) / 16;
color.rgb = lerp( tex2D(LUT, color.rg).rgb, tex2D(LUT, color.rg + float2(0.0625, 0)).rgb, color.b - shift);

Please Log in or Create an account to join the conversation.

  • Posts: 790
5 years 1 month ago - 5 years 1 month ago #8 by Ganossa
Edit::okay, read the document you linked. If you give me a COMPLETE LUT in 2d space, I can implement it in the next release.

A difference you will always have anyway compared to a game internal LUT is that you have to apply them to the entire image and not just texture as it is done in UT for sure.

Please Log in or Create an account to join the conversation.

  • Posts: 292
5 years 1 month ago - 5 years 1 month ago #9 by matsilagi

LuciferHawk wrote: Edit::okay, read the document you linked. If you give me a COMPLETE LUT in 2d space, I can implement it in the next release.

A difference you will always have anyway compared to a game internal LUT is that you have to apply them to the entire image and not just texture as it is done in UT for sure.


Good to see that this may be implemented.
Also, any way to keep the texture used by the shader the UT's one? (Would be much easier for me)

Please Log in or Create an account to join the conversation.

  • Posts: 790
5 years 1 month ago - 5 years 1 month ago #10 by Ganossa

matsilagi wrote: Good to see that this may be implemented.
Also, any way to keep the texture used by the shader the UT's one? (Would be much easier for me)


Then crosire needs to implememt 3d texture support first (or do they also provide 2d ones?) in the source which seems will not happen.

I need a raw gradient LUT that covers the entire color space in 2D (similar to those that you use when choosing colors in editing tools).

Edit::I can actually create one myself with a shader.

Please Log in or Create an account to join the conversation.

  • Posts: 1221
5 years 1 month ago - 5 years 1 month ago #11 by Marty McFly

kingeric1992 wrote: This should be fine, UE is also doing that , 16x16x16 3D --> 256x16 2D with some offset + lerp.

// LUT Scale =  256x16, left side is .b == 0, 
color.rgb = tex2D(OriginalColor, coord.xy).rgb;
color.b  *= 15;
float shift = floor(color.b);
color.r = (color.r + shift) / 16;
color.rgb = lerp( tex2D(LUT, color.rg).rgb, tex2D(LUT, color.rg + float2(0.0625, 0)).rgb, color.b - shift);


Either your code isn't 100 right or the LUT I use is shitty, however it produces heavy clipping. Colors are in 0~1 range.

Warning: Spoiler! [ Click to expand ]


EDIT: Yes, even a neutral LUT produces clipping. Cannot nail it down to a color channel though.

Please Log in or Create an account to join the conversation.

  • Posts: 118
5 years 1 month ago #12 by vfxninjaeditor

Marty McFly wrote:

kingeric1992 wrote: This should be fine, UE is also doing that , 16x16x16 3D --> 256x16 2D with some offset + lerp.

// LUT Scale =  256x16, left side is .b == 0, 
color.rgb = tex2D(OriginalColor, coord.xy).rgb;
color.b  *= 15;
float shift = floor(color.b);
color.r = (color.r + shift) / 16;
color.rgb = lerp( tex2D(LUT, color.rg).rgb, tex2D(LUT, color.rg + float2(0.0625, 0)).rgb, color.b - shift);


Either your code isn't 100 right or the LUT I use is shitty, however it produces heavy clipping. Colors are in 0~1 range.

Warning: Spoiler! [ Click to expand ]


EDIT: Yes, even a neutral LUT produces clipping. Cannot nail it down to a color channel though.


I believe he copied that code directly from UE4 source.

Please Log in or Create an account to join the conversation.

  • Posts: 118
5 years 1 month ago #13 by vfxninjaeditor

LuciferHawk wrote: Edit::okay, read the document you linked. If you give me a COMPLETE LUT in 2d space, I can implement it in the next release.

A difference you will always have anyway compared to a game internal LUT is that you have to apply them to the entire image and not just texture as it is done in UT for sure.


What do you mean by this Lucifer? Did you not see the workflow I posted on how UE4 LUT's are modified?

Please Log in or Create an account to join the conversation.

  • Posts: 790
5 years 1 month ago #14 by Ganossa
I read it but I still need the raw 2D LUT as reference.

Please Log in or Create an account to join the conversation.

  • Posts: 177
5 years 1 month ago - 5 years 1 month ago #15 by kingeric1992

vfxninjaeditor wrote: I believe he copied that code directly from UE4 source.


No, just guessing from provided LUT texture.

@Marty

I didn't add texture offset to sample the center of pixel, so there was some artifact at border.
Here is the fix(tested with enb)
// LUT Scale =  256x16, top left corner == 0. 
float2 pixelsize = 1 / float2(256, 16);
color.rgb = saturate(tex2D(OriginalColor, coord.xy).rgb);
color.b  *= 15;
float shift = floor(color.b);
color.rg =  color.rg * 15 * pixelsize + 0.5 * pixelsize ;
color.r += shift * 0.0625;
color.rgb = lerp( tex2D(LUT, color.rg).rgb, tex2D(LUT, color.rg + float2(0.0625, 0)).rgb, color.b - shift);

Please Log in or Create an account to join the conversation.

  • Posts: 790
5 years 1 month ago - 5 years 1 month ago #16 by Ganossa
So I implemented the UT - LUT using the same color depth. It works well but there is room for improvement.

Anyway, here is a quick comparison using

GTAV vanilla


blue-ish photoLUT applied (altered with filters in photoshop)


GTAV above photoLUT ( + ambient light + DoF )


I like the LUT simply because it reduces performance you would need to run a bunch of other color correction algorithms, however, it needs to be improved.
The following user(s) said Thank You: matsilagi, BillyAlt, Constantine PC, BrandonHortman

Please Log in or Create an account to join the conversation.

  • Posts: 292
5 years 1 month ago #17 by matsilagi
Amazing! Cant wait to actually use it.

Please Log in or Create an account to join the conversation.

  • Posts: 261
5 years 1 month ago #18 by Kleio420

LuciferHawk wrote: So I implemented the UT - LUT using the same color depth. It works well but there is room for improvement.

Anyway, here is a quick comparison using

GTAV vanilla


I like the LUT simply because it reduces performance you would need to run a bunch of other color correction algorithms, however, it needs to be improved.

is there any plans to improve and push this possibly to the next framework update ?would love to use this ik i can already using the code the user posted , been trying to use Reinhard tonemapping and it either destroys to much detail or makes the image foggy im thinking using LUT will help some on what im doing

Please Log in or Create an account to join the conversation.

  • Posts: 790
5 years 1 month ago #19 by Ganossa
Yes, its basically ready and I will ship it together with the motion focus shader once its done.

It is currently one part of the TuningPalette shader of CustomFX suite with the following options::
 /*¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*\
 ‡  •    Color LUT PARAMETERS    •  ‡
 \*……………………………………………………………………………………*/
#define TuningColorLUTDstTexture	"CFX_ColorLUTDst.png"  	//needs to have 256x16 pixels
#define TuningColorLUTNorm 		float2(1f/256f, 1f/16f)
#define TuningColorLUTIntensity 	1.0f
 /*ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ*\
 \*……………………………………………………………………………………*/
The following user(s) said Thank You: SpinelessJelly, jas01

Please Log in or Create an account to join the conversation.