Render eye view with off-center projection to better match visible area
[libs/vr.git] / source / oculusriftcombiner.cpp
index b15c86be54a41e6e3d54b82702bd945b605e1bf3..3ebbcc88914aea5d070bf265c5cd27556cf5274c 100644 (file)
@@ -22,6 +22,7 @@ const char fs_source[] =
        "uniform sampler2D texture;\n"
        "uniform vec4 distortion;\n"
        "uniform vec4 chromatic;\n"
+       "uniform vec2 lens_center;\n"
        "uniform vec2 eye_center;\n"
        "uniform vec3 scale;\n"
        "varying vec2 texcoord;\n"
@@ -29,13 +30,13 @@ const char fs_source[] =
        "{\n"
        "       float r_sq = dot(texcoord, texcoord);\n"
        "       float f = dot(distortion, vec4(1.0, r_sq, r_sq*r_sq, r_sq*r_sq*r_sq));\n"
-       "       vec2 dtc = (texcoord*f-eye_center)/(scale.xy*scale.z)+0.5;\n"
+       "       vec2 dtc = (texcoord*f-eye_center)/(scale.xy*scale.z)+lens_center;\n"
        "       if(dtc.x<0.0 || dtc.y<0.0 || dtc.x>1.0 || dtc.y>1.0)\n"
        "               gl_FragColor = vec4(0.0);\n"
        "       else\n"
        "       {\n"
-       "               vec2 red_dtc = (texcoord*f*(chromatic[0]+chromatic[1]*r_sq)-eye_center)/(scale.xy*scale.z)+0.5;\n"
-       "               vec2 blue_dtc = (texcoord*f*(chromatic[2]+chromatic[3]*r_sq)-eye_center)/(scale.xy*scale.z)+0.5;\n"
+       "               vec2 red_dtc = (texcoord*f*(chromatic[0]+chromatic[1]*r_sq)-eye_center)/(scale.xy*scale.z)+lens_center;\n"
+       "               vec2 blue_dtc = (texcoord*f*(chromatic[2]+chromatic[3]*r_sq)-eye_center)/(scale.xy*scale.z)+lens_center;\n"
        "               gl_FragColor = vec4(texture2D(texture, red_dtc).r, texture2D(texture, dtc).g, texture2D(texture, blue_dtc).b, 1.0);\n"
        "       }\n"
        "}\n";
@@ -155,6 +156,7 @@ void OculusRiftCombiner::update_parameters()
        right_shdata.uniform("scale", 2.0f, 2.5f, oversize);
 
        fov = Geometry::atan(oversize*0.625f/view_distance)*2.0f;
+       frustum_skew = lens_separation*2-1;
 }
 
 float OculusRiftCombiner::distort(float r) const