Exemplo n.º 1
0
class CameraWindow(mglw.WindowConfig):
    """Base class with built in 3D camera support"""
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.camera = KeyboardCamera(self.wnd.keys,
                                     aspect_ratio=self.wnd.aspect_ratio)
        self.camera_enabled = True

    def key_event(self, key, action, modifiers):
        keys = self.wnd.keys

        if self.camera_enabled:
            self.camera.key_input(key, action, modifiers)

        if action == keys.ACTION_PRESS:
            if key == keys.C:
                self.camera_enabled = not self.camera_enabled
                self.wnd.mouse_exclusivity = self.camera_enabled
                self.wnd.cursor = not self.camera_enabled
            if key == keys.SPACE:
                self.timer.toggle_pause()

    def mouse_position_event(self, x: int, y: int, dx, dy):
        if self.camera_enabled:
            self.camera.rot_state(-dx, -dy)

    def resize(self, width: int, height: int):
        self.camera.projection.update(aspect_ratio=self.wnd.aspect_ratio)
Exemplo n.º 2
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.camera = KeyboardCamera(self.wnd.keys,
                                     aspect_ratio=self.wnd.aspect_ratio,
                                     far=5000)
        self.camera.set_rotation(0, -90)
        self.camera.set_position(0, 200, 0)
        self.camera.mouse_sensitivity = 0.25

        self.camera_enabled = True
Exemplo n.º 3
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.wnd.mouse_exclusivity = True

        # --- glTF-Sample-Models ---
        # self.scene = self.load_scene('2CylinderEngine/glTF-Binary/2CylinderEngine.glb')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF-Embedded/CesiumMilkTruck.gltf')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF/CesiumMilkTruck.gltf')
        self.scene = self.load_scene('Sponza/glTF/Sponza.gltf')
        # self.scene = self.load_scene('Lantern/glTF-Binary/Lantern.glb')
        # self.scene = self.load_scene('Buggy/glTF-Binary/Buggy.glb')
        # self.scene = self.load_scene('VC/glTF-Binary/VC.glb')
        # self.scene = self.load_scene('DamagedHelmet/glTF-Binary/DamagedHelmet.glb')
        # self.scene = self.load_scene('BoxInterleaved/glTF/BoxInterleaved.gltf')

        self.camera = KeyboardCamera(self.wnd.keys,
                                     fov=75.0,
                                     aspect_ratio=self.wnd.aspect_ratio,
                                     near=0.1,
                                     far=1000.0)
        self.camera.velocity = 7.0
        self.camera.mouse_sensitivity = 0.3

        # Use this for gltf scenes for better camera controls
        if self.scene.diagonal_size > 0:
            self.camera.velocity = self.scene.diagonal_size / 5.0
Exemplo n.º 4
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.camera = KeyboardCamera(self.wnd.keys,
                                     aspect_ratio=self.wnd.aspect_ratio)
        self.terrain_program = self.load_program('my_shader.glsl')
        self.ctx.front_face = 'cw'

        # self.ctx.wireframe = True
        self.translate = Matrix44.from_translation((0, 1., .25))
        self.rotate = Matrix44.look_at((0., 1., .25), (0., 0., -1.),
                                       (0., 1., 0.))
        self.projection = (self.camera.projection.matrix *
                           (self.translate * self.rotate)).astype('f4')
        self.terrain_program['projection'].write(self.projection.tobytes())

        terrain_resolution = 5

        points = generate(terrain_resolution).astype('f4')
        self.buffer = self.ctx.buffer(points)

        indices = generate_index_buffer(terrain_resolution).astype('i4')
        print(indices)
        self.index_buffer = self.ctx.buffer(indices)

        self.vao_1 = VAO(name='vao_1')
        self.vao_1.buffer(self.buffer, '3f', ['in_position'])
        self.vao_1.index_buffer(self.index_buffer)
