varying vec3 lightvec; varying vec4 color; void main(void) { vec3 N = normalize(normal); /* Calculate the lighting */ float intensity = max(0.0, dot(N, normalize(lightvec))); float glare = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz))); vec4 ambient = gl_LightSource[0].ambient; vec4 diffuse = gl_LightSource[0].diffuse * intensity; vec4 specular = gl_LightSource[0].specular * pow(glare, 128.0); gl_FragColor = (ambient + diffuse + specular) * color; } ''') smooth_prog = shader.ShaderProgram(vert_shader, smooth_frag_shader) simple_bump_frag_shader = shader.FragmentShader('simple_bump', shader_noise_glsl + ''' /* Simple normal mapper using perlin noise */ uniform float height; varying vec3 position; varying vec3 normal; varying vec3 lightvec; varying vec4 color; void main(void) { const float offset = 0.05; // offset for computing surface derivative /* Calculate the normal resulting from the bump surface */ float h = pnoise(position);
h = h*h*h*h * 0.15; if (h > 0.0) { /* Calculate the lighting */ vec3 N = normalize(normal); float intensity = max(0.0, dot(N, normalize(lightvec))); float glare = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz))); vec4 ambient = gl_LightSource[0].ambient; vec4 diffuse = gl_LightSource[0].diffuse * intensity; vec4 specular = gl_LightSource[0].specular * pow(glare, 64.0); gl_FragColor = (ambient + diffuse + specular) * color * h; } else { discard; } } ''') atmosphere_prog = shader.ShaderProgram(vert_shader, atmosphere_frag_shader) atmosphere_prog.install() atmosphere_prog.uset1F('scale', 0.3) if __name__ == '__main__': import sys global xrot, yrot, d win = pyglet.window.Window(width=640, height=640, resizable=True, visible=False, config=pyglet.gl.Config(sample_buffers=1, samples=4, double_buffer=True, depth_size=24))