float del = 0.1; float q = smoothstep(0.8, 1., fract(l/del)); vec4 range = mix(vec4(0, 1, 0, 0), vec4(1, 0, 0.5, 0), l*0.4)*2.; c +=range*q; #endif c += 0.75*vec4(1.0, 0.6, 0.2, 1.)*exp(-1./abs(l+0.1))*2.; c *= smoothstep(0., 1.,l)+0.2; gl_FragColor = c; } ''' program = gloo.Program(vertex, fragment, count=4) program['a_position'] = [(-1., -1.), (-1., +1.), (+1., -1.), (+1., +1.)] program['iChannel0'] = data.checkerboard() program['iGlobalTime'] = 0.0 window = app.Window(width=900, height=900) @window.event def on_draw(dt): window.clear() program.draw(gl.GL_TRIANGLE_STRIP) program['iGlobalTime'] += dt @window.event def on_resize(width, height): gl.glViewport(0, 0, width, height)
window = app.Window(width=1024, height=1024, color=(.75, .75, .75, 1)) @window.event def on_draw(dt): window.clear() teapot.draw(gl.GL_TRIANGLES, indices) @window.event def on_init(): gl.glEnable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) vertices, indices = primitives.teapot() vertices["position"] *= 10 teapot = gloo.Program(teapot_vert, teapot_frag) teapot.bind(vertices) teapot['texture'] = data.checkerboard() trackball = Trackball(Position("position"), znear=0.1, zfar=100.0, distance=50) teapot['transform'] = trackball trackball.theta = 40 trackball.phi = 135 trackball.zoom = 40 window.attach(teapot['transform']) app.run()
shapes = [ primitives.plane(1.5), primitives.cube(1.5), primitives.sphere(), primitives.cubesphere(), primitives.cylinder(), primitives.torus(), primitives.cone(), primitives.pyramid(), primitives.teapot() ] vertices, indices = shapes[index] program = gloo.Program(vertex, fragment) program.bind(vertices) view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) glm.translate(view, 0, 0, -5) program['model'] = model program['view'] = view program['normal'] = np.array(np.matrix(np.dot(view, model)).I.T) program['texture'] = data.checkerboard() program["light1_position"] = 3, 0, 0+5 program["light2_position"] = 0, 3, 0+5 program["light3_position"] = -3, -3, +5 program["light1_color"] = 1, 0, 0 program["light2_color"] = 0, 1, 0 program["light3_color"] = 0, 0, 1 phi, theta = 0, 0 app.run()
b_indices = np.array(I, dtype=np.uint32).view(gloo.IndexBuffer) def func3(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2) x = np.linspace(-2.0, 2.0, 32).astype(np.float32) y = np.linspace(-2.0, 2.0, 32).astype(np.float32) X,Y = np.meshgrid(x, y) Z = func3(X,Y) surface['data'] = (Z-Z.min())/(Z.max() - Z.min()) surface['data'].interpolation = gl.GL_NEAREST surface['data_shape'] = Z.shape[1], Z.shape[0] surface['u_kernel'] = data.get("spatial-filters.npy") surface['u_kernel'].interpolation = gl.GL_LINEAR surface['texture'] = data.checkerboard(32,24) transform = Trackball("vec4(position.xy, z, 1.0)") surface['transform'] = transform window.attach(transform) T = (Z-Z.min())/(Z.max() - Z.min()) surface['height'] = 0.75 surface["light_position[0]"] = 3, 0, 0+5 surface["light_position[1]"] = 0, 3, 0+5 surface["light_position[2]"] = -3, -3, +5 surface["light_color[0]"] = 1, 0, 0 surface["light_color[1]"] = 0, 1, 0 surface["light_color[2]"] = 0, 0, 1 phi, theta = -45, 0
def func3(x, y): return (1 - x / 2 + x**5 + y**3) * np.exp(-x**2 - y**2) x = np.linspace(-2.0, 2.0, 32).astype(np.float32) y = np.linspace(-2.0, 2.0, 32).astype(np.float32) X, Y = np.meshgrid(x, y) Z = func3(X, Y) surface['data'] = (Z - Z.min()) / (Z.max() - Z.min()) surface['data'].interpolation = gl.GL_NEAREST surface['data_shape'] = Z.shape[1], Z.shape[0] surface['u_kernel'] = data.get("spatial-filters.npy") surface['u_kernel'].interpolation = gl.GL_LINEAR surface['texture'] = data.checkerboard(32, 24) transform = Trackball("vec4(position.xy, z, 1.0)") surface['transform'] = transform window.attach(transform) T = (Z - Z.min()) / (Z.max() - Z.min()) surface['height'] = 0.75 surface["light_position[0]"] = 3, 0, 0 + 5 surface["light_position[1]"] = 0, 3, 0 + 5 surface["light_position[2]"] = -3, -3, +5 surface["light_color[0]"] = 1, 0, 0 surface["light_color[1]"] = 0, 1, 0 surface["light_color[2]"] = 0, 0, 1 phi, theta = -45, 0
phi += 0.5 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['model'] = model @window.event def on_resize(width, height): gl.glViewport(0, 0, width, height) cube['projection'] = glm.perspective(45.0, width / float(height), 2.0, 100.0) pixelate.viewport = 0, 0, width, height @window.event def on_mouse_scroll(x, y, dx, dy): p = compose["level"] compose["level"] = min(max(8, p + .01 * dy * p), 512) # Build cube data vertices, faces = primitives.cube() cube = gloo.Program(vertex, fragment) cube.bind(vertices) view = np.eye(4, dtype=np.float32) glm.translate(view, 0, 0, -3) cube['view'] = view cube['model'] = np.eye(4, dtype=np.float32) cube['texture'] = data.checkerboard() phi, theta = 0, 0 app.run()
gl.glBlendFunc(gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_SRC_ALPHA) gl.glEnable(gl.GL_BLEND) post_process.draw(gl.GL_TRIANGLE_STRIP) accumulation = np.zeros((window.height,window.width,4),np.float32).view(gloo.TextureFloat2D) revealage = np.zeros((window.height,window.width),np.float32).view(gloo.TextureFloat2D) framebuffer = gloo.FrameBuffer(color=[accumulation,revealage]) vertices, indices = primitives.teapot() vertices["position"] *= 10 teapot = gloo.Program(teapot_vert, teapot_frag) teapot.bind(vertices) teapot['texture'] = data.checkerboard() # Post composition post_process = gloo.Program(post_process_vert, post_process_frag) post_process['tex_accumulation'] = accumulation post_process['tex_revealage'] = revealage post_process['position'] = [(-1,-1), (-1,1), (1,-1), (1,1)] trackball = Trackball(Position("position"), znear=0.1, zfar=100.0, distance=50) teapot['transform'] = trackball trackball.theta = 40 trackball.phi = 45 trackball.zoom = 40 window.attach(teapot['transform']) app.run()
model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube["model"] = model @window.event def on_resize(width, height): gl.glViewport(0, 0, width, height) cube["projection"] = glm.perspective(45.0, width / float(height), 2.0, 100.0) pixelate.viewport = 0, 0, width, height @window.event def on_mouse_scroll(x, y, dx, dy): p = compose["level"] compose["level"] = min(max(8, p + 0.01 * dy * p), 512) # Build cube data vertices, faces = primitives.cube() cube = gloo.Program(vertex, fragment) cube.bind(vertices) view = np.eye(4, dtype=np.float32) glm.translate(view, 0, 0, -3) cube["view"] = view cube["model"] = np.eye(4, dtype=np.float32) cube["texture"] = data.checkerboard() phi, theta = 0, 0 app.run()
else: writer.close() writer = None # Make cube rotate theta += 0.5 # degrees phi += 0.5 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['model'] = model @window.event def on_resize(width, height): cube['projection'] = glm.perspective(45.0, width / float(height), 2.0, 100.0) vertices, faces = primitives.cube() cube = gloo.Program(vertex, fragment) cube.bind(vertices) view = np.eye(4, dtype=np.float32) glm.translate(view, 0, 0, -3) cube['view'] = view cube['model'] = np.eye(4, dtype=np.float32) cube['texture'] = data.checkerboard() phi, theta = 0, 0 app.run(framerate=framerate)
else: x = 3 * cos(u) * (1 + sin(u)) + (2 * (1 - cos(u) / 2)) * cos(v + pi) z = -8 * sin(u) y = -2 * (1 - cos(u) / 2) * sin(v) return x/5, y/5, z/5 vertices, indices = surface(klein, urepeat=3) program = gloo.Program(vertex, fragment) program.bind(vertices) view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) glm.translate(view, 0, 0, -5) program['model'] = model program['view'] = view program['normal'] = np.array(np.matrix(np.dot(view, model)).I.T) program['texture'] = data.checkerboard() program['texture'].wrapping = gl.GL_REPEAT program["light1_position"] = 3, 0, 0+5 program["light2_position"] = 0, 3, 0+5 program["light3_position"] = -3, -3, +5 program["light1_color"] = 1, 0, 0 program["light2_color"] = 0, 1, 0 program["light3_color"] = 0, 0, 1 phi, theta = 0, 0 app.run()
float q = smoothstep(0.8, 1., fract(l/del)); vec4 range = mix(vec4(0, 1, 0, 0), vec4(1, 0, 0.5, 0), l*0.4)*2.; c +=range*q; #endif c += 0.75*vec4(1.0, 0.6, 0.2, 1.)*exp(-1./abs(l+0.1))*2.; c *= smoothstep(0., 1.,l)+0.2; gl_FragColor = c; } ''' program = gloo.Program(vertex, fragment, count=4) program['a_position'] = [(-1., -1.), (-1., +1.), (+1., -1.), (+1., +1.)] program['iChannel0'] = data.checkerboard() program['iGlobalTime'] = 0.0 window = app.Window(width=900, height=900) @window.event def on_draw(dt): window.clear() program.draw(gl.GL_TRIANGLE_STRIP) program['iGlobalTime'] += dt @window.event def on_resize(width, height): gl.glViewport(0, 0, width, height)