Exemplo n.º 1
0
 def __init__(self, app):
     # box model
     self.model = geometry.quad_2d((1, 1), (0.5, 0.5), False, False)
     # shader
     self.prog = app.load_program('programs/candlestick.glsl')
     self.prog['m_view'].write(Matrix44.identity(dtype='f4'))
     self.upper_cut = -1
Exemplo n.º 2
0
 def __init__(self, config):
     super().__init__(config)
     self.track_fade = self.get_track('fade')
     size = 1024 / 1920 * 2, 315 / 1080 * 2
     self.quad_2d = geometry.quad_2d(size=size)
     self.texture = self.config.load_texture_2d(
         'textures/logo_site_banner_1024.png')
     self.prog = self.config.load_program('programs/logo.glsl')
Exemplo n.º 3
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.camera.projection.update(near=1, far=200)
        self.wnd.mouse_exclusivity = True

        # Offscreen buffer
        offscreen_size = 1024, 1024
        self.offscreen_depth = self.ctx.depth_texture(offscreen_size)
        self.offscreen_depth.compare_func = ''
        self.offscreen_depth.repeat_x = False
        self.offscreen_depth.repeat_y = False
        self.offscreen_color = self.ctx.texture(offscreen_size, 4)

        self.offscreen = self.ctx.framebuffer(
            color_attachments=[self.offscreen_color],
            depth_attachment=self.offscreen_depth,
        )

        # Scene geometry
        self.floor = geometry.cube(size=(25.0, 1.0, 25.0))
        self.wall = geometry.cube(size=(1.0, 5, 25), center=(-12.5, 2, 0))
        self.sphere = geometry.sphere(radius=5.0, sectors=64, rings=32)
        self.sun = geometry.sphere(radius=1.0)

        # Debug geometry
        self.offscreen_quad = geometry.quad_2d(size=(0.5, 0.5),
                                               pos=(0.75, 0.75))
        self.offscreen_quad2 = geometry.quad_2d(size=(0.5, 0.5),
                                                pos=(0.25, 0.75))

        # Programs
        self.raw_depth_prog = self.load_program(
            'programs/shadow_mapping/raw_depth.glsl')
        self.basic_light = self.load_program(
            'programs/shadow_mapping/directional_light.glsl')
        self.basic_light['shadowMap'].value = 0
        self.basic_light['color'].value = 1.0, 1.0, 1.0, 1.0
        self.shadowmap_program = self.load_program(
            'programs/shadow_mapping/shadowmap.glsl')
        self.texture_prog = self.load_program('programs/texture.glsl')
        self.texture_prog['texture0'].value = 0
        self.sun_prog = self.load_program('programs/cube_simple.glsl')
        self.sun_prog['color'].value = 1, 1, 0, 1
        self.lightpos = 0, 0, 0
Exemplo n.º 4
0
 def __init__(self, app):
     # box model
     self.model = geometry.quad_2d((1, 1), (0.5, 0.5), False, False)
     # shaders
     self.program = app.load_program('programs/screen_element.glsl')
     # control
     self.dragging = False
     # W
     self.start = 0, 0
     self.end = 0, 0
Exemplo n.º 5
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.buffer_size = 320, 256
        # Textures
        self.background_texture = self.load_texture_array(
            'textures/animated_sprites/giphy.gif')
        self.background_texture.repeat_x = False
        self.background_texture.repeat_y = False
        self.caveman_texture = self.load_texture_array(
            'textures/animated_sprites/player_2.gif', layers=35)
        self.caveman_texture.repeat_x = False
        self.caveman_texture.repeat_y = False
        self.caveman_texture.filter = moderngl.NEAREST, moderngl.NEAREST

        # Geometry
        # One pixel quad 0, 0 -> 1.0, 1.0
        self.sprite_geometry = geometry.quad_2d(size=(1.0, 1.0),
                                                pos=(0.5, 0.5))
        self.quad_fs = geometry.quad_fs()

        # Programs
        self.sprite_program = self.load_program(
            'programs/animated_sprites/sprite_array.glsl')
        self.texture_program = self.load_program('programs/texture.glsl')

        # Offscreen buffer
        self.offscreen_texture = self.ctx.texture(self.buffer_size, 4)
        self.offscreen_texture.filter = moderngl.NEAREST, moderngl.NEAREST
        self.offscreen = self.ctx.framebuffer(
            color_attachments=[self.offscreen_texture])

        self.projection = Matrix44.orthogonal_projection(0,
                                                         320,
                                                         0,
                                                         256,
                                                         -1.0,
                                                         1.0,
                                                         dtype='f4')
        self.sprite_program['projection'].write(self.projection)
Exemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.size = self.wnd.buffer_size
        self.viewport = (0, 0, self.size[0], self.size[1])

        self.quad_fs = geometry.quad_fs()
        self.sprite = geometry.quad_2d(size=(9 / self.wnd.size[0], 9 / self.wnd.size[1]))

        self.texture_1 = self.ctx.texture(self.size, components=3)
        self.texture_2 = self.ctx.texture(self.size, components=3)

        self.fbo_1 = self.ctx.framebuffer(color_attachments=[self.texture_1])
        self.fbo_1.viewport = self.viewport
        self.fbo_2 = self.ctx.framebuffer(color_attachments=[self.texture_2])
        self.fbo_2.viewport = self.viewport

        drop = np.array([[0.0, 0.0, 1/6, 1/5, 1/4, 1/5, 1/6, 0.0, 0.0],
                         [0.0, 1/6, 1/5, 1/4, 1/3, 1/4, 1/5, 1/6, 0.0],
                         [1/6, 1/5, 1/4, 1/3, 1/2, 1/3, 1/4, 1/5, 1/6],
                         [1/5, 1/4, 1/3, 1/2, 1.0, 1/2, 1/3, 1/4, 1/5],
                         [1/4, 1/3, 1/2, 1.0, 1.0, 1.0, 1/2, 1/3, 1/4],
                         [1/5, 1/4, 1/3, 1/2, 1.0, 1/2, 1/3, 1/4, 1/5],
                         [1/6, 1/5, 1/4, 1/3, 1/2, 1/3, 1/4, 1/5, 1/6],
                         [0.0, 1/6, 1/5, 1/4, 1/3, 1/4, 1/5, 1/6, 0.0],
                         [0.0, 0.0, 1/6, 1/5, 1/4, 1/5, 1/6, 0.0, 0.0]])
        self.drops_texture = self.ctx.texture((9, 9), components=1, dtype='f4')
        self.drops_texture.write(drop.astype('f4').tobytes())

        # programs
        self.drop_program = self.load_program('programs/water/drop.glsl')
        self.wave_program = self.load_program('programs/water/wave.glsl')
        self.texture_program = self.load_program('programs/water/texture.glsl')
        self.wave_program['texture0'].value = 0
        self.wave_program['texture1'].value = 1

        self.mouse_pos = 0, 0
        self.wnd.fbo.viewport = self.viewport
