Beispiel #1
0
def test_simple_camera():
    camera = glnext.camera((4.0, 3.0, 2.0), (0.0, 0.0, 0.0), fov=60.0)
    assert type(camera) is bytes
    assert len(camera) == 64

    array = np.ndarray((4, 4), 'f4', camera)
    expected = [
        [-1.0392, -0.5146, -0.7428, -0.7427],
        [1.3856, -0.3859, -0.5571, -0.5570],
        [0.0000, 1.6081, -0.3714, -0.3713],
        [0.0000, 0.0000, 5.2856, 5.3851],
    ]
    np.testing.assert_array_almost_equal(array, expected, decimal=2)
Beispiel #2
0
def test_ortho_camera():
    camera = glnext.camera((4.0, 3.0, 2.0), (0.0, 0.0, 0.0), fov=0.0)
    assert type(camera) is bytes
    assert len(camera) == 64

    array = np.ndarray((4, 4), 'f4', camera)
    expected = [
        [-0.6000, -0.2971, -0.0007, 0.0000],
        [0.8000, -0.2228, -0.0005, 0.0000],
        [0.0000, 0.9284, -0.0003, 0.0000],
        [0.0000, 0.0000, 0.0052, 1.0000],
    ]
    np.testing.assert_array_almost_equal(array, expected, decimal=2)
Beispiel #3
0
    '''),
    vertex_format='3f',
    vertex_count=vertex_count,
    bindings=[
        {
            'binding': 0,
            'name': 'uniform_buffer',
            'type': 'uniform_buffer',
            'size': 64,
        },
    ],
)

framebuffer.update(
    clear_values=glnext.pack([1.0, 0.0, 0.0, 0.0]),
    clear_depth=1.0,
)

pipeline.update(
    uniform_buffer=glnext.camera((4.0, 3.0, 2.0), (0.0, 0.0, 0.0),
                                 near=1.0,
                                 far=7.0),
    vertex_buffer=mesh,
)

task.run()
data = framebuffer.output[0].read()
array = np.ndarray((512, 512), 'f4', data)[::-1]
plt.imshow(array, 'YlGnBu', vmin=0.8, vmax=1.0)
plt.show()
Beispiel #4
0
        layout (location = 0) out vec4 out_color;

        void main() {
            vec3 color = vec3(1.0, 1.0, 1.0);
            vec3 sight = -vec3(mvp[0].w, mvp[1].w, mvp[2].w);
            float lum = dot(normalize(sight), normalize(in_norm)) * 0.7 + 0.3;
            out_color = vec4(lum, lum, lum, 1.0);
        }
    '''),
    vertex_format='3f 3f',
    vertex_count=36,
    bindings=[
        {
            'binding': 0,
            'type': 'uniform_buffer',
            'buffer': uniform_buffer,
        },
    ],
)

uniform_buffer.write(glnext.camera((4.0, 3.0, 2.0), (0.0, 0.0, 0.0)))

pipeline.update(
    vertex_buffer=Obj.open('examples/cube.obj').pack('vx vy vz nx ny nz'),
)

task.run()
data = framebuffer.output[0].read()
Image.frombuffer('RGBA', (512, 512), data, 'raw', 'RGBA', 0, -1).show()
Beispiel #5
0
    0.5,
    0.5,
    0.0,
    0.0,
    0.0,
    0.0,
    0.0,
    0.0,
    0.0,
    0.0,
    0.0,
]), )

pipeline.update(
    uniform_buffer=glnext.camera((0.0, 0.0, 100.0), (0.0, 0.0, 0.0),
                                 (0.0, 1.0, 0.0),
                                 fov=4.0),
    vertex_buffer=vertex_data,
    index_buffer=index_data,
    instance_buffer=instance_data,
)


def image(output):
    data = framebuffer.output[output].read()
    return Image.frombuffer('RGBX', (512, 512), data, 'raw', 'RGBX', 0,
                            -1).convert('RGB')