Exemplo n.º 5
0
class CameraWindow(mglw.WindowConfig):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.camera = KeyboardCamera(self.wnd.keys,
                                     aspect_ratio=self.wnd.aspect_ratio)

    def key_event(self, key, action, modifiers):
        self.camera.key_input(key, action, modifiers)

        if key == self.wnd.keys.SPACE and action == self.wnd.keys.ACTION_PRESS:
            self.timer.toggle_pause()

    def mouse_position_event(self, x: int, y: int):
        self.camera.rot_state(x, y)

    def resize(self, width: int, height: int):
        self.camera.projection.update(aspect_ratio=self.wnd.aspect_ratio)
Exemplo n.º 6
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # self.wnd.mouse_exclusivity = True
        self.camera = KeyboardCamera(self.wnd.keys,
                                     aspect_ratio=self.wnd.aspect_ratio)
        self.camera_enabled = False
        self.render_program = self.load_program('my_shader.glsl')

        self.render_program['projection'].write(
            self.camera.projection.tobytes())
        self.render_program['m_camera'].write(
            self.camera.matrix.astype('f4').tobytes())
        self.cube = Cube(size=(.5, .5, .5))
Exemplo n.º 7
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.scene = self.load_scene('scenes/crate.obj')
        # self.scene = self.load_scene('scenes/Apollo_17.stl')

        # --- glTF-Sample-Models ---
        # self.scene = self.load_scene('2CylinderEngine/glTF-Binary/2CylinderEngine.glb')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF-Embedded/CesiumMilkTruck.gltf')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF/CesiumMilkTruck.gltf')
        # self.scene = self.load_scene('Sponza/glTF/Sponza.gltf')
        # self.scene = self.load_scene('Lantern/glTF-Binary/Lantern.glb')
        # self.scene = self.load_scene('Buggy/glTF-Binary/Buggy.glb')
        # self.scene = self.load_scene('VC/glTF-Binary/VC.glb')
        # self.scene = self.load_scene('DamagedHelmet/glTF-Binary/DamagedHelmet.glb')
        # self.scene = self.load_scene('BoxInterleaved/glTF/BoxInterleaved.gltf')

        self.camera = KeyboardCamera(self.wnd.keys,
                                     fov=75.0,
                                     aspect_ratio=self.wnd.aspect_ratio,
                                     near=0.1,
                                     far=1000.0)
Exemplo n.º 8
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.wnd.mouse_exclusivity = True

        # --- glTF-Sample-Models ---
        # self.scene = self.load_scene('2CylinderEngine/glTF-Binary/2CylinderEngine.glb')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF-Embedded/CesiumMilkTruck.gltf')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF/CesiumMilkTruck.gltf')
        self.scene = self.load_scene('Sponza/glTF/Sponza.gltf')
        # self.scene = self.load_scene('Lantern/glTF-Binary/Lantern.glb')
        # self.scene = self.load_scene('Buggy/glTF-Binary/Buggy.glb')
        # self.scene = self.load_scene('VC/glTF-Binary/VC.glb')
        # self.scene = self.load_scene('DamagedHelmet/glTF-Binary/DamagedHelmet.glb')
        # self.scene = self.load_scene('BoxInterleaved/glTF/BoxInterleaved.gltf')
        # self.scene = self.load_scene('OrientationTest/glTF/OrientationTest.gltf')
        # self.scene = self.load_scene('AntiqueCamera/glTF/AntiqueCamera.gltf')
        # self.scene = self.load_scene('BoomBox/glTF/BoomBox.gltf')
        # self.scene = self.load_scene('Box/glTF/Box.gltf')
        # self.scene = self.load_scene('BoxTextured/glTF/BoxTextured.gltf')
        # self.scene = self.load_scene('BoxTexturedNonPowerOfTwo/glTF/BoxTexturedNonPowerOfTwo.gltf')
        # self.scene = self.load_scene('BoxVertexColors/glTF/BoxVertexColors.gltf')
        # self.scene = self.load_scene('BrainStem/glTF/BrainStem.gltf')
        # self.scene = self.load_scene('Corset/glTF/Corset.gltf')
        # self.scene = self.load_scene('FlightHelmet/glTF/FlightHelmet.gltf')
        # self.scene = self.load_scene('Fox/glTF/Fox.gltf')
        # self.scene = self.load_scene('GearboxAssy/glTF/GearboxAssy.gltf')
        # self.scene = self.load_scene('ReciprocatingSaw/glTF/ReciprocatingSaw.gltf')
        # self.scene = self.load_scene('RiggedFigure/glTF/RiggedFigure.gltf')
        # self.scene = self.load_scene('RiggedSimple/glTF/RiggedSimple.gltf')
        # self.scene = self.load_scene('SciFiHelmet/glTF/SciFiHelmet.gltf')
        # self.scene = self.load_scene('SimpleMeshes/glTF/SimpleMeshes.gltf')
        # self.scene = self.load_scene('SimpleSparseAccessor/glTF/SimpleSparseAccessor.gltf')
        # self.scene = self.load_scene('Suzanne/glTF/Suzanne.gltf')
        # self.scene = self.load_scene('TextureCoordinateTest/glTF/TextureCoordinateTest.gltf')
        # self.scene = self.load_scene('TextureSettingsTest/glTF/TextureSettingsTest.gltf')
        # self.scene = self.load_scene('VertexColorTest/glTF/VertexColorTest.gltf')
        # self.scene = self.load_scene('WaterBottle/glTF/WaterBottle.gltf')

        self.camera = KeyboardCamera(self.wnd.keys,
                                     fov=75.0,
                                     aspect_ratio=self.wnd.aspect_ratio,
                                     near=0.1,
                                     far=1000.0)
        # self.camera.velocity = 7.0
        # self.camera.mouse_sensitivity = 0.3

        # Use this for gltf scenes for better camera controls
        if self.scene.diagonal_size > 0:
            self.camera.velocity = self.scene.diagonal_size / 5.0
