Realtime Atmospheric Scattering rotation fix
Diving into GLSL shaders to create effects supporting visuals I stumbled upon Sean O'neil's work only to find out Martins Upitis already implemented it in Blender's Game Engine.
Implementing this in my one work I noticed it had one shortcoming. The planet needs to be at the origin and can't rotate. So here's a quick fix around this
Blender's Game Engine works with Python. Most code is however done in GLSL. We don't need to change the GLSL code fortunately. The trouble with the code is that it generates pixels in the textures. The textures are in a fixed UV space. If you rotate the object the UV coords rotate along. So to overcome this we need to correct for rotations being done. So the planet rotates but we want the effects to be done like if the planet object is standing still. The solution to that is to correct the positions of the camera and the sun for the rotation of the camera before we feed them to the shaders.
#normally we feed these positions directly
objpos = obj.position
camerapos = camera.position
lightpos = lamp.position
But now we do some extra calculation
objpos = obj.position
# get the planet's orientation
objrot = obj.worldOrientation.to_quaternion()
# reverse the orientation
objrotinv = objrot.conjugated()
# get a copy of the sun's position
lightpos = lamp.position.copy()
# correct the position using the inverse rotation
lightpos.rotate(objrotinv)
# get a copy of the camera's position
camerapos = camera.position.copy()
# correct the position using the inverse rotation
camerapos.rotate(objrotinv)
That's it. The shader now supports a rotating planet