Exemplo n.º 7
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.camera.projection.update(near=1, far=200)
        self.wnd.mouse_exclusivity = True

        # Offscreen buffer
        offscreen_size = 1024, 1024
        self.offscreen_depth = self.ctx.depth_texture(offscreen_size)
        self.offscreen_depth.compare_func = ''
        self.offscreen_depth.repeat_x = False
        self.offscreen_depth.repeat_y = False
        self.offscreen_color = self.ctx.texture(offscreen_size, 4)

        self.offscreen = self.ctx.framebuffer(
            color_attachments=[self.offscreen_color],
            depth_attachment=self.offscreen_depth,
        )

        # Scene geometry
        self.hmd = geometry.cube(size=np.array((7, 5, 1))/2, center=(0, 0, 0))
        self.hmd2 = geometry.cube(size=np.array((2, 2, 1))/2, center=(0, 0, 2))

        self.handL = geometry.cube(size=np.array((2, 2, 5))/2, center=(0, 0, 0))
        self.handL2 = geometry.cube(size=np.array((1, 1, 1))/2, center=(2, 0, 0))
        self.handL3 = geometry.cube(size=np.array((1, 1, 1))/2, center=(0, 0, 4))

        self.handR = geometry.cube(size=np.array((2, 2, 5))/2, center=(0, 0, 0))
        self.handR2 = geometry.cube(size=np.array((1, 1, 1))/2, center=(2, 0, 0))
        self.handR3 = geometry.cube(size=np.array((1, 1, 1))/2, center=(0, 0, 4))

        self.floor = geometry.cube(size=np.array((100, 0.3, 100)), center=(0, -16, 0))

        # self.sun = geometry.sphere(radius=1.0)

        # Debug geometry
        self.offscreen_quad = geometry.quad_2d(size=(0.5, 0.5), pos=(0.75, 0.75))
        self.offscreen_quad2 = geometry.quad_2d(size=(0.5, 0.5), pos=(0.25, 0.75))

        # Programs
        self.raw_depth_prog = self.load_program('programs/shadow_mapping/raw_depth.glsl')

        # self.basic_light = self.load_program('programs/shadow_mapping/directional_light.glsl')
        # self.basic_light['shadowMap'].value = 0
        # self.basic_light['color'].value = 1.0, 1.0, 1.0, 1.0


        self.shadowmap_program = self.load_program('programs/shadow_mapping/shadowmap.glsl')
        self.basic_lightL = self.load_program('programs/shadow_mapping/directional_light.glsl')
        self.basic_lightL['shadowMap'].value = 0
        self.basic_lightL['color'].value = 0.0, 1.0, 0.0, 1.0

        self.basic_lightR = self.load_program('programs/shadow_mapping/directional_light.glsl')
        self.basic_lightR['shadowMap'].value = 0
        self.basic_lightR['color'].value = 0.0, 0.0, 1.0, 1.0

        self.basic_lightHmd = self.load_program('programs/shadow_mapping/directional_light.glsl')
        self.basic_lightHmd['shadowMap'].value = 0
        self.basic_lightHmd['color'].value = 1.0, 0.0, 0.0, 1

        self.basic_lightFloor = self.load_program('programs/shadow_mapping/directional_light.glsl')
        self.basic_lightFloor['shadowMap'].value = 0
        self.basic_lightFloor['color'].value = 1.0, 1.0, 1.0, 1


        self.texture_prog = self.load_program('programs/texture.glsl')
        self.texture_prog['texture0'].value = 0

        self.sun_prog = self.load_program('programs/cube_simple.glsl')
        self.sun_prog['color'].value = 1, 1, 0, 1
        self.lightpos = 0, 0, 0
        time = 2
        self.lightpos = Vector3((math.sin(time) * 20, 5, math.cos(time) * 20), dtype='f4')
