def data_eval(cfg): cfg.aspect_ratio = (1, 1) # Entangled dependencies between evals t = ngl.Time() a = ngl.UniformFloat(0.7) b = ngl.UniformFloat(0.3) x = ngl.EvalFloat("sin(a - b + t*4)") x.update_resources(t=t, a=a, b=b) color = ngl.EvalVec4( expr0="sat(sin(x + t*4)/2 + wiggle/3)", expr1="abs(fract(sin(t + a)))", expr2=None, # re-use expr1 expr3="1", ) color.update_resources(wiggle=ngl.NoiseFloat(), t=t, a=a, x=x) vert = textwrap.dedent("""\ void main() { ngl_out_pos = ngl_projection_matrix * ngl_modelview_matrix * vec4(ngl_position, 1.0); } """) frag = textwrap.dedent("""\ void main() { ngl_out_color = color; } """) program = ngl.Program(vertex=vert, fragment=frag) geometry = ngl.Quad(corner=(-1, -1, 0), width=(2, 0, 0), height=(0, 2, 0)) render = ngl.Render(geometry, program) render.update_frag_resources(color=color) return render
def py_bindings_allow_node(): c = ngl.Camera(eye=(0, 1, 0)) assert c.set_eye(ngl.EvalVec3()) == 0 assert c.set_eye(1, 0, 0) == 0 c = ngl.Camera(eye=ngl.NoiseVec3()) assert c.set_eye(1, 0, 0) == 0 assert c.set_eye(ngl.UniformVec3()) == 0 r = ngl.Rotate(angle=30) assert r.set_angle(ngl.NoiseFloat()) == 0 assert r.set_angle(-45) == 0 r = ngl.Rotate(angle=ngl.EvalFloat()) assert r.set_angle(90) == 0 assert r.set_angle(ngl.UniformFloat()) == 0
def data_noise_time(cfg): cfg.aspect_ratio = (1, 1) cfg.duration = 2 vert = ''' void main() { ngl_out_pos = ngl_projection_matrix * ngl_modelview_matrix * ngl_position; ngl_out_pos += vec4(t - 1., signal, 0.0, 0.0); } ''' frag = ''' void main() { ngl_out_color = color; } ''' geometry = ngl.Circle(radius=0.25, npoints=6) program = ngl.Program(vertex=vert, fragment=frag) render = ngl.Render(geometry, program) render.update_vert_resources(t=ngl.Time(), signal=ngl.NoiseFloat(octaves=8)) render.update_frag_resources(color=ngl.UniformVec4(value=COLORS['white'])) return render
def smptebars_glitch(cfg): """SMPTE bars glitching at irregular intervals""" cfg.duration = 15 cfg.aspect_ratio = (4, 3) quad = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0)) program = ngl.Program(vertex=cfg.get_vert("smptebars"), fragment=cfg.get_frag("smptebars")) program.update_vert_out_vars(var_uvcoord=ngl.IOVec2()) render = ngl.Render(quad, program) freq = cfg.framerate[0] / cfg.framerate[1] + 1 render.update_frag_resources( active_noise=ngl.NoiseFloat(octaves=1), active_probability=ngl.UniformFloat(0.4), # glitch 40% of the time uv_noise_0=ngl.NoiseVec2(amplitude=0.05, frequency=freq, seed=1000 + 0), uv_noise_1=ngl.NoiseVec2(amplitude=0.05, frequency=freq, seed=1000 + 0x7FFF), uv_noise_2=ngl.NoiseVec2(amplitude=0.05, frequency=freq, seed=1000 + 0xFFFF), ) return render