I'm trying to implement a GLSL shader which helps understanding special relativity Lorentz Transformation.
Let's take two axis-aligned inertial observer O and O' . The observer O' is in motion w.r.t observer O with velocity v=(v_x,0,0).
When described in terms of O' coordinates, an event P' = (x',y',z',ct') has transformed coordinates (x,y,z,ct)= L (x',y',z',ct')
where L is a 4x4 matrix called Lorentz transformation which helps us writing the coordinates of event P' in O coordinates.
(for details look http://en.wikipedia.org/wiki/Lorentz_transformation#Boost_in_the_x-direction)
I've wrote down a first preliminary vertex shader that apply the Lorentz transformation given the velocity to every vertex, but I can't get the transformation to work correctly.
vec3 beta= vec3(0.5,0.0,0.0);
float b2 = (beta.x*beta.x + beta.y*beta.y + beta.z*beta.z )+1E-12;
float g=1.0/(sqrt(abs(1.0-b2))+1E-12); // Lorentz factor (boost)
float q=(g-1.0)/b2;
//http://en.wikipedia.org/wiki/Lorentz_transformation#Matrix_forms
vec3 tmpVertex = (gl_ModelViewMatrix*gl_Vertex).xyz;
float w = gl_Vertex.w;
mat4 lorentzTransformation =
mat4(
1.0+beta.x*beta.x*q , beta.x*beta.y*q , beta.x*beta.z*q , beta.x*g ,
beta.y*beta.x*q , 1.0+beta.y*beta.y*q , beta.y*beta.z*q , beta.y*g ,
beta.z*beta.x*q , beta.z*beta.y*q , 1.0+beta.z*beta.z*q , beta.z*g ,
beta.x*g , beta.y*g , beta.z*g , g
);
vec4 vertex2 = (lorentzTransformation)*vec4(tmpVertex,1.0);
gl_Position = gl_ProjectionMatrix*(vec4(vertex2.xyz,1.0) );
This shader should apply to every vertex and perform the non-linear Lorentz transformation, but the transformation it performs is clearly different from what I'd expect (in this case a length-contraction on x-axis).
Has somebody already worked on special relativity shader for 3D videogame?


Ois in (0,0,0) looking down the z-axis while the observerO'is in motion w.r.tOwith velocityv_xand the objects described forO'are at rest. I know that in this vertex shader the transformation are applied only for vertices so the deformation of lines is lost but I just want to understand and make work this at first. Seems that the game Polynomial already made transformations of this kind, but the shader I've found doesn't nothing interesting, because I get the same results! bit.ly/MueQqo – linello Jul 30 '12 at 14:52