goat3dgfx
diff src/vr/vr_sdr.h @ 11:d061fe1a31ec
compile vr source files or not
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 24 Nov 2013 14:00:14 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/vr/vr_sdr.h Sun Nov 24 14:00:14 2013 +0200 1.3 @@ -0,0 +1,45 @@ 1.4 +static const char *sdr_src = 1.5 + "uniform sampler2D tex;\n" 1.6 + "uniform float aspect, scale;\n" 1.7 + "uniform float lens_center_offset;\n" 1.8 + "uniform vec4 dist_factors;\n" 1.9 + "\n" 1.10 + "vec2 distort_texcoords(in vec2 tc);\n" 1.11 + "float barrel_scale(float x, in vec4 k);\n" 1.12 + "\n" 1.13 + "void main()\n" 1.14 + "{\n" 1.15 + " vec2 tc = distort_texcoords(gl_TexCoord[0].xy);\n" 1.16 + "\n" 1.17 + " float vis = any(greaterThan(tc, vec2(1.0)) || lessThan(tc, vec2(0.0))) ? 0.0 : 1.0;\n" 1.18 + "\n" 1.19 + " gl_FragColor.rgb = texture2D(tex, tc).rgb * vis;\n" 1.20 + " gl_FragColor.a = 1.0;\n" 1.21 + "}\n" 1.22 + "\n" 1.23 + "vec2 distort_texcoords(in vec2 tc)\n" 1.24 + "{\n" 1.25 + " // map tc [0, 1] -> [-1, 1]\n" 1.26 + " vec2 pt = tc * 2.0 - 1.0;\n" 1.27 + "\n" 1.28 + " pt.x += lens_center_offset * 2.0;\n" 1.29 + " pt.y /= aspect; // correct for aspect ratio\n" 1.30 + "\n" 1.31 + " float rad = barrel_scale(dot(pt, pt), dist_factors);\n" 1.32 + " pt *= rad; // scale the point by the computer distortion radius\n" 1.33 + "\n" 1.34 + " pt /= scale;\n" 1.35 + " pt.y *= aspect;\n" 1.36 + " pt.x -= lens_center_offset * 2.0;\n" 1.37 + "\n" 1.38 + " // map back to range [0, 1]\n" 1.39 + " return pt * 0.5 + 0.5;\n" 1.40 + "}\n" 1.41 + "\n" 1.42 + "float barrel_scale(float rad, in vec4 k)\n" 1.43 + "{\n" 1.44 + " float radsq = rad * rad;\n" 1.45 + " float radquad = radsq * radsq;\n" 1.46 + " return k.x + k.y * radsq + k.z * radquad + k.w * radquad * radsq;\n" 1.47 + "}\n"; 1.48 +