]> git.tdb.fi Git - libs/vr.git/commitdiff
Use vignetting to smoothly fade out the edges
authorMikko Rasa <tdb@tdb.fi>
Mon, 22 Dec 2014 23:56:45 +0000 (01:56 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 22 Dec 2014 23:56:45 +0000 (01:56 +0200)
This somewhat reduces artifacts seen at the borders.

source/oculusriftcombiner.cpp

index 492f5fdbcb220ee40b5f73207fb0f7ee6a94a12c..a9808de75a4c72a059b4365a9d499bbc1e4a1fc6 100644 (file)
@@ -14,12 +14,14 @@ const char vs_source[] =
        "varying vec2 texcoord_r;\n"
        "varying vec2 texcoord_g;\n"
        "varying vec2 texcoord_b;\n"
+       "varying float vignette;\n"
        "void main()\n"
        "{\n"
        "       gl_Position = vec4(gl_Vertex.xy, 0.5, 1.0);\n"
        "       texcoord_r = gl_MultiTexCoord0.xy;\n"
        "       texcoord_g = gl_MultiTexCoord1.xy;\n"
        "       texcoord_b = gl_MultiTexCoord2.xy;\n"
+       "       vignette = gl_MultiTexCoord3.x;\n"
        "}\n";
 
 const char fs_source[] =
@@ -27,18 +29,19 @@ const char fs_source[] =
        "varying vec2 texcoord_r;\n"
        "varying vec2 texcoord_g;\n"
        "varying vec2 texcoord_b;\n"
+       "varying float vignette;\n"
        "void main()\n"
        "{\n"
        "       float r = texture2D(texture, texcoord_r).r;\n"
        "       float g = texture2D(texture, texcoord_g).g;\n"
        "       float b = texture2D(texture, texcoord_b).b;\n"
-       "       gl_FragColor = vec4(r, g, b, 1.0);\n"
+       "       gl_FragColor = vec4(vec3(r, g, b)*vignette, 1.0);\n"
        "}\n";
 
 void create_distortion_mesh(Msp::GL::Mesh &mesh, ovrHmd hmd, ovrEyeType eye, const ovrFovPort &fov)
 {
        ovrDistortionMesh ovr_mesh;
-       ovrHmd_CreateDistortionMesh(hmd, eye, fov, ovrDistortionCap_Chromatic, &ovr_mesh);
+       ovrHmd_CreateDistortionMesh(hmd, eye, fov, ovrDistortionCap_Chromatic|ovrDistortionCap_Vignette, &ovr_mesh);
 
        ovrSizei tex_size = ovrHmd_GetFovTextureSize(hmd, eye, fov, 1.0);
        ovrRecti view_rect;
@@ -57,6 +60,7 @@ void create_distortion_mesh(Msp::GL::Mesh &mesh, ovrHmd hmd, ovrEyeType eye, con
                bld.multitexcoord(0, v.TanEyeAnglesR.x*scale.x+offset.x, 1.0f-(v.TanEyeAnglesR.y*scale.y+offset.y));
                bld.multitexcoord(1, v.TanEyeAnglesG.x*scale.x+offset.x, 1.0f-(v.TanEyeAnglesG.y*scale.y+offset.y));
                bld.multitexcoord(2, v.TanEyeAnglesB.x*scale.x+offset.x, 1.0f-(v.TanEyeAnglesB.y*scale.y+offset.y));
+               bld.multitexcoord(3, v.VignetteFactor);
                bld.vertex(v.ScreenPosNDC.x, v.ScreenPosNDC.y);
        }
 
@@ -74,8 +78,8 @@ namespace VR {
 
 OculusRiftCombiner::OculusRiftCombiner(const OculusRiftDevice &d):
        device(d),
-       left_mesh((GL::VERTEX2, GL::TEXCOORD2,0, GL::TEXCOORD2,1, GL::TEXCOORD2,2)),
-       right_mesh((GL::VERTEX2, GL::TEXCOORD2,0, GL::TEXCOORD2,1, GL::TEXCOORD2,2)),
+       left_mesh((GL::VERTEX2, GL::TEXCOORD2,0, GL::TEXCOORD2,1, GL::TEXCOORD2,2, GL::TEXCOORD1,3)),
+       right_mesh((GL::VERTEX2, GL::TEXCOORD2,0, GL::TEXCOORD2,1, GL::TEXCOORD2,2, GL::TEXCOORD1,3)),
        shprog(vs_source, fs_source)
 {
        const OculusRiftDevice::Private &dev_priv = device.get_private();