YACA (Yet Another Chromatic Aberration)

  • Marty McFly
  • Topic Author
More
8 years 7 months ago - 8 years 7 months ago #1 by Marty McFly YACA (Yet Another Chromatic Aberration) was created by Marty McFly
Hello there! While working on my DOF shader I came up with a more advanced CA version which I now release as standalone.When looking into this subforum I saw that fellow user kingeric1992 also released a not-so-standard CA shader , hence the title.
While all CA shaders on the web either split the RGB channels and offset them or use precalculated hues, I wanted to do something different.
This CA shader here calculates the offset Hues for the spectrum on the fly, so you can use any number of Hues :woohoo: . A Hue count of 3 does the regular Red, Green and Blue split while anything above gives a more precise range of points in the light spectrum.
But pictures speak more than 1000 words!

Depending on the CA offset, you may choose how many different Hues you want.

2 to 11 Hues

10 to 19 Hues

somemorehues to evenmorehues


Yes, on these pictures the CA angle is vertical but no worries, the shader itself works like the old ones!
As the shader is ripped out of the DOF shader, some descriptions etc may be wrong, sorry for that.
Shader is standalone, if the DOF ever makes it to the public it will be in the Framework (I still find optimization points every time I want to release it) along with the CA.

DOWNLOAD:

pastebin.com/QaGL47CR

Just paste the code into an empty ReShade.fx and you are good to go.
Last edit: 8 years 7 months ago by Marty McFly.
The following user(s) said Thank You: matsilagi, SunBroDave, brussell, Ganossa, jas01, Aelius Maximus

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

  • kingeric1992
More
8 years 7 months ago #2 by kingeric1992 Replied by kingeric1992 on topic YACA (Yet Another Chromatic Aberration)
Also need to clarify the fact that HSV hue != spectrum.
A way to increase precision in spectrum color is to sample 1d spectrum texture, or using functions to fit RGB weight
google on visible spectrum + RGB
RGB values of visible spectrum on stackoverflow

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

  • Marty McFly
  • Topic Author
More
8 years 7 months ago - 8 years 7 months ago #3 by Marty McFly Replied by Marty McFly on topic YACA (Yet Another Chromatic Aberration)
This isn't an essay where I have to be as scientifically correct as possible, I have to make sure everyone understands rightaway what I am talking about. Every simplification is also a falsification. Please tell me how I am supposed to explain in easy words without using the word spectrum. And that it isn't scientifically accurate is self-explanatory. I mean it's a shader, it's an approximation of something, like everything we do on ReShade, ENB and whatnot. Do we simulate a real lens, calculate its surface angle to the view vector with a sphere function, calculate the refraction angle based on the wavelength and refraction index of the used material? No we don't, we just want to create a little rainbow effect on the screen borders. But if you want to do that, go ahead. I doubt it will look much different and will only be slower. Yes I could use a texture and yes I could use a better function but that means yet another external texture and a complex function that runs X times. I attempted to use this simple hue to rgb functon in my dof shader for per tap chroma. The performance drop was unbearable.
That dude in your one link explains it perfectly:

There is a relationship between frequency and what is known as Hue, but for complicated reasons of perception, monitor gamut, and calibration, the best you can achieve outside of expensive lab equipment is a gross approximation.

See en.wikipedia.org/wiki/HSL_and_HSV for the math, and note that you'll have to come up with your best guess for the Hue ⇔ Frequency mapping. I expect this empirical mapping to be anything but linear.

Last edit: 8 years 7 months ago by Marty McFly.

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

  • kingeric1992
More
8 years 7 months ago #4 by kingeric1992 Replied by kingeric1992 on topic YACA (Yet Another Chromatic Aberration)
seriously, I'm just saying HSV Hue does not represent spectrum in case ppl get confused....
also using spectrum color has nothing to do with performance. it is just a simple change form one color filter to another.
about the quote, it state that Hue to frequency mapping is nonlinear, but no one is saying about doing that.

