Chromatic aberration predistortion filter?

I need a way to access the red, green and blue channels of a frame and apply distortion to them.
This may be done different ways, shaders, render to texture for each channel then manipulate the texture somehow (UVs, or positions of points on a grid card instead).

The main reason for this is using Panda3D with optical systems where chromatic aberration is an issue and the frames need to be pre-distorted with the color channels pre-distorted in such a way as to appear normal after the chromatic aberration distortion from real life lenses, such as in VR, or spherical screens. This solution is known as “cchromatic aberration software compensation”. https://developer.oculus.com/documentation/pcsdk/0.4/concepts/dg-chromatic-aberration/

What approach would you suggest?

Yes, I know both SteamVR, Oculus and similar SDKs include this but I use none of them and not only VR.

Hi,

I have managed to use the “FilterManager” for something similar. In my case I wanted to simulate a particular colour blindness condition. Conceptually is a full screen pass with all the work on a fragment shader, but I do not know how is implemented internally in the engine.

I can share the code if you need, I used GLSL in the end, check this (if you have not yet):
https://www.panda3d.org/manual/index.php/Generalized_Image_Filters

It may be possible with filter only, although the distortion map would have to be read by the shader somehow.

What I do roughly is,

shader = Shader.load(Shader.SL_GLSL, vertex=“shader.vs”, fragment=“shader.fs”)
filter = FilterManager(base.win, base.cam)
filter.setShader(shader)

If I remember correctly this is pretty much all there is to connect the filter as a post-processing pass. It should be possible to use set_shader_input() from the Shader class to add an additional texture or buffer with your correction map
https://www.panda3d.org/manual/index.php/List_of_GLSL_Shader_Inputs

I can try in a couple of days and come back to you, I don’t have the environment now to try this.

you need a shader to use FilterManager first

Sorry, I am not sure I understand, is that a question?

If I understand your problem correctly, you want to render as usual, but before presenting the image to the HMD you want to apply a filter to the entire buffer[s] (not sure how is stereo rendering handled here).

Would that not be possible with the FilterManager, and a custom shader you write (adding any extra input needed to move the colour planes)?

Do you need help writing the actual shader code?

Of course, the issue is the shader code, not how to set up FilterManager (that is in the manual)

Ok, I see.
I am afraid I cannot help you with this shader, maybe someone else can.

I saw a forked project from the RenderingPipeline where they integrated OpenVR with Panda3D (in a plugin), but it looks very recent (days old) so I do not know if it fully works. I guess a pre-distorted image is enough if you go through the VR compositor.

good luck!