Hey y’all. We’ve all used chromatic aberration in our projects, but the current method of creating it using the Lens Distortion node in the compositor is very limiting and not very accurate to the real world. I’ve been experimenting with recreating this effect optically, directly in cycles. Not only did I find a way to recreate a more realistic chromatic aberration effect, I’ve also found ways to recreate effects like longitudinal chromatic aberration, spherical aberration, cats eye bokeh, and vignetting (with more possibilities to come).
Take a look at my first prototype here: Advanced Optics prototype 1.blend (8.17 MB)
(effects are controlled using the material nodegroup and shape keys)
Lateral Achromatic Aberration, Spherical Aberration & Cat’s Eye test:
Yes this is cycles. (Made using Quixel Megascan’s free samples)
Scroll down for more!
Longitudinal Achromatic / Chromatic Aberration:
Real world example:
Lateral Achromatic Aberration:
- Increases render times and noise in some cases
(especially with Longitudinal Aberration)
- Is not completely physically accurate
- Is controlled with material nodegroups and shape keys
- The lens and lens hoods has to be scaled along with the size of the camera’s aperture
- Doesn’t work well with cycles’ denoising feature
- This technique works best with Branched Path Tracing and Correlated Multi-jitter.
- A side effect is colored noise, since light is split into red, green, and blue.
- This is a prototype and has much room for improvement and optimizations.
- I would like to experiment with OSL, but I don’t have any experience with OSL.
Thanks for reading! Please give it a try and post tests, feedback, or discussion below.
dude, this is crazy!
i made some experiments with a setup like this in the past but damn, you took it to a new level.
Glad you like it. I have been almost obsessed with it this past week haha
Truly admirable stuff going on here.
Gonna take a look.
&thanks to your obsessions
Could you give some realistic values for all the different settings?
Looks very interesting! Can you give a bit of background on how it works? The node-setup is quite complex…
That’s hard to say, as the values depend on the size of the aperture and the distance to the focus point. Best to just play around with it until you find something that works. Remember the lens and lens hoods has to be scaled along with the size of the camera’s aperture!
One thing I can recommend is in to not use the foreground and background aberration settings at the same time. One of them should always be at 0!
The node/setup is only complex because it essentially mixes 3 materials into one. The most important part is this:
This just splits the lenses into red, green, and blue, with different IOR values, which creates the lateral and longitudinal aberration effects. The values in the node group simply control the amount of IOR separation of the RGB values. Much of the complexity of the nodegroup is to make sure the lenses are invisible, when the values are at 0, as to not slow down render times when they are not in use.
There are 3 lenses that control the aberration effects (not the lens hood effects).
Lens 1 is used for Longitudinal Chromatic Aberration and works like this:
Lens 2 is essentially the same as lens 1 except it is flat, which creates a lateral aberration effect, instead of a longitudinal aberration effect.
Lens 3 is what controls spherical aberration. The dome shape of the lens scatters the light unevenly, creating a ring / haze effect. The shape of the lens is controlled using shape keys. This lens does not need to split the light into RGB.
I think it’s possible to to eliminate the need for lens 2 all together, which might make for faster renders when using longitudinal aberration and lateral aberration at the same time.
I hope you’re not afraid of spiders :eek:
Here’s a test using longitudinal chromatic aberration and spherical aberration:
Comparison with no aberration:
It’s a GIF
I know it looks “uglier”, but that’s the point. We’re not trying to make the image prettier. We’re trying to make it look more like a real picture, which means recreating the inherent flaws in camera lenses.
Wow, those aberrations really sell the close up. I have spent years wondering where that red/green fringe comes from, especially noticeable on TV dramas where the lenses are cheap and the bokeh cheaper.
With this setup, can you get bokeh like this image?
It could be possible, but it would take some heavy tweaking to create the modulation effect and the small distortions in the bokeh. It would also require a lot of samples because the lights would have to be tiny to create such a sharp bokeh.
I haven’t looked into how the modulation effect works, so I honestly don’t know how to create it, but I know it’s related to spherical aberration. Although, I do recall accidentally creating a similar effect once, but I forgot how I did it.
The distortions could be made by using a noise texture as a bump on one of the lenses. The small specks might just be dirt on the lens, so that could probably also be done with a texture on one of the lenses.
I’ve attempted this before, but boy have you done a good job of it.
How have you managed to do the lens hood occlusion? Is that just real geometery? I’m guessing that would also be possible with a node group which takes the input normal and position into account and returns either blackout or transparent, though that would add a transparent calculation to every single ray, so maybe the geometery version is more optimised.
Also with spherical aberration, is that done just with a plane with a material? I’d love to take a deep dive into this and potentially see if some of it could be added to Cycles itself.
While the entire lens setup could potentially be done with a shader or 2, the current implementation is largely geometry-based both for speed purposes and that minuscule additional touch of physical accuracy.
It is currently faster to calculate the triangle intersections than it is to calculate the normal on a parabola/sphere in-shader.
The spherical aberration is achieved by a spherical lens in the front.
really interesting stuff.
Cool stuff! I was just wondering if you since made any updates to your prototype?