Esempio n. 1
0
def data_mat_iovars(cfg):
    cfg.aspect_ratio = (1, 1)
    vert = textwrap.dedent("""\
        void main()
        {
            ngl_out_pos = ngl_projection_matrix * ngl_modelview_matrix * vec4(ngl_position, 1.0);
            var_mat3 = mat3(1.0);
            var_mat4 = mat4(1.0);
            var_vec4 = vec4(1.0, 0.5, 0.0, 1.0);
        }
        """)
    frag = textwrap.dedent("""\
        void main()
        {
            ngl_out_color = mat4(var_mat3) * var_mat4 * var_vec4;
        }
        """)
    program = ngl.Program(vertex=vert, fragment=frag)
    program.update_vert_out_vars(
        var_mat3=ngl.IOMat3(),
        var_mat4=ngl.IOMat4(),
        var_vec4=ngl.IOVec4(),
    )
    geometry = ngl.Quad(corner=(-1, -1, 0), width=(2, 0, 0), height=(0, 2, 0))
    render = ngl.Render(geometry, program)
    return render
Esempio n. 2
0
def triangle(cfg, size=0.5):
    '''Rotating triangle with edge coloring specified in a vertex attribute'''
    b = size * math.sqrt(3) / 2.0
    c = size * 1 / 2.
    cfg.duration = 3.
    cfg.aspect_ratio = (1, 1)

    colors_data = array.array(
        'f', [0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0])
    colors_buffer = ngl.BufferVec4(data=colors_data)

    triangle = ngl.Triangle((-b, -c, 0), (b, -c, 0), (0, size, 0))
    p = ngl.Program(fragment=cfg.get_frag('color'),
                    vertex=cfg.get_vert('triangle'))
    p.update_vert_out_vars(color=ngl.IOVec4())
    node = ngl.Render(triangle, p)
    node.update_attributes(edge_color=colors_buffer)
    animkf = [
        ngl.AnimKeyFrameFloat(0, 0),
        ngl.AnimKeyFrameFloat(cfg.duration / 3., -360 / 3., 'exp_in_out'),
        ngl.AnimKeyFrameFloat(2 * cfg.duration / 3., -2 * 360 / 3.,
                              'exp_in_out'),
        ngl.AnimKeyFrameFloat(cfg.duration, -360, 'exp_in_out')
    ]
    node = ngl.Rotate(node, anim=ngl.AnimatedFloat(animkf))
    return node
Esempio n. 3
0
def _data_vertex_and_fragment_blocks(cfg, layout):
    """
    This test ensures that the block bindings are properly set by pgcraft
    when UBOs or SSBOs are bound to different stages.
    """
    cfg.aspect_ratio = (1, 1)

    src = ngl.Block(
        fields=[
            ngl.UniformVec3(value=COLORS.red, label="color"),
            ngl.UniformFloat(value=0.5, label="opacity"),
        ],
        layout="std140",
    )
    dst = ngl.Block(
        fields=[
            ngl.UniformVec3(value=COLORS.white, label="color"),
        ],
        layout=layout,
    )
    vert = textwrap.dedent("""\
        void main()
        {
            ngl_out_pos = ngl_projection_matrix * ngl_modelview_matrix * vec4(ngl_position, 1.0);
            var_src = vec4(src.color, 1.0) * src.opacity;
        }
        """)
    frag = textwrap.dedent("""\
        void main()
        {
            vec3 color = var_src.rgb + (1.0 - var_src.a) * dst.color;
            ngl_out_color = vec4(color, 1.0);
        }
        """)

    program = ngl.Program(vertex=vert, fragment=frag)
    program.update_vert_out_vars(var_src=ngl.IOVec4(), )
    geometry = ngl.Quad(corner=(-1, -1, 0), width=(2, 0, 0), height=(0, 2, 0))
    render = ngl.Render(geometry, program)
    render.update_vert_resources(src=src)
    render.update_frag_resources(dst=dst)

    return render
Esempio n. 4
0
def shape_precision_iovar(cfg):
    cfg.aspect_ratio = (1, 1)
    vert = textwrap.dedent("""\
        void main()
        {
            ngl_out_pos = ngl_projection_matrix * ngl_modelview_matrix * vec4(ngl_position, 1.0);
            color = vec4((ngl_out_pos.xy + 1.0) * .5, 1.0 - (ngl_out_pos.x + 1.0) * .5 - (ngl_out_pos.y + 1.0) * .5, 1.0);
        }
        """)
    frag = textwrap.dedent("""\
        void main()
        {
            ngl_out_color = color;
        }
        """)
    program = ngl.Program(vertex=vert, fragment=frag)
    program.update_vert_out_vars(
        color=ngl.IOVec4(precision_out="high", precision_in="low"))
    geometry = ngl.Quad(corner=(-1, -1, 0), width=(2, 0, 0), height=(0, 2, 0))
    scene = ngl.Render(geometry, program)
    return scene