Change camera property every render (stereo)

I’m trying to change the shift_x property of the Camera object per eye.
(The stereo camera runs two renders per frame. One for each eye)

from bge import logic, render
    
def main():
    scene = logic.getCurrentScene()
    objects = scene.objects
    cam = objects['Camera']
    
    if render.getStereoEye() == render.LEFT_EYE:
        print('left')
        cam.shift_x = 0.3
        
    if render.getStereoEye() == render.RIGHT_EYE:
        print('right')
        cam.shift_x = -0.3

main()

But my code above will just run once when the program is started. How do I access the main render loop?

I tried searching for this but there’s nothing on it at all.

There should be a lens shift setting per eye when you use the stereo camera. Also a barrel distortion setting instead of messing with matrices. BGE could really take off as a VR/AR game engine if these settings would be more accessible.

Please have a look at the BGE API. This operation is not supposed to be used within the games logic.

It can be used within the logic bypass to modify render (see the documentation). You will need to create an install script that runs once in the BGE.

install_myRenderModifier


import bge

def myRenderModifier():
   print("myRenderModifier prints to console!")

scene = bge.logic.getCurrentScene()
scene.pre_draw.append(myRenderModifier)

(script mode)

chromaticAberationWithControls.blend (463 KB)
Press A to Add, Press D for backward