Exemplo n.º 9
0
class CameraWindow(mglw.WindowConfig):
    """Base class with built in 3D camera support"""
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.camera = KeyboardCamera(self.wnd.keys,
                                     aspect_ratio=self.wnd.aspect_ratio,
                                     far=5000)
        self.camera.set_rotation(0, -90)
        self.camera.set_position(0, 200, 0)
        self.camera.mouse_sensitivity = 0.25

        self.camera_enabled = True

    def key_event(self, key, action, modifiers):
        keys = self.wnd.keys

        if self.camera_enabled:
            if modifiers.shift:
                self.camera.velocity = 250.0
            else:
                self.camera.velocity = 5.0
            self.camera.key_input(key, action, modifiers)

        if action == keys.ACTION_PRESS:
            if key == keys.C:
                self.camera_enabled = not self.camera_enabled
                self.wnd.mouse_exclusivity = self.camera_enabled
                self.wnd.cursor = not self.camera_enabled
            if key == keys.SPACE:
                self.timer.toggle_pause()

    def mouse_position_event(self, x: int, y: int, dx, dy):
        if self.camera_enabled:
            self.camera.rot_state(-dx, -dy)

    def resize(self, width: int, height: int):
        self.camera.projection.update(aspect_ratio=self.wnd.aspect_ratio)

    def render(self, time: float, frame_time: float):
        pass
Exemplo n.º 10
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.camera = KeyboardCamera(self.wnd.keys,
                                  aspect_ratio=self.wnd.aspect_ratio)
     self.camera_enabled = True
