Welcome, Guest.
Username: Password: Remember me

TOPIC: YACA (Yet Another Chromatic Aberration)

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

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 609
  • Thank you received: 716
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: 1 year 2 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) 1 year 2 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) 1 year 2 months ago #3

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

YACA (Yet Another Chromatic Aberration) 1 year 2 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) 1 year 2 months ago #5

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

YACA (Yet Another Chromatic Aberration) 1 year 2 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: 1 year 2 months ago by kingeric1992.
The administrator has disabled public write access.

YACA (Yet Another Chromatic Aberration) 1 year 2 months ago #7

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

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

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • 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