oculus1
diff sdr/sdr.glsl @ 16:f3672317e5c2
made teapots many sizes and more colorful, added phong shader
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 21 Sep 2013 05:22:48 +0300 |
parents | sdr.glsl@cceffea995a4 |
children | 1b107de821c1 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/sdr/sdr.glsl Sat Sep 21 05:22:48 2013 +0300 1.3 @@ -0,0 +1,43 @@ 1.4 +uniform sampler2D tex; 1.5 +uniform float aspect, scale; 1.6 +uniform float lens_center_offset; 1.7 +uniform vec4 dist_factors; 1.8 + 1.9 +vec2 distort_texcoords(in vec2 tc); 1.10 +float barrel_scale(float x, in vec4 k); 1.11 + 1.12 +void main() 1.13 +{ 1.14 + vec2 tc = distort_texcoords(gl_TexCoord[0].xy); 1.15 + 1.16 + float vis = any(greaterThan(tc, vec2(1.0)) || lessThan(tc, vec2(0.0))) ? 0.0 : 1.0; 1.17 + 1.18 + gl_FragColor.rgb = texture2D(tex, tc).rgb * vis; 1.19 + gl_FragColor.a = 1.0; 1.20 +} 1.21 + 1.22 +vec2 distort_texcoords(in vec2 tc) 1.23 +{ 1.24 + // map tc [0, 1] -> [-1, 1] 1.25 + vec2 pt = tc * 2.0 - 1.0; 1.26 + 1.27 + pt.x += lens_center_offset * 2.0; 1.28 + pt.y /= aspect; // correct for aspect ratio 1.29 + 1.30 + float rad = barrel_scale(dot(pt, pt), dist_factors); 1.31 + pt *= rad; // scale the point by the computer distortion radius 1.32 + 1.33 + pt /= scale; 1.34 + pt.y *= aspect; 1.35 + pt.x -= lens_center_offset * 2.0; 1.36 + 1.37 + // map back to range [0, 1] 1.38 + return pt * 0.5 + 0.5; 1.39 +} 1.40 + 1.41 +float barrel_scale(float rad, in vec4 k) 1.42 +{ 1.43 + float radsq = rad * rad; 1.44 + float radquad = radsq * radsq; 1.45 + return k.x + k.y * radsq + k.z * radquad + k.w * radquad * radsq; 1.46 +}