tesspot

view sdr/bezier.p.glsl @ 2:178a9e3c3c8c

isolines
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Dec 2012 07:30:39 +0200
parents 72b7f9f2eead
children
line source
1 #version 410 compatibility
3 uniform int tess_level;
5 in vec3 normal;
6 in vec3 vpos;
7 in vec2 uv;
10 void main()
11 {
12 vec3 ldir = gl_LightSource[0].position.xyz - vpos;
14 vec3 n = normalize(normal);
15 vec3 v = -normalize(vpos);
16 vec3 l = normalize(ldir);
17 vec3 h = normalize(l + v);
19 float ndotl = max(dot(n, l), 0.0);
20 float ndoth = max(dot(n, h), 0.0);
22 vec3 ka = gl_FrontMaterial.ambient.xyz;
23 vec3 kd = gl_FrontMaterial.diffuse.xyz;
24 vec3 ks = gl_FrontMaterial.specular.xyz;
25 float shin = gl_FrontMaterial.shininess;
27 vec3 diffuse = kd * ndotl * gl_LightSource[0].diffuse.xyz;
28 vec3 specular = ks * pow(ndoth, shin) * gl_LightSource[0].specular.xyz;
29 vec3 ambient = ka * gl_LightModel.ambient.xyz;
30 vec3 color = ambient + diffuse + specular;
32 vec2 tess_uv = mod(uv * float(tess_level), 1.0);
34 #define STEPSZ 0.1
35 float wire = smoothstep(0.0, STEPSZ, tess_uv.x) * smoothstep(1.0, 1.0 - STEPSZ, tess_uv.x);
36 wire *= smoothstep(0.0, STEPSZ, tess_uv.y) * smoothstep(1.0, 1.0 - STEPSZ, tess_uv.y);
38 gl_FragColor = vec4(mix(vec3(0.0, 0.0, 0.0), color, wire), gl_FrontMaterial.diffuse.w);
39 }