dbf-udg
changeset 7:603656331514
phong blobs
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 18 Feb 2013 05:44:17 +0200 |
parents | 57ea4988a9f2 |
children | f0a47f46ee45 |
files | sdr/phong.p.glsl sdr/phong.v.glsl src/udg.cc |
diffstat | 3 files changed, 44 insertions(+), 7 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/sdr/phong.p.glsl Mon Feb 18 05:44:17 2013 +0200 1.3 @@ -0,0 +1,21 @@ 1.4 +varying vec3 normal, vpos; 1.5 + 1.6 +void main() 1.7 +{ 1.8 + vec3 n = normalize(normal); 1.9 + vec3 v = -normalize(vpos); 1.10 + vec3 l = normalize(gl_LightSource[0].position.xyz); 1.11 + 1.12 + vec3 h = normalize(v + l); 1.13 + 1.14 + float ndotl = max(dot(n, l), 0.0); 1.15 + float ndoth = max(dot(n, h), 0.0); 1.16 + float spec = pow(ndoth, gl_FrontMaterial.shininess); 1.17 + 1.18 + vec3 acol = gl_FrontMaterial.ambient.xyz * gl_LightModel.ambient.xyz; 1.19 + vec3 dcol = gl_FrontMaterial.diffuse.xyz * gl_LightSource[0].diffuse.xyz; 1.20 + vec3 scol = gl_FrontMaterial.specular.xyz * gl_LightSource[0].specular.xyz; 1.21 + 1.22 + gl_FragColor.xyz = acol + dcol * ndotl + scol * spec; 1.23 + gl_FragColor.w = 1.0; 1.24 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/sdr/phong.v.glsl Mon Feb 18 05:44:17 2013 +0200 2.3 @@ -0,0 +1,10 @@ 2.4 +varying vec3 normal, vpos; 2.5 + 2.6 +void main() 2.7 +{ 2.8 + gl_Position = ftransform(); 2.9 + vpos = (gl_ModelViewMatrix * gl_Vertex).xyz; 2.10 + normal = gl_NormalMatrix * gl_Normal; 2.11 + 2.12 + gl_TexCoord[0] = gl_MultiTexCoord0; 2.13 +}
3.1 --- a/src/udg.cc Mon Feb 18 04:41:26 2013 +0200 3.2 +++ b/src/udg.cc Mon Feb 18 05:44:17 2013 +0200 3.3 @@ -39,7 +39,7 @@ 3.4 float cam_theta, cam_phi = 25, cam_dist = 9; 3.5 unsigned int dither_tex; 3.6 struct render_target *rtarg; 3.7 -unsigned int prog; 3.8 +unsigned int post_prog, phong_prog; 3.9 3.10 int opt_highres, opt_regular_render; 3.11 3.12 @@ -102,7 +102,11 @@ 3.13 fclose(fp); 3.14 } 3.15 3.16 - if(!(prog = create_program_load("sdr/dither.v.glsl", "sdr/dither.p.glsl"))) { 3.17 + if(!(phong_prog = create_program_load("sdr/phong.v.glsl", "sdr/phong.p.glsl"))) { 3.18 + return false; 3.19 + } 3.20 + 3.21 + if(!(post_prog = create_program_load("sdr/dither.v.glsl", "sdr/dither.p.glsl"))) { 3.22 return false; 3.23 } 3.24 3.25 @@ -206,7 +210,9 @@ 3.26 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white); 3.27 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80.0); 3.28 3.29 + bind_program(phong_prog); 3.30 mball_render(); 3.31 + bind_program(0); 3.32 3.33 3.34 if(!opt_regular_render) { 3.35 @@ -225,11 +231,11 @@ 3.36 glPushAttrib(GL_ENABLE_BIT); 3.37 glDisable(GL_DEPTH_TEST); 3.38 3.39 - bind_program(prog); 3.40 - set_uniform_int(prog, "framebuf", 0); 3.41 - set_uniform_int(prog, "dither_tex", 1); 3.42 - set_uniform_int(prog, "dither_levels", DITHER_LEVELS); 3.43 - set_uniform_int(prog, "dither_size", DITHER_SZ); 3.44 + bind_program(post_prog); 3.45 + set_uniform_int(post_prog, "framebuf", 0); 3.46 + set_uniform_int(post_prog, "dither_tex", 1); 3.47 + set_uniform_int(post_prog, "dither_levels", DITHER_LEVELS); 3.48 + set_uniform_int(post_prog, "dither_size", DITHER_SZ); 3.49 3.50 glActiveTextureARB(GL_TEXTURE0); 3.51 glBindTexture(GL_TEXTURE_2D, rtarg->color_tex);