# HG changeset patch # User John Tsiombikas # Date 1361163224 -7200 # Node ID f0a47f46ee45d6e0346c80b393e1fdaaa4f597e8 # Parent 6036563315149eeb33831f0f4a0a4ec213f49540 lalala diff -r 603656331514 -r f0a47f46ee45 sdr/phong.p.glsl --- a/sdr/phong.p.glsl Mon Feb 18 05:44:17 2013 +0200 +++ b/sdr/phong.p.glsl Mon Feb 18 06:53:44 2013 +0200 @@ -4,18 +4,25 @@ { vec3 n = normalize(normal); vec3 v = -normalize(vpos); - vec3 l = normalize(gl_LightSource[0].position.xyz); - vec3 h = normalize(v + l); + vec3 color = vec3(0.0, 0.0, 0.0); - float ndotl = max(dot(n, l), 0.0); - float ndoth = max(dot(n, h), 0.0); - float spec = pow(ndoth, gl_FrontMaterial.shininess); + for(int i=0; i<2; i++) { + vec3 l = normalize(gl_LightSource[i].position.xyz); + vec3 h = normalize(v + l); + + float ndotl = max(dot(n, l), 0.0); + float ndoth = max(dot(n, h), 0.0); + float spec = pow(ndoth, gl_FrontMaterial.shininess); + + vec3 dcol = gl_FrontMaterial.diffuse.xyz * gl_LightSource[i].diffuse.xyz; + vec3 scol = gl_FrontMaterial.specular.xyz * gl_LightSource[i].diffuse.xyz; + + color += dcol * ndotl + scol * spec; + } vec3 acol = gl_FrontMaterial.ambient.xyz * gl_LightModel.ambient.xyz; - vec3 dcol = gl_FrontMaterial.diffuse.xyz * gl_LightSource[0].diffuse.xyz; - vec3 scol = gl_FrontMaterial.specular.xyz * gl_LightSource[0].specular.xyz; - gl_FragColor.xyz = acol + dcol * ndotl + scol * spec; + gl_FragColor.xyz = acol + color; gl_FragColor.w = 1.0; } diff -r 603656331514 -r f0a47f46ee45 src/mballs.cc --- a/src/mballs.cc Mon Feb 18 05:44:17 2013 +0200 +++ b/src/mballs.cc Mon Feb 18 06:53:44 2013 +0200 @@ -23,6 +23,7 @@ static float grid[MBALL_GRID_SZ][MBALL_GRID_SZ][MBALL_GRID_SZ]; static std::vector balls; static struct metasurface *msurf; +static float floor_height = -0.95; bool mball_init() { @@ -54,14 +55,61 @@ { update(); + const float blue[] = {0.4, 0.45, 1.0, 1}; + const float dark_red[] = {0.6, 0.2, 0.1, 1}; + const float white[] = {1, 1, 1, 1}; + const float black[] = {0, 0, 0, 1}; + glMatrixMode(GL_MODELVIEW); glPushMatrix(); glScalef(4.0, 4.0, 4.0); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80.0); + glBegin(GL_TRIANGLES); msurf_polygonize(msurf); glEnd(); + // floor + glBegin(GL_QUADS); + glNormal3f(0, 1, 0); + glVertex3f(-5, -1, 5); + glVertex3f(5, -1, 5); + glVertex3f(5, -1, -5); + glVertex3f(-5, -1, -5); + glEnd(); + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dark_red); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80.0); + + // box + glPushMatrix(); + glTranslatef(0, -1.7, 1); + glScalef(1.05, 1, 0.05); + glutSolidCube(2.0); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(0, -1.7, -1); + glScalef(1.05, 1, 0.05); + glutSolidCube(2.0); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(1, -1.7, 0); + glScalef(0.05, 1, 1); + glutSolidCube(2.0); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-1, -1.7, 0); + glScalef(0.05, 1, 1); + glutSolidCube(2.0); + glPopMatrix(); + glPopMatrix(); } @@ -103,6 +151,15 @@ sum += 1000.0; } } + + // floor + float height = y - floor_height; + if(height > 1e-6) { + sum += 1.0 / height; + } else { + sum += 1000.0; + } + return sum; } diff -r 603656331514 -r f0a47f46ee45 src/udg.cc --- a/src/udg.cc Mon Feb 18 05:44:17 2013 +0200 +++ b/src/udg.cc Mon Feb 18 06:53:44 2013 +0200 @@ -36,12 +36,13 @@ void destroy_rtarg(struct render_target *rt); int xsz, ysz; -float cam_theta, cam_phi = 25, cam_dist = 9; +float cam_theta, cam_phi = 25, cam_dist = 11; unsigned int dither_tex; struct render_target *rtarg; unsigned int post_prog, phong_prog; int opt_highres, opt_regular_render; +bool opt_autorot = true; int main(int argc, char **argv) @@ -130,6 +131,7 @@ glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); + glEnable(GL_LIGHT1); glEnable(GL_NORMALIZE); return true; @@ -168,7 +170,13 @@ void disp() { float ldir[] = {-1, 1, 2, 0}; + float ldir2[] = {0.0, 0.35, -0.9, 0}; + + float lcol[] = {1, 1, 1, 1}; + float lcol2[] = {0.35, 0.3, 0.15, 1}; + int xres, yres; + float auto_angle = glutGet(GLUT_ELAPSED_TIME) / 100.0; if(opt_highres) { xres = xsz; @@ -198,11 +206,15 @@ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(0, 0, -cam_dist); + glTranslatef(0, 0.8, -cam_dist); glRotatef(cam_phi, 1, 0, 0); - glRotatef(cam_theta, 0, 1, 0); + glRotatef(opt_autorot ? auto_angle : cam_theta, 0, 1, 0); glLightfv(GL_LIGHT0, GL_POSITION, ldir); + glLightfv(GL_LIGHT0, GL_DIFFUSE, lcol); + + glLightfv(GL_LIGHT1, GL_POSITION, ldir2); + glLightfv(GL_LIGHT1, GL_DIFFUSE, lcol2); const float blue[] = {0.4, 0.45, 1.0, 1}; const float white[] = {1, 1, 1, 1}; @@ -298,6 +310,10 @@ case 27: exit(0); + case 'a': + opt_autorot = !opt_autorot; + break; + case 'f': { static bool fullscreen;