Exemplo n.º 11
0
class CubeModel(mglw.WindowConfig):
    # window_size = (1920, 1080)
    aspect_ratio = 16 / 9

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.scene = self.load_scene('scenes/crate.obj')
        # self.scene = self.load_scene('scenes/Apollo_17.stl')

        # --- glTF-Sample-Models ---
        # self.scene = self.load_scene('2CylinderEngine/glTF-Binary/2CylinderEngine.glb')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF-Embedded/CesiumMilkTruck.gltf')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb')
        # self.scene = self.load_scene('CesiumMilkTruck/glTF/CesiumMilkTruck.gltf')
        # self.scene = self.load_scene('Sponza/glTF/Sponza.gltf')
        # self.scene = self.load_scene('Lantern/glTF-Binary/Lantern.glb')
        # self.scene = self.load_scene('Buggy/glTF-Binary/Buggy.glb')
        # self.scene = self.load_scene('VC/glTF-Binary/VC.glb')
        # self.scene = self.load_scene('DamagedHelmet/glTF-Binary/DamagedHelmet.glb')
        # self.scene = self.load_scene('BoxInterleaved/glTF/BoxInterleaved.gltf')

        self.camera = KeyboardCamera(self.wnd.keys,
                                     fov=75.0,
                                     aspect_ratio=self.wnd.aspect_ratio,
                                     near=0.1,
                                     far=1000.0)
        # Use this for gltf scenes for better camera controls
        # if self.scene.diagonal_size > 0:
        # self.camera.velocity = self.scene.diagonal_size / 5.0

    def render(self, time: float, frametime: float):
        """Render the scene"""
        self.ctx.enable_only(moderngl.DEPTH_TEST)  # | moderngl.CULL_FACE)

        # Create camera matrix with rotation and translation
        translation = matrix44.create_from_translation((0, 0, -1.5))
        # rotation = matrix44.create_from_eulers((time, time, time))
        rotation = matrix44.create_from_eulers((0, 0, 0))
        model_matrix = matrix44.multiply(rotation, translation)

        camera_matrix = matrix44.multiply(model_matrix, self.camera.matrix)

        self.scene.draw(
            projection_matrix=self.camera.projection.matrix,
            camera_matrix=camera_matrix,
            time=time,
        )
        # # Currently only works with GLTF2
        # self.scene.draw_bbox(
        #     projection_matrix=self.camera.projection.matrix,
        #     camera_matrix=camera_matrix,
        #     children=True,
        # )

    def key_event(self, key, action, modifiers):
        self.camera.key_input(key, action, modifiers)

    def mouse_position_event(self, x: int, y: int):
        self.camera.rot_state(x, y)

    def resize(self, width: int, height: int):
        self.camera.projection.update(aspect_ratio=self.wnd.aspect_ratio)
