tesspot
changeset 2:178a9e3c3c8c tip
isolines
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 03 Dec 2012 07:30:39 +0200 |
parents | befe01bbd27f |
children | |
files | Makefile sdr/bezier.p.glsl sdr/bezier.te.glsl src/test.c |
diffstat | 4 files changed, 31 insertions(+), 6 deletions(-) [+] |
line diff
1.1 --- a/Makefile Sun Dec 02 17:16:32 2012 +0200 1.2 +++ b/Makefile Mon Dec 03 07:30:39 2012 +0200 1.3 @@ -2,7 +2,7 @@ 1.4 obj = $(src:.c=.o) 1.5 bin = test 1.6 1.7 -CFLAGS = -pedantic -Wall -g 1.8 +CFLAGS = -pedantic -Wall -g -O3 -ffast-math 1.9 LDFLAGS = $(libgl) 1.10 1.11 ifeq ($(shell uname -s), Darwin)
2.1 --- a/sdr/bezier.p.glsl Sun Dec 02 17:16:32 2012 +0200 2.2 +++ b/sdr/bezier.p.glsl Mon Dec 03 07:30:39 2012 +0200 2.3 @@ -1,7 +1,11 @@ 2.4 #version 410 compatibility 2.5 2.6 +uniform int tess_level; 2.7 + 2.8 in vec3 normal; 2.9 in vec3 vpos; 2.10 +in vec2 uv; 2.11 + 2.12 2.13 void main() 2.14 { 2.15 @@ -15,12 +19,21 @@ 2.16 float ndotl = max(dot(n, l), 0.0); 2.17 float ndoth = max(dot(n, h), 0.0); 2.18 2.19 + vec3 ka = gl_FrontMaterial.ambient.xyz; 2.20 vec3 kd = gl_FrontMaterial.diffuse.xyz; 2.21 vec3 ks = gl_FrontMaterial.specular.xyz; 2.22 float shin = gl_FrontMaterial.shininess; 2.23 2.24 vec3 diffuse = kd * ndotl * gl_LightSource[0].diffuse.xyz; 2.25 vec3 specular = ks * pow(ndoth, shin) * gl_LightSource[0].specular.xyz; 2.26 + vec3 ambient = ka * gl_LightModel.ambient.xyz; 2.27 + vec3 color = ambient + diffuse + specular; 2.28 2.29 - gl_FragColor = vec4(diffuse + specular, gl_FrontMaterial.diffuse.w); 2.30 + vec2 tess_uv = mod(uv * float(tess_level), 1.0); 2.31 + 2.32 +#define STEPSZ 0.1 2.33 + float wire = smoothstep(0.0, STEPSZ, tess_uv.x) * smoothstep(1.0, 1.0 - STEPSZ, tess_uv.x); 2.34 + wire *= smoothstep(0.0, STEPSZ, tess_uv.y) * smoothstep(1.0, 1.0 - STEPSZ, tess_uv.y); 2.35 + 2.36 + gl_FragColor = vec4(mix(vec3(0.0, 0.0, 0.0), color, wire), gl_FrontMaterial.diffuse.w); 2.37 }
3.1 --- a/sdr/bezier.te.glsl Sun Dec 02 17:16:32 2012 +0200 3.2 +++ b/sdr/bezier.te.glsl Mon Dec 03 07:30:39 2012 +0200 3.3 @@ -4,6 +4,7 @@ 3.4 3.5 out vec3 normal; 3.6 out vec3 vpos; 3.7 +out vec2 uv; 3.8 3.9 uniform vec3 norm_scale; 3.10 3.11 @@ -16,6 +17,8 @@ 3.12 vec3 pos = bezier_patch(gl_TessCoord.x, gl_TessCoord.y); 3.13 normal = gl_NormalMatrix * bezier_patch_norm(gl_TessCoord.x, gl_TessCoord.y); 3.14 3.15 + uv = gl_TessCoord.xy; 3.16 + 3.17 gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0); 3.18 vpos = (gl_ModelViewMatrix * vec4(pos, 1.0)).xyz; 3.19 }
4.1 --- a/src/test.c Sun Dec 02 17:16:32 2012 +0200 4.2 +++ b/src/test.c Mon Dec 03 07:30:39 2012 +0200 4.3 @@ -7,7 +7,7 @@ 4.4 #include "teapot_data.h" 4.5 4.6 void disp(void); 4.7 -void draw_teapot(void); 4.8 +void draw_teapot(float scale); 4.9 void draw_teapot_patch(struct vec3 *bez_cp, int *index, int flip, float rot); 4.10 void set_material(float dr, float dg, float db, float sr, float sg, float sb, float shin); 4.11 void reshape(int x, int y); 4.12 @@ -25,6 +25,8 @@ 4.13 4.14 int main(int argc, char **argv) 4.15 { 4.16 + float amb[] = {0.05, 0.05, 0.05, 0.0}; 4.17 + 4.18 glutInit(&argc, argv); 4.19 glutInitWindowSize(1280, 800); 4.20 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 4.21 @@ -35,10 +37,12 @@ 4.22 glutKeyboardFunc(keyb); 4.23 glutMouseFunc(mouse); 4.24 glutMotionFunc(motion); 4.25 + glutIdleFunc(glutPostRedisplay); 4.26 4.27 glewInit(); 4.28 4.29 - glClearColor(0.07, 0.07, 0.07, 1); 4.30 + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb); 4.31 + glClearColor(amb[0], amb[1], amb[2], 1); 4.32 4.33 glEnable(GL_CULL_FACE); 4.34 glEnable(GL_DEPTH_TEST); 4.35 @@ -51,6 +55,7 @@ 4.36 printf("maximum tesselation levels: %d\n", max_tess_level); 4.37 4.38 glPatchParameteri(GL_PATCH_VERTICES, 16); 4.39 + glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); 4.40 4.41 { 4.42 unsigned int vsdr, tcsdr, tesdr, psdr; 4.43 @@ -94,17 +99,21 @@ 4.44 4.45 set_material(0.2, 0.35, 1.0, 1.0, 1.0, 1.0, 60.0); 4.46 4.47 - draw_teapot(); 4.48 + draw_teapot(2.0); 4.49 4.50 glutSwapBuffers(); 4.51 } 4.52 4.53 -void draw_teapot(void) 4.54 +void draw_teapot(float scale) 4.55 { 4.56 int i; 4.57 4.58 + scale /= 2.0; 4.59 + 4.60 glPushMatrix(); 4.61 + glTranslatef(0, -3.15 * scale * 0.5, 0); 4.62 glRotatef(-90.0, 1, 0, 0); 4.63 + glScalef(scale, scale, scale); 4.64 4.65 glUseProgram(prog); 4.66 set_uniform_int(prog, "tess_level", tess_level);