oculus1

view src/vr_sdr.h @ 22:251bc9e2e4a1

made mouselook only affect horizontal movement in VR mode
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 28 Sep 2013 04:13:09 +0300
parents
children
line source
1 static const char *sdr_src =
2 "uniform sampler2D tex;\n"
3 "uniform float aspect, scale;\n"
4 "uniform float lens_center_offset;\n"
5 "uniform vec4 dist_factors;\n"
6 "\n"
7 "vec2 distort_texcoords(in vec2 tc);\n"
8 "float barrel_scale(float x, in vec4 k);\n"
9 "\n"
10 "void main()\n"
11 "{\n"
12 " vec2 tc = distort_texcoords(gl_TexCoord[0].xy);\n"
13 "\n"
14 " float vis = any(greaterThan(tc, vec2(1.0)) || lessThan(tc, vec2(0.0))) ? 0.0 : 1.0;\n"
15 "\n"
16 " gl_FragColor.rgb = texture2D(tex, tc).rgb * vis;\n"
17 " gl_FragColor.a = 1.0;\n"
18 "}\n"
19 "\n"
20 "vec2 distort_texcoords(in vec2 tc)\n"
21 "{\n"
22 " // map tc [0, 1] -> [-1, 1]\n"
23 " vec2 pt = tc * 2.0 - 1.0;\n"
24 "\n"
25 " pt.x += lens_center_offset * 2.0;\n"
26 " pt.y /= aspect; // correct for aspect ratio\n"
27 "\n"
28 " float rad = barrel_scale(dot(pt, pt), dist_factors);\n"
29 " pt *= rad; // scale the point by the computer distortion radius\n"
30 "\n"
31 " pt /= scale;\n"
32 " pt.y *= aspect;\n"
33 " pt.x -= lens_center_offset * 2.0;\n"
34 "\n"
35 " // map back to range [0, 1]\n"
36 " return pt * 0.5 + 0.5;\n"
37 "}\n"
38 "\n"
39 "float barrel_scale(float rad, in vec4 k)\n"
40 "{\n"
41 " float radsq = rad * rad;\n"
42 " float radquad = radsq * radsq;\n"
43 " return k.x + k.y * radsq + k.z * radquad + k.w * radquad * radsq;\n"
44 "}\n";