Real-time Colour Cast Neutralizer

  • Posts: 206
1 year 5 months ago - 1 year 5 months ago #1 by Duran.te
Hi guys
I was wondering if it was possible to achieve an effect like the neutralize filter seen in photoshop to reduce color casting.
(What is the neutralize filter)

I'll take the game Need for Speed 2015 as an example. I took screenshots of two scenes with excessive color tint, I then applied the filter in photoshop and here's the result:



(gameplay source: https://www.youtube.com/watch?v=kxZGNUQPsNI&feature=youtu.be&t=46 )
The following user(s) said Thank You: MaxG3D, Viper_Joe, Arkane, Teh_pwnisher, thalixte, prod80

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

  • Posts: 42
1 year 5 months ago #2 by Marty
This effect would really make my life easier :cheer: I'm no programmer but it sounds like it should be possible.
At the very least you can apply the effect to LUT in Photoshop.

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

  • Posts: 504
1 year 5 months ago #3 by Wicked Sick
That would be nice to try.

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

  • Posts: 160
1 year 5 months ago #4 by Fu-Bama
It looks like a simple histogram normalization or curves RGB levels adjustment.

Principle is this:
• Sample whole image and determine maximum and minimum levels for Red Green and Blue
• On second pass apply this to the image:
CastRemoved = (SourceImg.rgb-Minimum.rgb)/(Maximum.rgb-Minimum.rgb)
• Then maybe mix original image.x in YUV with CastRemoved.yz in YUV to change only color

I would try it, but don't know how to pass variables between passes :/

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

  • Posts: 126
1 year 5 months ago #5 by Chavolatra
i very like this ideia hahaha =)

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

  • Posts: 176
1 year 5 months ago - 1 year 5 months ago #6 by Daodan

Fu-Bama wrote: I would try it, but don't know how to pass variables between passes :/


Maybe save the min/max RGB values into a 1x1 texture and use RGBA16 as the format (max value stored in the upper, min value in the lower 8 bits).
And then read from that texture when applying the color correction.

[Edit]
Or, having a pass that has two render targets (1x1 texture) would be easier.
@Fu-Bama I just wrote up a gist that could act as a baseline.
It gets the min/max RGB values and applies them in the formula you provided.
The following user(s) said Thank You: j4712

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

  • Posts: 176
1 year 5 months ago - 9 months 1 week ago #7 by Daodan
There are still some things to tweak but I guess it works: RemoveTint.fx
[Old Version]

[Edit]
  • Added control to set the interpolation speed of min/max values between frames (does anyone know how to do that framerate independent?)
  • Added control to set the effect strength

Base image:


Tinted:


Neutralized:
The following user(s) said Thank You: Wicked Sick, MaxG3D, OtisInf, Uncle Crassius, Marty, j4712, Duran.te, prod80

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

  • Posts: 45
1 year 5 months ago #8 by MaxG3D
OMG, this is beautiful! I needed that in my life. Thanks a lot!
The following user(s) said Thank You: Daodan

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

  • Posts: 206
1 year 5 months ago #9 by Duran.te
It looks phenomenal. Thank you very much!
The following user(s) said Thank You: Daodan

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

  • Posts: 343
1 year 5 months ago - 1 year 5 months ago #10 by OtisInf

Daodan wrote: Added control to set the interpolation speed of min/max values between frames (does anyone know how to do that framerate independent?)

I assume you use a temporal lerp between 2 1pixel textures? You could adjust the speed with a timer, instead of simply adding a value with each pass (frame), so if the framerate is low or high it doesn't matter.

Shader looks great! good job :)
The following user(s) said Thank You: Daodan

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

  • Posts: 176
1 year 5 months ago - 1 year 5 months ago #11 by Daodan
I've updated the shader a bit:
  • More meaningful name: RemoveTint.fx
  • When interpolating the min/max RGB values the frametime is taken into account
  • It is possible to set custom min/max RGB values, can lead to some interesting results (add REMOVE_TINT_CUSTOM_COLORS to the preprocessor defs)

But, it seems the shader doesn't work in d3d9 yet.
Changed tex2Dfetch() with tex2D() and it works now. tex2Dfetch() in d3d9 seems to be bugged at the moment.
Warning: Spoiler! [ Click to expand ]
The following user(s) said Thank You: Wicked Sick, Ryukou36, Marty, Cul

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

  • Posts: 504
1 year 5 months ago #12 by Wicked Sick
Man, what the hell? This is beautiful!

flic.kr/p/2ev64bZ
The following user(s) said Thank You: Daodan

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

  • Posts: 3737
1 year 5 months ago #13 by crosire

Daodan wrote: Changed tex2Dfetch() with tex2D() and it works now. tex2Dfetch() in d3d9 seems to be bugged at the moment.

Fixed: github.com/crosire/reshade/commit/0fc8fe...e793afdd47cf958513d7
tex2Dfetch didn't work on the backbuffer and depth buffer in D3D9 (worked on user textures). This fixes that.
The following user(s) said Thank You: Marty, Daodan

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

  • Posts: 176
1 year 5 months ago #14 by Daodan
Thanks Wicked Sick!
This is one of my all-time favourites :)

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

  • Posts: 1
9 months 2 weeks ago #15 by sulpherStaer
I am having issues getting the correct color correction when the UI is visible. I tried using UImask to select a sample area, so that it ignored the UI (as this resulted in a always black & always white - so no correction at all)

Here are two images to show what I mean.

The top image one has the UI hidden. and as you can see, the right side (where the UImask is) is being corrected.
The bottom image shows the ui, and the masked area is no longer corrected. How would I solve this? How do I create a 'sample area' so that the UI is ignored in the color pick.

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

  • Posts: 176
9 months 1 week ago #16 by Daodan
I've updated the shader - see one of my posts with the link in it. Using that might help a bit with your problem as the min/max rgb values are now taken from a mipmap and not the full resolution.

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

  • Posts: 179
6 months 3 weeks ago #17 by klotim

Daodan wrote: I've updated the shader - see one of my posts with the link in it. Using that might help a bit with your problem as the min/max rgb values are now taken from a mipmap and not the full resolution.


With strength 1.0

I'm not sure but it still looks way different to photoshop neutralize.
Is it possible to make it look like PS Neutralize?

PS Neutralize


Reshade Remove Tint

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

  • Posts: 31
6 months 2 weeks ago #18 by mirt81
Th@nks

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

  • Posts: 176
6 months 5 days ago - 6 months 3 days ago #19 by Daodan

klotim wrote: I'm not sure but it still looks way different to photoshop neutralize.
Is it possible to make it look like PS Neutralize?


Have you tried setting REMOVE_TINT_MIPLEVEL_EXP2 to 1 so the min/max RGB values are taken from the native resolution and not a mipmap? This will probably not work as there could be too many iterations in the for-loop (-> shader fails to compile).

This shader is still some sort of "draft" - when I find time I will rework it and post it in the presentation thread.

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

  • Posts: 179
6 months 3 days ago #20 by klotim

Daodan wrote:

klotim wrote: I'm not sure but it still looks way different to photoshop neutralize.
Is it possible to make it look like PS Neutralize?


Have you tried setting REMOVE_TINT_MIPLEVEL_EXP2 to 1 so the min/max RGB values are taken from the native resolution and not a mipmap? This will probably not work as there could be too many iterations in the for-loop (-> shader fails to compile).

This shader is still some sort of "draft" - when I find time I will rework it and post it in the presentation thread.


Alright, thanks anyway, im looking forward to a updated version. To neutralize colors for a game is really nice to have.

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