# Special relativity shader in GLSL

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.

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).

• It's actually a linear transformation, not non-linear, as the wiki you linked states. So what you see sounds ok, however, hard to say for sure without seeing it. – Maik Semder Jul 30 '12 at 12:31
• You can try this shader in ShaderMaker to see the effects, but what I'd want to achieve is this effect: spacetimetravel.org/relaflug/relaflug.html Here we should see the lenght contraction on x-axis but I see an incorrect scaling – linello Jul 30 '12 at 13:09
• Do you actually move the camera? The spacetimetravle-link comes with source code, might worth having a look there – Maik Semder Jul 30 '12 at 13:48
• also the speed 0.5 c/s is a bit small, try using something bigger than 0.9, the example uses 0.93 c/s and move the camera with that speed – Maik Semder Jul 30 '12 at 14:04
• No I suppose the observer O is in (0,0,0) looking down the z-axis while the observer O' is in motion w.r.t O with velocity v_x and the objects described for O' 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