예제 #1
0
    def __init__(self):
        self.cube = geometry.cube(4.0, 4.0, 4.0)

        # Instantiate the cube effects
        # This would normally be done in project
        self.plain = PlainCube(self.cube)
        self.light = LightCube(self.cube)
        self.textured = TexturedCube(self.cube)
예제 #2
0
    def test_subroutines(self):
        shader = self.create_shader(path='vf_subroutines.glsl')
        cube = geometry.cube(1.0, 1.0, 1.0)
        self.assertAttributes(shader)

        assert shader.subroutines == ('color',)

        cube.subroutines(shader, (shader['redColor'],))
        cube.draw(shader)
예제 #3
0
 def test_instanced(self):
     shader = self.load_program("vf_instanced.glsl")
     vao = geometry.cube(1.0, 1.0, 1.0)
     vao.buffer(
         self.ctx.buffer(reserve=4 * 10),
         '1f',
         "in_instance",
         per_instance=True,
     )
     vao.render(shader, instances=10)
예제 #4
0
 def test_instanced(self):
     shader = self.create_shader(path="vf_instanced.glsl")
     vao = geometry.cube(1.0, 1.0, 1.0)
     vao.buffer(
         self.ctx.buffer(reserve=4 * 10),
         '1f',
         "in_instance",
         per_instance=True,
     )
     vao.draw(shader, instances=10)
예제 #5
0
    def __init__(self, width, height, gbuffer=None, lightbuffer=None):
        self.ctx = context.ctx()

        self.width = width
        self.height = height
        self.size = (width, height)
        self.depth_sampler = samplers.create(texture_compare_mode=False,
                                             min_filter=moderngl.LINEAR,
                                             mag_filter=moderngl.LINEAR)

        # FBOs
        self.gbuffer = gbuffer
        self.lightbuffer = lightbuffer

        # Light Info
        self.point_lights = []

        # Create geometry buffer if not supplied
        depth_buffer = DepthTexture(self.size)

        if not self.gbuffer:
            self.gbuffer = FBO.create_from_textures(
                [
                    Texture2D.create(self.size, 4, dtype='f1'),
                    Texture2D.create(self.size, 3, dtype='f2'),
                ],
                depth_buffer=depth_buffer,
            )

        if not self.lightbuffer:
            self.lightbuffer = FBO.create_from_textures(
                [Texture2D.create(self.size, 4)],
                # depth_buffer=depth_buffer,
            )

        # Unit cube for point lights (cube with radius 1.0)
        self.unit_cube = geometry.cube(width=2, height=2, depth=2)
        self.point_light_shader = resources.shaders.get(
            "deferred/light_point.glsl", create=True)

        # Debug draw lights
        self.debug_shader = resources.shaders.get("deferred/debug.glsl",
                                                  create=True)

        # Combine shader
        self.combine_shader = resources.shaders.get("deferred/combine.glsl",
                                                    create=True)
        self.quad = geometry.quad_fs()
예제 #6
0
    def test_create(self):
        self.instance.add_point_light(position=[0.0, 0.0, 0.0], radius=40.0)

        cube = geometry.cube(width=8.0, height=8.0, depth=8.0)
        geo_shader_color = self.load_program(
            path="deferred/geometry_color.glsl")
        projection = Projection()

        with self.instance.gbuffer_scope:
            cube.render(geo_shader_color)

        self.instance.render_lights(
            matrix44.create_identity(dtype='f4'),
            projection,
        )
        self.instance.combine()
        self.instance.clear()
예제 #7
0
    def __init__(self):
        self.cube_shader1 = self.get_shader('geocubes/cube_multi_fade.glsl')
        self.cube_shader2 = self.get_shader('geocubes/cube_texture_light.glsl')
        self.quad_shader = self.get_shader('geocubes/quad_fs_uvscale.glsl')

        self.texture1 = self.get_texture('geocubes/texture.png')
        self.texture2 = self.get_texture('geocubes/GreenFabric.png')

        self.cube = geometry.cube(4.0, 4.0, 4.0)

        v = 100.0
        r = (-v, v)

        self.points = geometry.points_random_3d(50_000,
                                                range_x=r,
                                                range_y=r,
                                                range_z=r,
                                                seed=7656456)
        self.quad = geometry.quad_fs()
        self.fbo = FBO.create((512, 512), depth=True)
예제 #8
0
    def __init__(self):
        self.cube_prog1 = self.get_program('cube_multi_fade')
        self.cube_prog2 = self.get_program('cube_texture_light')
        self.quad_prog = self.get_program('quad_fs_uvscale')

        self.texture1 = self.get_texture('texture')
        self.texture2 = self.get_texture('GreenFabric')

        self.cube = geometry.cube(4.0, 4.0, 4.0)

        axis_range = 100.0
        range_tuple = (-axis_range, axis_range)

        self.points = geometry.points_random_3d(50_000,
                                                range_x=range_tuple,
                                                range_y=range_tuple,
                                                range_z=range_tuple,
                                                seed=7656456)
        self.quad = geometry.quad_fs()

        self.fbo = self.ctx.framebuffer(
            self.ctx.texture((512, 512), 4),
            depth_attachment=self.ctx.depth_texture((512, 512)),
        )
예제 #9
0
 def test_cube(self):
     vao = geometry.cube(1.0, 1.0, 1.0)
     vao.draw(self.shader)
예제 #10
0
 def test_cube(self):
     vao = geometry.cube(1.0, 1.0, 1.0)
     vao.render(self.program)
예제 #11
0
 def __init__(self):
     self.shader = self.get_shader("cube_plain.glsl", local=True)
     self.cube = geometry.cube(4.0, 4.0, 4.0)
예제 #12
0
 def __init__(self):
     self.plain_shader = self.get_shader("cubes/cube_plain.glsl")
     self.light_shader = self.get_shader("cubes/cube_light.glsl")
     self.texture_shader = self.get_shader("cubes/cube_textured.glsl")
     self.texture = self.get_texture("cubes/crate.jpg", mipmap=True)
     self.cube = geometry.cube(4.0, 4.0, 4.0)