# HG changeset patch # User John Tsiombikas # Date 1379726120 -10800 # Node ID 402cbb6d9ce31a38ad8018251b3e98dae0d0e080 # Parent cceffea995a46c445bb5aa66e27ad1026b65b506 added the shader as a separate header file diff -r cceffea995a4 -r 402cbb6d9ce3 src/vr.cc --- a/src/vr.cc Sat Sep 21 03:35:53 2013 +0300 +++ b/src/vr.cc Sat Sep 21 04:15:20 2013 +0300 @@ -2,35 +2,7 @@ #include #include "vr.h" #include "vr_impl.h" - -static const char *sdr_src = - "uniform sampler2D tex;\n" - "uniform vec2 lens_center;\n" - "uniform vec2 scr_center;\n" - "uniform vec2 scale;\n" - "uniform vec2 scale_in;\n" - "uniform vec4 warp_param;\n" - "\n" - "vec2 warp(in vec2 pt, out float dbgrad)\n" - "{\n" - " vec2 theta = (pt - lens_center) * scale_in;\n" - " float rsq = dot(theta, theta);\n" - " vec2 rvec = theta * (warp_param.x + \n" - " warp_param.y * rsq +\n" - " warp_param.z * rsq * rsq +\n" - " warp_param.w * rsq * rsq * rsq);\n" - " dbgrad = length(theta);\n" - " return lens_center + scale * rvec;\n" - "}\n" - "\n" - "void main()\n" - "{\n" - " float dbgrad;\n" - " vec2 tc = warp(gl_TexCoord[0].xy, dbgrad);\n" - " gl_FragColor.rgb = texture2D(tex, tc).rgb;\n" - " gl_FragColor.rgb += mix(vec3(1.0, 1.0, 0.0), vec3(0.0), smoothstep(0.01, 0.05, dbgrad));\n" - " gl_FragColor.a = 1.0;\n" - "}\n"; +#include "vr_sdr.h" static bool init_ovr(); static bool init_sdr(); @@ -55,6 +27,7 @@ extern "C" void vr_shutdown(void) { + delete [] vr_ctx.info.display; //System::Destroy(); } @@ -124,6 +97,10 @@ float center_dist_meters = info.HScreenSize * 0.25; float proj_shift = center_dist_meters - info.LensSeparationDistance * 0.5; vr_ctx.info.proj_center_offset = 4.0 * proj_shift / info.HScreenSize; + + // grab the display name + vr_ctx.info.display = new char[strlen(info.DisplayDeviceName) + 1]; + strcpy(vr_ctx.info.display, info.DisplayDeviceName); } // get the sensor device diff -r cceffea995a4 -r 402cbb6d9ce3 src/vr_impl.h --- a/src/vr_impl.h Sat Sep 21 03:35:53 2013 +0300 +++ b/src/vr_impl.h Sat Sep 21 04:15:20 2013 +0300 @@ -12,6 +12,7 @@ SensorFusion ovr_sfusion; struct { + char *display; // the full width and height of the display (both eyes) int width, height; float fov; diff -r cceffea995a4 -r 402cbb6d9ce3 src/vr_sdr.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/vr_sdr.h Sat Sep 21 04:15:20 2013 +0300 @@ -0,0 +1,45 @@ +static const char *sdr_src = + "uniform sampler2D tex;\n" + "uniform float aspect, scale;\n" + "uniform float lens_center_offset;\n" + "uniform vec4 dist_factors;\n" + "\n" + "vec2 distort_texcoords(in vec2 tc);\n" + "float barrel_scale(float x, in vec4 k);\n" + "\n" + "void main()\n" + "{\n" + " vec2 tc = distort_texcoords(gl_TexCoord[0].xy);\n" + "\n" + " float vis = any(greaterThan(tc, vec2(1.0)) || lessThan(tc, vec2(0.0))) ? 0.0 : 1.0;\n" + "\n" + " gl_FragColor.rgb = texture2D(tex, tc).rgb * vis;\n" + " gl_FragColor.a = 1.0;\n" + "}\n" + "\n" + "vec2 distort_texcoords(in vec2 tc)\n" + "{\n" + " // map tc [0, 1] -> [-1, 1]\n" + " vec2 pt = tc * 2.0 - 1.0;\n" + "\n" + " pt.x += lens_center_offset * 2.0;\n" + " pt.y /= aspect; // correct for aspect ratio\n" + "\n" + " float rad = barrel_scale(dot(pt, pt), dist_factors);\n" + " pt *= rad; // scale the point by the computer distortion radius\n" + "\n" + " pt /= scale;\n" + " pt.y *= aspect;\n" + " pt.x -= lens_center_offset * 2.0;\n" + "\n" + " // map back to range [0, 1]\n" + " return pt * 0.5 + 0.5;\n" + "}\n" + "\n" + "float barrel_scale(float rad, in vec4 k)\n" + "{\n" + " float radsq = rad * rad;\n" + " float radquad = radsq * radsq;\n" + " return k.x + k.y * radsq + k.z * radquad + k.w * radquad * radsq;\n" + "}\n"; +