Exemplo n.º 8
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.camera.projection.update(near=1, far=200)
        self.wnd.mouse_exclusivity = True

        # Offscreen buffer
        offscreen_size = 1024, 1024
        self.offscreen_depth = self.ctx.depth_texture(offscreen_size)
        self.offscreen_depth.compare_func = ""
        self.offscreen_depth.repeat_x = False
        self.offscreen_depth.repeat_y = False
        self.offscreen_color = self.ctx.texture(offscreen_size, 4)

        self.offscreen = self.ctx.framebuffer(
            color_attachments=[self.offscreen_color],
            depth_attachment=self.offscreen_depth,
        )

        # Scene geometry
        self.floor = geometry.cube(size=np.array((100, 0.3, 100)),
                                   center=(0, -16, 0))

        # self.sun = geometry.sphere(radius=1.0)

        # Debug geometry
        self.offscreen_quad = geometry.quad_2d(size=(0.5, 0.5),
                                               pos=(0.75, 0.75))
        self.offscreen_quad2 = geometry.quad_2d(size=(0.5, 0.5),
                                                pos=(0.25, 0.75))

        # Programs
        self.raw_depth_prog = self.load_program(
            "programs/shadow_mapping/raw_depth.glsl")

        # self.basic_light = self.load_program('programs/shadow_mapping/directional_light.glsl')
        # self.basic_light['shadowMap'].value = 0
        # self.basic_light['color'].value = 1.0, 1.0, 1.0, 1.0

        self.shadowmap_program = self.load_program(
            "programs/shadow_mapping/shadowmap.glsl")

        self.basic_lightFloor = self.load_program(
            "programs/shadow_mapping/directional_light.glsl")
        self.basic_lightFloor["shadowMap"].value = 0
        self.basic_lightFloor["color"].value = 1.0, 1.0, 1.0, 1

        self.texture_prog = self.load_program("programs/texture.glsl")
        self.texture_prog["texture0"].value = 0

        self.sun_prog = self.load_program("programs/cube_simple.glsl")
        self.sun_prog["color"].value = 1, 1, 0, 1
        self.lightpos = 0, 0, 0
        time = 2
        self.lightpos = Vector3((math.sin(time) * 20, 5, math.cos(time) * 20),
                                dtype="f4")

        self.device_list = []
        np.random.seed(69)
        for i in myDriver.device_order:
            if i == "h":
                self.device_list.append(
                    (Device_hmd(
                        self.ctx,
                        tuple(np.random.randint(100, size=(4, )) / 100)),
                     Velocity_vector(self.ctx, (1, 0, 0, 1))))

            elif i == "c":
                self.device_list.append(
                    (Device_cntrlr(
                        self.ctx,
                        tuple(np.random.randint(100, size=(4, )) / 100)),
                     Velocity_vector(self.ctx, (1, 0, 0, 1),
                                     (-0.75, 0, -1.75))))

            elif i == "t":
                self.device_list.append(
                    (Device_trkr(
                        self.ctx,
                        tuple(np.random.randint(100, size=(4, )) / 100)),
                     Velocity_vector(self.ctx, (1, 0, 0, 1))))
Exemplo n.º 9
0
player_ship = None
player_lives = []
score = 0
num_asteroids = 3
game_objects = []

# We need to pop off as many event stack frames as we pushed on
# every time we reset the level.
event_stack_size = 0

ctx = moderngl.create_context()
moderngl_window.activate_context(ctx=ctx)
moderngl_window.resources.register_dir(
    Path(__file__).resolve().parent / 'resources')

quad = geometry.quad_2d(size=(800 / 600, 1.0))
fbo = ctx.framebuffer(color_attachments=ctx.texture((window_x, window_y),
                                                    components=4),
                      # depth_attachment=ctx.depth_texture((800, 600)),
                      )
texture_program = moderngl_window.resources.programs.load(
    meta.ProgramDescription(path='texture.glsl'))
scene = moderngl_window.resources.scenes.load(
    #    meta.SceneDescription(path='VC/glTF/VC.gltf')
    meta.SceneDescription(path='Sponza/glTF/Sponza.gltf'))
projection = matrix44.create_perspective_projection(90,
                                                    window_x / window_y,
                                                    0.1,
                                                    1000,
                                                    dtype='f4')