Exemplo n.º 12
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.camera = KeyboardCamera(self.wnd.keys, aspect_ratio=self.wnd.aspect_ratio)
     self.camera_enabled = True
     self.camera.set_position(4.42387942, 17.55616676, 29.89753398)
     self.camera.set_rotation(-103, -29.0)
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        imgui.create_context()
        self.wnd.ctx.error
        self.imgui = ModernglWindowRenderer(self.wnd)
        self.space_down = False

        self.prog = self.ctx.program(
            vertex_shader="""
        #version 330
        uniform mat4 transform;
        uniform vec3 clr;
        uniform float aspect;

        in vec3 in_vert;
        out vec3 color;
        out vec2 uv;
        void main() {
            vec3 pos = vec3(in_vert.x, in_vert.y * aspect, 0.0);
            gl_Position = transform * vec4(pos, 1.0);
            uv = vec2(in_vert.x * 0.5 + 0.5, in_vert.y * 0.5 + 0.5);
            uv.y = 1.0 - uv.y;
            color = vec3(1, 0, 0);
        }
        """,
            fragment_shader="""
        #version 330
        uniform sampler2D tex_sampler;

        out vec4 fragColor;
        in vec3 color;
        in vec2 uv;
        void main() {
            fragColor = vec4(texture(tex_sampler, uv).rgb, 1.0);
        }
        """,
        )

        self.reference_texture = self.ctx.texture(
            (dataset.render_size, dataset.render_size), components=3)
        self.prediction_texture = self.ctx.texture(
            (dataset.render_size, dataset.render_size), components=3)
        self.reference_texture.repeat_x = False
        self.reference_texture.repeat_y = False
        self.prediction_texture.repeat_x = False
        self.prediction_texture.repeat_y = False
        self.reference_texture.use(5)
        self.prediction_texture.use(6)

        self.prog['aspect'].value = 12 / 6
        T = pyrr.matrix44.create_from_translation(np.array([-0.5, 0.15, 0]))
        T2 = pyrr.matrix44.create_from_translation(np.array([0.5, 0.15, 0]))
        S = pyrr.matrix44.create_from_scale(np.array([0.4, 0.4, 1]))
        self.M = pyrr.matrix44.multiply(S, T)
        self.M2 = pyrr.matrix44.multiply(S, T2)
        self.transform = self.prog['transform']
        self.transform.value = tuple(self.M.flatten())

        self.observation_textures = []
        self.observation_transforms = []
        for i in range(1, settings.views_per_scene):
            self.observation_textures.append(
                self.ctx.texture((dataset.render_size, dataset.render_size),
                                 components=3))
            self.observation_textures[-1].repeat_x = False
            self.observation_textures[-1].repeat_y = False
            self.observation_textures[-1].use(6 + i)

            T = pyrr.matrix44.create_from_translation(
                np.array([-0.825 + (i - 1) * 0.165, -0.825, 0]))
            S = pyrr.matrix44.create_from_scale(np.array([0.075, 0.075, 1]))
            M = pyrr.matrix44.multiply(S, T)
            self.observation_transforms.append(M)

        self.buffer_textures = []
        self.buffer_transforms = []
        for i in range(len(settings.model.generators[-1].query_passes)):
            self.buffer_textures.append(
                self.ctx.texture((dataset.render_size, dataset.render_size),
                                 components=3))
            self.buffer_textures[-1].repeat_x = False
            self.buffer_textures[-1].repeat_y = False
            self.buffer_textures[-1].use(6 + settings.views_per_scene + i)

            T = pyrr.matrix44.create_from_translation(
                np.array([0.175 + i * 0.165, -0.825, 0]))
            S = pyrr.matrix44.create_from_scale(np.array([0.075, 0.075, 1]))
            M = pyrr.matrix44.multiply(S, T)
            self.buffer_transforms.append(M)

        self.camera = KeyboardCamera(self.wnd.keys, 45.0, 1.0, 0.1, 100.0)
        self.camera.position[0] = 1.5
        self.camera.position[1] = 1.5
        self.camera.position[2] = -1.5
        self.camera._velocity = -2.5
        self.camera._mouse_sensitivity = -0.1

        self.quad = np.array([
            -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 1.0, 1.0, 0.0, -1.0, -1.0, 0.0,
            1.0, 1.0, 0.0, -1.0, 1.0, 0.0
        ],
                             dtype='f4')
        self.quad_vao = self.ctx.simple_vertex_array(
            self.prog, self.ctx.buffer(self.quad), 'in_vert')
