Making a smoother Contrast Equation

Post Reply
  • Author
  • Message
Offline
Posts: 9
Joined: 27 Sep 2023, 23:45

Making a smoother Contrast Equation

Hey i'm making a Contrast effect and i'm using this equation : color.rgb = (color.rgb - 0.5) * Contrast + 0.5;. However, it's not really smooth and creates dark areas. Any idea of another smoother equation?

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17447
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: Making a smoother Contrast Equation

Maybe try non linear amount of shift, when near black and near white value is compressed. Something like the following code (check yourself for errors, i just give an idea):
float ContrastCurve = 1.0; //change this
float nonlinearcontrast = dot(color.rgb, 0.3333);
nonlinearcontrast = abs(nonlinearcontrast * 2.0 - 1.0);
nonlinearcontrast = saturate(1.0 - nonlinearcontrast);
nonlinearcontrast = pow(nonlinearcontrast, ContrastCurve);
color.rgb = (color.rgb - 0.5) * Contrast * nonlinearcontrast + 0.5;
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
Post Reply