Welcome, Guest.
Username: Password: Remember me

TOPIC: YACA (Yet Another Chromatic Aberration)

YACA (Yet Another Chromatic Aberration) 2 years 8 months ago #1

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 1000
  • Thank you received: 996
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: 2 years 8 months ago by Marty McFly.
The administrator has disabled public write access.
The following user(s) said Thank You: matsilagi, SunBroDave, brussell, Ganossa, jas01, Aelius Maximus

YACA (Yet Another Chromatic Aberration) 2 years 8 months ago #2

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
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 2 years 8 months ago #3

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 1000
  • Thank you received: 996
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: 2 years 8 months ago by Marty McFly.
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 2 years 8 months ago #4

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).
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 2 years 8 months ago #5

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 1000
  • Thank you received: 996
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: 2 years 8 months ago by Marty McFly.
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 2 years 8 months ago #6

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: 2 years 8 months ago by kingeric1992.
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 2 years 8 months ago #7

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 1000
  • Thank you received: 996
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:



and this one with 3:



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: 2 years 8 months ago by Marty McFly.
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 2 years 8 months ago #8

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 18
  • Thank you received: 6
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 administrator has disabled public write access.
The following user(s) said Thank You: Marty McFly

YACA (Yet Another Chromatic Aberration) 3 months 2 weeks ago #9

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 70
  • Thank you received: 67
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! [ Click to expand ]

Here's source image (just BW version of image above with some levels):
Warning: Spoiler! [ Click to expand ]

Here's shader effect:


Shader code:
*edit: with some optimization tips from Marty McFly
Warning: Spoiler! [ Click to expand ]
If you want to buy me a coffee, www.paypal.me/fubax :)
Last Edit: 3 months 5 days ago by Fu-Bama.
The administrator has disabled public write access.
The following user(s) said Thank You: BeTa, brussell, DeMondo, Rudy102, Arkane

YACA (Yet Another Chromatic Aberration) 3 months 2 weeks ago #10

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 70
  • Thank you received: 67
Here are some screenshots from CoD 4 MW

Suddle effect
Before
Warning: Spoiler! [ Click to expand ]



Stronger effect
Before
Warning: Spoiler! [ Click to expand ]

If you want to buy me a coffee, www.paypal.me/fubax :)
Last Edit: 3 months 1 week ago by Fu-Bama.
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 3 months 1 week ago #11

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 1000
  • Thank you received: 996
Looks interesting! Some optimizations can be made but I doubt it'll give any substantial boost on a fast filter like that.
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 3 months 1 week ago #12

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 70
  • Thank you received: 67
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?
If you want to buy me a coffee, www.paypal.me/fubax :)
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 3 months 1 week ago #13

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 1000
  • Thank you received: 996
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: 3 months 1 week ago by Marty McFly.
The administrator has disabled public write access.
The following user(s) said Thank You: brussell, DeMondo, Fu-Bama

YACA (Yet Another Chromatic Aberration) 3 months 6 days ago #14

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 70
  • Thank you received: 67
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.
If you want to buy me a coffee, www.paypal.me/fubax :)
Last Edit: 3 months 5 days ago by Fu-Bama.
The administrator has disabled public write access.