class WindowEvents(mglw.WindowConfig):
    gl_version = (3, 3)
    window_size = (1200, 600)
    aspect_ratio = window_size[0] / window_size[1]
    title = "Neural Renderer"

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        imgui.create_context()
        self.wnd.ctx.error
        self.imgui = ModernglWindowRenderer(self.wnd)
        self.space_down = False

        self.prog = self.ctx.program(
            vertex_shader="""
        #version 330
        uniform mat4 transform;
        uniform vec3 clr;
        uniform float aspect;

        in vec3 in_vert;
        out vec3 color;
        out vec2 uv;
        void main() {
            vec3 pos = vec3(in_vert.x, in_vert.y * aspect, 0.0);
            gl_Position = transform * vec4(pos, 1.0);
            uv = vec2(in_vert.x * 0.5 + 0.5, in_vert.y * 0.5 + 0.5);
            uv.y = 1.0 - uv.y;
            color = vec3(1, 0, 0);
        }
        """,
            fragment_shader="""
        #version 330
        uniform sampler2D tex_sampler;

        out vec4 fragColor;
        in vec3 color;
        in vec2 uv;
        void main() {
            fragColor = vec4(texture(tex_sampler, uv).rgb, 1.0);
        }
        """,
        )

        self.reference_texture = self.ctx.texture(
            (dataset.render_size, dataset.render_size), components=3)
        self.prediction_texture = self.ctx.texture(
            (dataset.render_size, dataset.render_size), components=3)
        self.reference_texture.repeat_x = False
        self.reference_texture.repeat_y = False
        self.prediction_texture.repeat_x = False
        self.prediction_texture.repeat_y = False
        self.reference_texture.use(5)
        self.prediction_texture.use(6)

        self.prog['aspect'].value = 12 / 6
        T = pyrr.matrix44.create_from_translation(np.array([-0.5, 0.15, 0]))
        T2 = pyrr.matrix44.create_from_translation(np.array([0.5, 0.15, 0]))
        S = pyrr.matrix44.create_from_scale(np.array([0.4, 0.4, 1]))
        self.M = pyrr.matrix44.multiply(S, T)
        self.M2 = pyrr.matrix44.multiply(S, T2)
        self.transform = self.prog['transform']
        self.transform.value = tuple(self.M.flatten())

        self.observation_textures = []
        self.observation_transforms = []
        for i in range(1, settings.views_per_scene):
            self.observation_textures.append(
                self.ctx.texture((dataset.render_size, dataset.render_size),
                                 components=3))
            self.observation_textures[-1].repeat_x = False
            self.observation_textures[-1].repeat_y = False
            self.observation_textures[-1].use(6 + i)

            T = pyrr.matrix44.create_from_translation(
                np.array([-0.825 + (i - 1) * 0.165, -0.825, 0]))
            S = pyrr.matrix44.create_from_scale(np.array([0.075, 0.075, 1]))
            M = pyrr.matrix44.multiply(S, T)
            self.observation_transforms.append(M)

        self.buffer_textures = []
        self.buffer_transforms = []
        for i in range(len(settings.model.generators[-1].query_passes)):
            self.buffer_textures.append(
                self.ctx.texture((dataset.render_size, dataset.render_size),
                                 components=3))
            self.buffer_textures[-1].repeat_x = False
            self.buffer_textures[-1].repeat_y = False
            self.buffer_textures[-1].use(6 + settings.views_per_scene + i)

            T = pyrr.matrix44.create_from_translation(
                np.array([0.175 + i * 0.165, -0.825, 0]))
            S = pyrr.matrix44.create_from_scale(np.array([0.075, 0.075, 1]))
            M = pyrr.matrix44.multiply(S, T)
            self.buffer_transforms.append(M)

        self.camera = KeyboardCamera(self.wnd.keys, 45.0, 1.0, 0.1, 100.0)
        self.camera.position[0] = 1.5
        self.camera.position[1] = 1.5
        self.camera.position[2] = -1.5
        self.camera._velocity = -2.5
        self.camera._mouse_sensitivity = -0.1

        self.quad = np.array([
            -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 1.0, 1.0, 0.0, -1.0, -1.0, 0.0,
            1.0, 1.0, 0.0, -1.0, 1.0, 0.0
        ],
                             dtype='f4')
        self.quad_vao = self.ctx.simple_vertex_array(
            self.prog, self.ctx.buffer(self.quad), 'in_vert')

    def render(self, time: float, frametime: float):
        # Load transform
        view = self.camera.matrix
        view_inverse = pyrr.matrix44.inverse(view)
        position = pyrr.matrix44.apply_to_vector(
            view_inverse, np.array([0.0, 0.0, 0.0, 1.0]))
        lookat = pyrr.matrix44.apply_to_vector(view_inverse,
                                               np.array([0.0, 0.0, 1.0, 1.0]))
        dataset.renderer.renderer.set_camera(position[:3], lookat[:3])

        # Get reference and draw
        dataset.samples = samples
        queries = dataset.get_current_view()
        data["query_images"] = queries[0]
        data["query_poses"] = queries[1]

        reference = format_buffer(
            data["query_images"][settings.model.output_pass][0])
        reference = reference.clamp(0, 1).numpy()
        reference = (reference * 255).astype(np.uint8)
        self.reference_texture.write(reference.tobytes())
        self.prog['tex_sampler'].value = 5
        self.transform.value = tuple(self.M.flatten())
        self.quad_vao.render(mode=moderngl.TRIANGLES)

        # Draw observations
        for i in range(len(self.observation_textures)):
            observation = format_buffer(
                data["observation_images"][settings.model.output_pass][0][i])
            observation = observation.clamp(0, 1).numpy()
            observation = (observation * 255).astype(np.uint8)
            self.observation_textures[i].write(observation.tobytes())
            self.prog['tex_sampler'].value = 6 + 1 + i
            self.transform.value = tuple(
                self.observation_transforms[i].flatten())
            self.quad_vao.render(mode=moderngl.TRIANGLES)

        # Draw G-buffer (TODO)
        for i in range(len(self.buffer_textures)):
            buffer = format_buffer(data["query_images"][
                settings.model.generators[-1].query_passes[i]][0])
            buffer = buffer.clamp(0, 1).numpy()
            buffer = (buffer * 255).astype(np.uint8)
            self.buffer_textures[i].write(buffer.tobytes())
            self.prog['tex_sampler'].value = 6 + settings.views_per_scene + i
            self.transform.value = tuple(self.buffer_transforms[i].flatten())
            self.quad_vao.render(mode=moderngl.TRIANGLES)

        # Network sample and draw
        prediction = net.sample(data)
        pred = format_buffer(prediction[-1][settings.model.output_pass][0])
        pred = pred.clamp(0, 1).numpy()
        pred = (pred * 255).astype(np.uint8)
        self.prediction_texture.write(pred.tobytes())
        self.prog['tex_sampler'].value = 6
        self.transform.value = tuple(self.M2.flatten())
        self.quad_vao.render(mode=moderngl.TRIANGLES)

        self.render_ui()

    def render_ui(self):
        global samples, observation_samples
        imgui.new_frame()

        imgui.begin("Options", True)

        if imgui.button("Random Scene"):
            random_scene()

        if imgui.button("Randomize Observations"):
            random_observations()

        _, samples = imgui.drag_int("Query SPP",
                                    samples,
                                    min_value=1,
                                    max_value=1024)
        _, observation_samples = imgui.drag_int("Observation SPP",
                                                observation_samples,
                                                min_value=1,
                                                max_value=1024)

        imgui.end()

        imgui.render()
        self.imgui.render(imgui.get_draw_data())

    def resize(self, width: int, height: int):
        self.imgui.resize(width, height)

    def key_event(self, key, action, modifiers):
        global samples, observation_samples
        self.imgui.key_event(key, action, modifiers)
        if action == self.wnd.keys.ACTION_PRESS:
            if key == self.wnd.keys.SPACE:
                self.space_down = True
            if key == self.wnd.keys.R:
                random_scene()
            if key == self.wnd.keys.O:
                random_observations()
            if key == self.wnd.keys.J:
                samples += 10
            if key == self.wnd.keys.H:
                samples = max(1, samples - 10)
            if key == self.wnd.keys.M:
                observation_samples += 10
            if key == self.wnd.keys.N:
                observation_samples = max(1, observation_samples - 10)

        if action == self.wnd.keys.ACTION_RELEASE:
            if key == self.wnd.keys.SPACE:
                self.space_down = False
                imgui.set_window_focus()

        if self.space_down:
            self.camera.key_input(key, action, modifiers)

    def mouse_position_event(self, x, y, dx, dy):
        self.imgui.mouse_position_event(x, y, dx, dy)

    def mouse_drag_event(self, x, y, dx, dy):
        self.imgui.mouse_drag_event(x, y, dx, dy)
        if self.space_down:
            self.camera.rot_state(dx, dy)

    def mouse_scroll_event(self, x_offset, y_offset):
        self.imgui.mouse_scroll_event(x_offset, y_offset)

    def mouse_press_event(self, x, y, button):
        self.imgui.mouse_press_event(x, y, button)

    def mouse_release_event(self, x: int, y: int, button: int):
        self.imgui.mouse_release_event(x, y, button)

    def unicode_char_entered(self, char):
        self.imgui.unicode_char_entered(char)