oculus1

changeset 14:cceffea995a4

implemented wasd controls and clamping of the texcoords to [0, 1]
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Sep 2013 03:35:53 +0300
parents 464e1d135d68
children 402cbb6d9ce3
files sdr.glsl src/main.cc src/vr.cc
diffstat 3 files changed, 54 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/sdr.glsl	Sat Sep 21 03:00:47 2013 +0300
     1.2 +++ b/sdr.glsl	Sat Sep 21 03:35:53 2013 +0300
     1.3 @@ -3,20 +3,20 @@
     1.4  uniform float lens_center_offset;
     1.5  uniform vec4 dist_factors;
     1.6  
     1.7 -vec2 distort_texcoords(in vec2 tc, out float dbgrad);
     1.8 +vec2 distort_texcoords(in vec2 tc);
     1.9  float barrel_scale(float x, in vec4 k);
    1.10  
    1.11  void main()
    1.12  {
    1.13 -	float dbgrad;
    1.14 -	vec2 tc = distort_texcoords(gl_TexCoord[0].xy, dbgrad);
    1.15 +	vec2 tc = distort_texcoords(gl_TexCoord[0].xy);
    1.16  
    1.17 -	gl_FragColor.rgb = texture2D(tex, tc).rgb;
    1.18 -	gl_FragColor.rgb += mix(vec3(1.0, 1.0, 0.0), vec3(0.0), smoothstep(0.01, 0.05, dbgrad));
    1.19 +	float vis = any(greaterThan(tc, vec2(1.0)) || lessThan(tc, vec2(0.0))) ? 0.0 : 1.0;
    1.20 +
    1.21 +	gl_FragColor.rgb = texture2D(tex, tc).rgb * vis;
    1.22  	gl_FragColor.a = 1.0;
    1.23  }
    1.24  
    1.25 -vec2 distort_texcoords(in vec2 tc, out float dbgrad)
    1.26 +vec2 distort_texcoords(in vec2 tc)
    1.27  {
    1.28  	// map tc [0, 1] -> [-1, 1]
    1.29  	vec2 pt = tc * 2.0 - 1.0;
    1.30 @@ -27,8 +27,7 @@
    1.31  	float rad = barrel_scale(dot(pt, pt), dist_factors);
    1.32  	pt *= rad;	// scale the point by the computer distortion radius
    1.33  
    1.34 -	dbgrad = length(pt) * rad;
    1.35 -
    1.36 +	pt /= scale;
    1.37  	pt.y *= aspect;
    1.38  	pt.x -= lens_center_offset * 2.0;
    1.39  
     2.1 --- a/src/main.cc	Sat Sep 21 03:00:47 2013 +0300
     2.2 +++ b/src/main.cc	Sat Sep 21 03:35:53 2013 +0300
     2.3 @@ -138,10 +138,35 @@
     2.4  	vr_shutdown();
     2.5  }
     2.6  
     2.7 +static void handle_input(float dt)
     2.8 +{
     2.9 +	Vector3 inpv;
    2.10 +	float offs = dt * 2.0;
    2.11 +
    2.12 +	if(keystate['w'] || keystate['W']) {
    2.13 +		inpv.z -= offs;
    2.14 +	}
    2.15 +	if(keystate['s'] || keystate['S']) {
    2.16 +		inpv.z += offs;
    2.17 +	}
    2.18 +	if(keystate['d'] || keystate['D']) {
    2.19 +		inpv.x += offs;
    2.20 +	}
    2.21 +	if(keystate['a'] || keystate['A']) {
    2.22 +		inpv.x -= offs;
    2.23 +	}
    2.24 +
    2.25 +	cam.input_move(inpv.x, inpv.y, inpv.z);
    2.26 +}
    2.27 +
    2.28  static void disp()
    2.29  {
    2.30 -	unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
    2.31 +	static long prev_msec;
    2.32 +	long msec = glutGet(GLUT_ELAPSED_TIME);
    2.33 +	float dt = (msec - prev_msec) / 1000.0;
    2.34 +	prev_msec = msec;
    2.35  
    2.36 +	handle_input(dt);
    2.37  	cam.track_vr();
    2.38  
    2.39  	/*glMatrixMode(GL_PROJECTION);
    2.40 @@ -211,7 +236,7 @@
    2.41  	float lpos[] = {0, 60, 0, 1};
    2.42  	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
    2.43  
    2.44 -	draw_grid(100.0, 2.5);
    2.45 +	draw_grid(50.0, 2.5);
    2.46  
    2.47  	static Vector2 teapos[] = {
    2.48  		Vector2(-8, 8), Vector2(8, 8), Vector2(8, -8), Vector2(-8, -8)
    2.49 @@ -245,7 +270,7 @@
    2.50  
    2.51  static void draw_squares()
    2.52  {
    2.53 -	static const int num_sq = 4;
    2.54 +	static const int num_sq = 8;
    2.55  
    2.56  	glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT);
    2.57  	glDisable(GL_LIGHTING);
    2.58 @@ -255,7 +280,7 @@
    2.59  	glTranslatef(0, 1, 0);
    2.60  
    2.61  
    2.62 -	glLineWidth(3.0);
    2.63 +	glLineWidth(2.0);
    2.64  	glColor3f(1.0, 0.7, 0.2);
    2.65  
    2.66  	float zdist = 2.0;
    2.67 @@ -267,7 +292,7 @@
    2.68  		glVertex3f(-1, 1, -zdist);
    2.69  		glEnd();
    2.70  
    2.71 -		zdist += 1.0;
    2.72 +		zdist += 2.0;
    2.73  	}
    2.74  
    2.75  	glPopMatrix();
     3.1 --- a/src/vr.cc	Sat Sep 21 03:00:47 2013 +0300
     3.2 +++ b/src/vr.cc	Sat Sep 21 03:35:53 2013 +0300
     3.3 @@ -107,7 +107,13 @@
     3.4  			vr_ctx.info.distort[i] = info.DistortionK[i];
     3.5  		}
     3.6  
     3.7 -		vr_ctx.info.scale = 1.0;
     3.8 +		Util::Render::StereoConfig stereohelp;
     3.9 +		stereohelp.SetFullViewport(Util::Render::Viewport(0, 0, vr_ctx.info.width, vr_ctx.info.height));
    3.10 +		stereohelp.SetStereoMode(Util::Render::Stereo_LeftRight_Multipass);
    3.11 +		stereohelp.SetHMDInfo(info);
    3.12 +		stereohelp.SetDistortionFitPointVP(-1.0, 0.0);
    3.13 +
    3.14 +		vr_ctx.info.scale = stereohelp.GetDistortionScale();
    3.15  
    3.16  		float vhalfsz = vr_ctx.info.scale * info.VScreenSize * 0.5;
    3.17  		vr_ctx.info.fov = 2.0 * atan(vhalfsz / info.EyeToScreenDistance);
    3.18 @@ -173,6 +179,16 @@
    3.19  	glGetShaderiv(sdr, GL_COMPILE_STATUS, &status);
    3.20  	if(!status) {
    3.21  		fprintf(stderr, "failed to compile distortion shader\n");
    3.22 +
    3.23 +		int loglen;
    3.24 +		glGetShaderiv(sdr, GL_INFO_LOG_LENGTH, &loglen);
    3.25 +
    3.26 +		if(loglen > 0) {
    3.27 +			char *log = (char*)alloca(loglen);
    3.28 +			glGetShaderInfoLog(sdr, loglen, &loglen, log);
    3.29 +			fprintf(stderr, "%s\n", log);
    3.30 +		}
    3.31 +
    3.32  		return false;
    3.33  	}
    3.34