task.run()
image(0).show()
Beispiel #6
0
        layout (location = 0) in vec3 in_norm;

        layout (location = 0) out vec4 out_color;

        void main() {
            vec3 light = vec3(4.0, 3.0, 10.0);
            float lum = dot(normalize(light), normalize(in_norm)) * 0.7 + 0.3;
            out_color = vec4(lum, lum, lum, 1.0);
        }
    '''),
    vertex_format='3f 3f',
    vertex_count=vertex_count,
    bindings=[
        {
            'binding': 0,
            'name': 'uniform_buffer',
            'type': 'uniform_buffer',
            'size': 64,
        },
    ],
)

pipeline.update(
    uniform_buffer=glnext.camera((4.0, 3.0, 2.0), (0.0, 0.0, 0.0)),
    vertex_buffer=mesh,
)

task.run()
data = framebuffer.output[0].read()
Image.frombuffer('RGBA', (512, 512), data, 'raw', 'RGBA', 0, -1).show()
Beispiel #7
0
        layout (location = 0) out vec4 out_color;

        void main() {
            out_color = vec4(0.0, 0.0, 0.0, 1.0);
        }
    '''),
    vertex_format='3f',
    vertex_count=len(vertex_data) // 12,
    index_count=len(index_data) // 4,
    topology='line_strip',
    bindings=[
        {
            'binding': 0,
            'name': 'uniform_buffer',
            'type': 'uniform_buffer',
            'size': 64,
        },
    ],
)

pipeline.update(
    uniform_buffer=glnext.camera((2.0, 2.0, 1.0), (0.0, 0.0, 0.0), fov=45.0, aspect=16 / 9),
    vertex_buffer=vertex_data,
    index_buffer=index_data,
)

task.run()
data = framebuffer.output[0].read()
Image.frombuffer('RGBA', (1280, 720), data, 'raw', 'RGBA', 0, -1).show()
Beispiel #8
0
            'type':
            'sampled_image',
            'images': [{
                'image': triangle_framebuffer.output[0],
                'sampler': {
                    'min_filter': 'linear',
                    'mag_filter': 'linear',
                    'mipmap_filter': 'linear',
                },
            }],
        },
    ],
)

pipeline.update(
    uniform_buffer=glnext.camera((1.0, 1.0, 1.0), (2.0, 2.0, 1.0)),
    vertex_buffer=glnext.pack([
        0.0,
        0.0,
        0.0,
        0.0,
        0.0,
        0.0,
        100.0,
        0.0,
        0.0,
        20.0,
        100.0,
        0.0,
        0.0,
        20.0,
Beispiel #9
0
        {
            'binding': 0,
            'type': 'uniform_buffer',
            'buffer': uniform_buffer,
        },
        {
            'binding': 1,
            'type': 'sampled_image',
            'images': [{
                'image': shadow_fbo.output[0],
                'sampler': {},
            }]
        },
    ],
)

uniform_buffer.write(b''.join([
    glnext.camera((4.0, 3.0, 2.0), (0.0, 0.0, 0.0)),
    glnext.camera((4.0, 3.0, 12.0), (0.0, 0.0, 0.0),
                  fov=0.0,
                  size=3.0,
                  near=1.0,
                  far=16.0),
    glnext.pack([4.0, 3.0, 2.0, 0.0]),
    glnext.pack([4.0, 3.0, 12.0, 0.0]),
]))

task.run()
data = framebuffer.output[0].read()
Image.frombuffer('RGBA', (512, 512), data, 'raw', 'RGBA', 0, -1).show()
    vertex_format='3h 3h',
    instance_format='3f 4f 3f',
    vertex_buffer=bytes.fromhex(shapes['data']),
    indirect_count=len(objects),
    instance_count=len(objects),
    buffers=[
        {
            'name': 'uniform_buffer',
            'type': 'uniform_buffer',
            'binding': 0,
            'size': 64,
        }
    ]
)

render['uniform_buffer'].write(glnext.camera((4, 3, 2), (0, 0, 0)))

instance_buffer = []
indirect_buffer = []

for i, obj in enumerate(objects):
    instance_buffer += [*obj['position'], *obj['rotation'], *obj['size']]
    indirect_buffer += [shapes['shapes'][obj['shape']]['count'], 1, shapes['shapes'][obj['shape']]['offset'], i]

render['instance_buffer'].write(glnext.pack(instance_buffer))
render['indirect_buffer'].write(glnext.pack(indirect_buffer))

instance.run()

Image.frombuffer('RGBA', (512, 512), fbo.output[0].read(), 'raw', 'RGBA', 0, -1).show()