Exemplo n.º 10
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        print("window buffer size:", self.wnd.buffer_size)
        self.marker_file = Path('markers.bin')
        # Object rotation
        self.x_rot = 0
        self.y_rot = 0
        # Object position
        self.zoom = 0

        # Load scene cached to speed up loading!
        self.scene = self.load_scene('scenes/fragment_picking/centered.obj',
                                     cache=True)
        # Grab the raw mesh/vertexarray
        self.mesh = self.scene.root_nodes[0].mesh.vao
        self.mesh_texture = self.scene.root_nodes[
            0].mesh.material.mat_texture.texture

        self.projection = Projection3D(
            fov=60,
            aspect_ratio=self.wnd.aspect_ratio,
            near=1.0,
            far=100.0,
        )

        # --- Offscreen render target
        # RGBA color/diffuse layer
        self.offscreen_diffuse = self.ctx.texture(self.wnd.buffer_size, 4)
        # Textures for storing normals (16 bit floats)
        self.offscreen_normals = self.ctx.texture(self.wnd.buffer_size,
                                                  4,
                                                  dtype='f2')
        # Texture for storing the view positions rendered to framebuffer
        self.offscreen_viewpos = self.ctx.texture(self.wnd.buffer_size,
                                                  4,
                                                  dtype='f4')
        # Texture for storing depth values
        self.offscreen_depth = self.ctx.depth_texture(self.wnd.buffer_size)
        # Create a framebuffer we can render to
        self.offscreen = self.ctx.framebuffer(
            color_attachments=[
                self.offscreen_diffuse,
                self.offscreen_normals,
                self.offscreen_viewpos,
            ],
            depth_attachment=self.offscreen_depth,
        )

        # This is just for temp changing depth texture parameters
        # temporary so we can use it as a normal texture
        self.depth_sampler = self.ctx.sampler(
            filter=(moderngl.LINEAR, moderngl.LINEAR),
            compare_func='',
        )

        # A fullscreen quad just for rendering offscreen textures to the window
        self.quad_fs = geometry.quad_fs()

        # --- Shaders
        # Simple program just rendering texture
        self.texture_program = self.load_program(
            'programs/fragment_picking/texture.glsl')
        self.texture_program['texture0'].value = 0
        # Geomtry shader writing to two offscreen layers (color, normal) + depth
        self.geometry_program = self.load_program(
            'programs/fragment_picking/geometry.glsl')
        self.geometry_program['texture0'].value = 0  # use texture channel 0

        # Shader for linearizing depth (debug visualization)
        self.linearize_depth_program = self.load_program(
            'programs/linearize_depth.glsl')
        self.linearize_depth_program['texture0'].value = 0
        self.linearize_depth_program['near'].value = self.projection.near
        self.linearize_depth_program['far'].value = self.projection.far

        # Shader for picking the world position of a fragment
        self.fragment_picker_program = self.load_program(
            'programs/fragment_picking/picker.glsl')
        self.fragment_picker_program[
            'position_texture'].value = 0  # Read from texture channel 0
        self.fragment_picker_program[
            'normal_texture'].value = 1  # Read from texture channel 1
        self.fragment_picker_program[
            'diffuse_texture'].value = 2  # Read from texture channel 2

        # Picker geometry
        self.marker_byte_size = 7 * 4  # position + normal + temperature (7 x 32bit floats)
        self.picker_output = self.ctx.buffer(reserve=self.marker_byte_size)
        self.picker_vao = VAO(mode=moderngl.POINTS)

        # Shader for rendering markers
        self.marker_program = self.load_program(
            'programs/fragment_picking/markers.glsl')
        self.marker_program['color'].value = 1.0, 0.0, 0.0, 1.0

        # Marker geometry
        self.marker_buffer = self.ctx.buffer(
            reserve=self.marker_byte_size *
            1000)  # Resever room for 1000 points
        self.marker_vao = VAO(name="markers", mode=moderngl.POINTS)
        self.marker_vao.buffer(self.marker_buffer, '3f 3f 1f',
                               ['in_position', 'in_normal', 'temperature'])
        self.num_markers = 0

        # Debug geometry
        self.quad_normals = geometry.quad_2d(size=(0.25, 0.25),
                                             pos=(0.75, 0.875))
        self.quad_depth = geometry.quad_2d(size=(0.25, 0.25), pos=(0.5, 0.875))
        self.quad_positions = geometry.quad_2d(size=(0.25, 0.25),
                                               pos=(0.25, 0.875))
Exemplo n.º 11
0
 def __init__(self):
     self.model = geometry.quad_2d((1, 1), (0.5, 0.5), False, False)
Exemplo n.º 12
0
 def __init__(self):
     self.__date_id = {}
     self.__id_date = []
     self.gap_width = 0.3
     self.day_width = 0.2
     self.model = geometry.quad_2d((1, 1), (0.5, 0.5), False, False)