here are the internal visible spectrum functions in Mathematica


a approximation such as this can be simply achieved by 4 abs(): 2 for red, another 2 for green and blue channel each with viable result. (ignore the curves and stick to piecewise linear).

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

  • Marty McFly
  • Topic Author
More
8 years 7 months ago - 8 years 7 months ago #5 by Marty McFly Replied by Marty McFly on topic YACA (Yet Another Chromatic Aberration)

kingeric1992 wrote: seriously, I'm just saying HSV Hue does not represent spectrum in case ppl get confused....

Which normal user will be able to tell the difference? And the advanced users will know it anyways, like you.

also using spectrum color has nothing to do with performance. it is just a simple change form one color filter to another.

The current Hue2RGB function I use cannot be shorter. I doubt that a texture lookup or a different function is faster if such function is not smaller. Producing accurate color values it not the only thing any function must do, it must also return values that when summed up, give the original color. I tried your approach with a texture gradient, the colors it gives are not summing up to the source color when added up. Feel free to try any other function in combination with my code.

a approximation such as this can be simply achieved by 4 abs(): 2 for red, another 2 for green and blue channel each with viable result. (ignore the curves and stick to piecewise linear).

But if you want to do that, go ahead

I'm quite satisfied with this result here. As long as I don't claim that I can replicate the physical effect of chromatic aberration, what I have here is totally fine. And much more scalable than precalculated stuff. If you want to put your opinion into working code, I'm more than happy to see the result.
Last edit: 8 years 7 months ago by Marty McFly.

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

  • kingeric1992
More
8 years 7 months ago - 8 years 7 months ago #6 by kingeric1992 Replied by kingeric1992 on topic YACA (Yet Another Chromatic Aberration)
fitting the graph with abs():

resault( top bar is reference)
float3 rainbow( float index)
{
     float4 color;
     color.r = 2.0 - abs(index - 0.72)*8;
     color.g = 1.7 - abs(index - 0.47)*6.46;
     color.b = 2.0 - abs(index - 0.17)*10;
     color.a = 2.0 - abs(index - 0.1)*20;
     color   = saturate(color);
     color.r = color.r + color.a * 0.5;
    return color.rgb;
}
and shadertoy sample
www.shadertoy.com/view/4tBXRw
probably can blend more smoothly with sin(), but abs() it is.

Edit: Also the visible difference to HSV is the reduced red component in violet zone where HSV hue loops back to full red.
Last edit: 8 years 7 months ago by kingeric1992.

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

  • Marty McFly
  • Topic Author
More
8 years 7 months ago - 8 years 7 months ago #7 by Marty McFly Replied by Marty McFly on topic YACA (Yet Another Chromatic Aberration)
Interesting function, definitely added to my stash of useful things. But there is one little problem: the chromas don't sum up to original color, just what I feared.
This is a pic with 25 hues:

[img


and this one with 3:

[img


I tried a few more but all are more or less shifted in the color. That's why a HSV hue is better for things like this. If we can come up with something that chooses the offsets accordingly so that they sum up to the base color again, this might have a future but I doubt that this will ever work on a generic basis.

Edit: just what I like: boasting with optimizations and telling me how wrong I am with doing what I do and then the "optimizations" don't work.
Last edit: 8 years 7 months ago by Marty McFly.

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

  • Alo81
More
8 years 7 months ago #8 by Alo81 Replied by Alo81 on topic YACA (Yet Another Chromatic Aberration)
This looks really rad. Thanks for making/sharing.

Next time I'm playing a game with ReShade support I'll give it a shot.
The following user(s) said Thank You: Marty McFly

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

  • Fu-Bama
More
6 years 2 months ago - 6 years 2 months ago #9 by Fu-Bama Replied by Fu-Bama on topic YACA (Yet Another Chromatic Aberration)
Hi.
I made custom version of YACA deeply inspired by this shader.
Goal was to recreate real lens chromatic aberration spectrum, that add up to white.

Here's real chromatic aberration ( from this link ):
Warning: Spoiler!

Here's source image (just BW version of image above with some levels):
Warning: Spoiler!

Here's shader effect:


Shader code:
*edit: with some optimization tips from Marty McFly
Warning: Spoiler!
Last edit: 6 years 2 months ago by Fu-Bama.
The following user(s) said Thank You: BeTa, brussell, DeMondo, Rudy102, Arkane

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

  • Fu-Bama
More
6 years 2 months ago - 6 years 2 months ago #10 by Fu-Bama Replied by Fu-Bama on topic YACA (Yet Another Chromatic Aberration)
Here are some screenshots from CoD 4 MW

Suddle effect
Before
Warning: Spoiler!



Stronger effect
Before
Warning: Spoiler!

Last edit: 6 years 2 months ago by Fu-Bama.

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

  • Marty McFly
  • Topic Author
More
6 years 2 months ago #11 by Marty McFly Replied by Marty McFly on topic YACA (Yet Another Chromatic Aberration)
Looks interesting! Some optimizations can be made but I doubt it'll give any substantial boost on a fast filter like that.

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

  • Fu-Bama
More
6 years 2 months ago #12 by Fu-Bama Replied by Fu-Bama on topic YACA (Yet Another Chromatic Aberration)

Marty McFly wrote: Looks interesting! Some optimizations can be made but I doubt it'll give any substantial boost on a fast filter like that.

Can you share those optimization tips?

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

  • Marty McFly
  • Topic Author
More
6 years 2 months ago - 6 years 2 months ago #13 by Marty McFly Replied by Marty McFly on topic YACA (Yet Another Chromatic Aberration)
Sure, it's small things, optimized math. For a small shader like this, maybe the compiler is smart enough but for bigger projects it's definitely not.
float Mask = length(RadialCoord) * rsqrt(Aspect * Aspect + 1);
Position = (Position + 1.0) * 0.5; //add, mul
to
Position = Position * 0.5 + 0.5;//madd

Then you do a lot of math inside loop all the time instead of moving it out.
Offset = Mask * CurrentOffset * Aberration * Pixel * 2.0 + 1.0;

to

//outside loop
Mask *= Abberation * Pixel * 2.0;
//inside loop
Offset = Mask * CurrentSample + 1.0;

Then you divide each color sample by amount of samples instead of doing that after the loop once.
//inside loop
BluredImage += Spectrum(CurrentSample) * tex2Dlod(ReShade::BackBuffer, float4(Position, 0, 0)).rgb / Samples * 2.0;

to 
//inside loop
BluredImage += Spectrum(CurrentSample) * tex2Dlod(ReShade::BackBuffer, float4(Position, 0, 0)).rgb;
//outside
BluredImage = BluredImage / Samples * 2.0;
then instead of doing that, you could maybe sum up all the Spectrum weights and divide final BluredImage by that, that way you should get a tint free image even for low sample counts. Maybe there's more, I know from experience that many shaders can be wittled down a LOT but then you have no real idea anymore what's going on.
Last edit: 6 years 2 months ago by Marty McFly.
The following user(s) said Thank You: brussell, DeMondo, Fu-Bama

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

  • Fu-Bama
More
6 years 2 months ago - 6 years 2 months ago #14 by Fu-Bama Replied by Fu-Bama on topic YACA (Yet Another Chromatic Aberration)

Marty McFly wrote: (...) then instead of doing that, you could maybe sum up all the Spectrum weights and divide final BluredImage by that, that way you should get a tint free image even for low sample counts. (...)

Even 2 sample will give original, tint-free white balance, just the color split won't be cyan-blue/yellow-red, but purple/green. Note, you can set automatic sample to off and duble click the value, type in 2, or 4.

Thanks for the tips, I just added them to the code.
Last edit: 6 years 2 months ago by Fu-Bama.

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

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.