# HG changeset patch # User John Tsiombikas # Date 1361159057 -7200 # Node ID 6036563315149eeb33831f0f4a0a4ec213f49540 # Parent 57ea4988a9f2322330436b46ef6d8c098b8b9b66 phong blobs diff -r 57ea4988a9f2 -r 603656331514 sdr/phong.p.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sdr/phong.p.glsl Mon Feb 18 05:44:17 2013 +0200 @@ -0,0 +1,21 @@ +varying vec3 normal, vpos; + +void main() +{ + vec3 n = normalize(normal); + vec3 v = -normalize(vpos); + vec3 l = normalize(gl_LightSource[0].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 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.w = 1.0; +} diff -r 57ea4988a9f2 -r 603656331514 sdr/phong.v.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sdr/phong.v.glsl Mon Feb 18 05:44:17 2013 +0200 @@ -0,0 +1,10 @@ +varying vec3 normal, vpos; + +void main() +{ + gl_Position = ftransform(); + vpos = (gl_ModelViewMatrix * gl_Vertex).xyz; + normal = gl_NormalMatrix * gl_Normal; + + gl_TexCoord[0] = gl_MultiTexCoord0; +} diff -r 57ea4988a9f2 -r 603656331514 src/udg.cc --- a/src/udg.cc Mon Feb 18 04:41:26 2013 +0200 +++ b/src/udg.cc Mon Feb 18 05:44:17 2013 +0200 @@ -39,7 +39,7 @@ float cam_theta, cam_phi = 25, cam_dist = 9; unsigned int dither_tex; struct render_target *rtarg; -unsigned int prog; +unsigned int post_prog, phong_prog; int opt_highres, opt_regular_render; @@ -102,7 +102,11 @@ fclose(fp); } - if(!(prog = create_program_load("sdr/dither.v.glsl", "sdr/dither.p.glsl"))) { + if(!(phong_prog = create_program_load("sdr/phong.v.glsl", "sdr/phong.p.glsl"))) { + return false; + } + + if(!(post_prog = create_program_load("sdr/dither.v.glsl", "sdr/dither.p.glsl"))) { return false; } @@ -206,7 +210,9 @@ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80.0); + bind_program(phong_prog); mball_render(); + bind_program(0); if(!opt_regular_render) { @@ -225,11 +231,11 @@ glPushAttrib(GL_ENABLE_BIT); glDisable(GL_DEPTH_TEST); - bind_program(prog); - set_uniform_int(prog, "framebuf", 0); - set_uniform_int(prog, "dither_tex", 1); - set_uniform_int(prog, "dither_levels", DITHER_LEVELS); - set_uniform_int(prog, "dither_size", DITHER_SZ); + bind_program(post_prog); + set_uniform_int(post_prog, "framebuf", 0); + set_uniform_int(post_prog, "dither_tex", 1); + set_uniform_int(post_prog, "dither_levels", DITHER_LEVELS); + set_uniform_int(post_prog, "dither_size", DITHER_SZ); glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, rtarg->color_tex);