Ejemplo n.º 1
0
    def init(self, platform_data):
        self.init_conf.platform_data = platform_data
        bgfx.render_frame()
        bgfx.init(self.init_conf)
        bgfx.reset(
            self.width, self.height, BGFX_RESET_VSYNC, self.init_conf.resolution.format,
        )

        bgfx.set_debug(BGFX_DEBUG_TEXT)
        bgfx.set_view_clear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF, 1.0, 0)

        # Create time uniform
        self.time_uniform = bgfx.create_uniform("u_time", bgfx.UniformType.VEC4)

        # Load Bunny mesh
        self.mesh = Mesh(Path(__file__).parent.parent / "assets" / "meshes" / "bunny.bin")

        # Create program from shaders.
        self.main_program = bgfx.create_program(
            load_shader(
                "mesh.VertexShader.vert", ShaderType.VERTEX, root_path=root_path
            ),
            load_shader(
                "mesh.FragmentShader.frag", ShaderType.FRAGMENT, root_path=root_path
            ),
            True,
        )

        ImGuiExtra.imgui_create()
Ejemplo n.º 2
0
    def init(self, platform_data):
        self.init_conf.platform_data = platform_data
        bgfx.render_frame()
        bgfx.init(self.init_conf)
        bgfx.reset(
            self.width,
            self.height,
            BGFX_RESET_VSYNC,
            self.init_conf.resolution.format,
        )

        bgfx.set_debug(BGFX_DEBUG_TEXT)
        bgfx.set_view_clear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF,
                            1.0, 0)

        self.vertex_layout = bgfx.VertexLayout()
        self.vertex_layout.begin().add(
            bgfx.Attrib.POSITION, 3,
            bgfx.AttribType.FLOAT).add(bgfx.Attrib.COLOR0, 4,
                                       bgfx.AttribType.UINT8,
                                       True).add(bgfx.Attrib.TEXCOORD0, 2,
                                                 bgfx.AttribType.FLOAT).end()

        # Create static vertex buffer
        vb_memory = bgfx.copy(as_void_ptr(cube_vertices),
                              sizeof(PosColorTexVertex) * num_vertices)
        self.vertex_buffer = bgfx.create_vertex_buffer(vb_memory,
                                                       self.vertex_layout)

        # Create index buffer
        ib_memory = bgfx.copy(as_void_ptr(cube_indices), cube_indices.nbytes)
        self.index_buffer = bgfx.create_index_buffer(ib_memory)

        # Create texture uniform
        self.texture_uniform = bgfx.create_uniform("s_tex",
                                                   bgfx.UniformType.SAMPLER)

        # Load the image using PIL and make the texture
        logo = Image.open(
            Path(__file__).parent.parent / "assets" / "textures" /
            "python_logo.png")
        logo_memory = bgfx.copy(as_void_ptr(logo.tobytes()),
                                len(logo.tobytes()))
        self.logo_texture = bgfx.create_texture2d(logo.width, logo.height,
                                                  False, 1,
                                                  bgfx.TextureFormat.RGBA8,
                                                  BGFX_TEXTURE_RT, logo_memory)

        # Create program from shaders.
        self.main_program = bgfx.create_program(
            load_shader("textures.VertexShader.vert",
                        ShaderType.VERTEX,
                        root_path=root_path),
            load_shader("textures.FragmentShader.frag",
                        ShaderType.FRAGMENT,
                        root_path=root_path),
            True,
        )

        ImGuiExtra.imgui_create()
Ejemplo n.º 3
0
 def _load_compute_kernels(self):
     self._add_particles_kernel = bgfx.createProgram(
         load_shader("shader.AddParticle.comp",
                     ShaderType.COMPUTE,
                     root_path=root_path),
         True,
     )
     self._advect_particles_kernel = bgfx.createProgram(
         load_shader("shader.AdvectParticle.comp",
                     ShaderType.COMPUTE,
                     root_path=root_path),
         True,
     )
Ejemplo n.º 4
0
    def init(self, platform_data):
        self.init_conf.platform_data = platform_data
        bgfx.render_frame()
        bgfx.init(self.init_conf)
        bgfx.reset(
            self.width,
            self.height,
            BGFX_RESET_VSYNC,
            self.init_conf.resolution.format,
        )

        bgfx.set_debug(BGFX_DEBUG_TEXT)
        bgfx.set_view_clear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF,
                            1.0, 0)

        self.vertex_layout = bgfx.VertexLayout()
        self.vertex_layout.begin().add(bgfx.Attrib.POSITION, 3,
                                       bgfx.AttribType.FLOAT).add(
                                           bgfx.Attrib.COLOR0, 4,
                                           bgfx.AttribType.UINT8, True).end()

        # Create static vertex buffer
        vb_memory = bgfx.copy(as_void_ptr(cube_vertices),
                              sizeof(PosColorVertex) * num_vertices)
        self.vertex_buffer = bgfx.create_vertex_buffer(vb_memory,
                                                       self.vertex_layout)

        self.index_buffers = []

        for i in range(0, len(primitives)):
            ib_memory = bgfx.copy(as_void_ptr(primitives[i]),
                                  primitives[i].nbytes)
            self.index_buffers.append(bgfx.create_index_buffer(ib_memory))

        # Create program from shaders.
        self.main_program = bgfx.create_program(
            load_shader("cubes.VertexShader.vert",
                        ShaderType.VERTEX,
                        root_path=root_path),
            load_shader("cubes.FragmentShader.frag",
                        ShaderType.FRAGMENT,
                        root_path=root_path),
            True,
        )

        ImGuiExtra.imgui_create()
Ejemplo n.º 5
0
 def _load_compute_kernels(self):
     self._add_velocity_kernel = bgfx.createProgram(
         load_shader(
             "shader.AddVelocity.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
     self._init_boundaries_kernel = bgfx.createProgram(
         load_shader(
             "shader.InitBoundaries.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
     self._advect_velocity_kernel = bgfx.createProgram(
         load_shader(
             "shader.AdvectVelocity.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
     self._divergence_kernel = bgfx.createProgram(
         load_shader(
             "shader.Divergence.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
     self._poisson_kernel = bgfx.createProgram(
         load_shader("shader.Poisson.comp", ShaderType.COMPUTE, root_path=root_path),
         True,
     )
     self._subtract_gradient_kernel = bgfx.createProgram(
         load_shader(
             "shader.SubtractGradient.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
     self._calc_vorticity_kernel = bgfx.createProgram(
         load_shader(
             "shader.CalcVorticity.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
     self._apply_vorticity_kernel = bgfx.createProgram(
         load_shader(
             "shader.ApplyVorticity.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
     self._add_circle_obstacle_kernel = bgfx.createProgram(
         load_shader(
             "shader.AddCircleObstacle.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
     self._add_triangle_obstacle_kernel = bgfx.createProgram(
         load_shader(
             "shader.AddTriangleObstacle.comp",
             ShaderType.COMPUTE,
             root_path=root_path,
         ),
         True,
     )
     self._clear_buffer_kernel = bgfx.createProgram(
         load_shader(
             "shader.ClearBuffer.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
     self._viscosity_kernel = bgfx.createProgram(
         load_shader(
             "shader.Viscosity.comp", ShaderType.COMPUTE, root_path=root_path
         ),
         True,
     )
Ejemplo n.º 6
0
    def init(self, platform_data):
        self.init_conf.platformData = platform_data

        bgfx.init(self.init_conf)
        bgfx.reset(
            self.fb_width,
            self.fb_height,
            BGFX_RESET_VSYNC | BGFX_RESET_HIDPI,
            self.init_conf.resolution.format,
        )

        bgfx.setDebug(BGFX_DEBUG_TEXT)
        bgfx.setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF, 1.0, 0)

        self.vertex_layout = bgfx.VertexLayout()
        self.vertex_layout.begin().add(
            bgfx.Attrib.Position, 3, bgfx.AttribType.Float
        ).add(bgfx.Attrib.TexCoord0, 3, bgfx.AttribType.Float).end()

        self.fluid_simulator = FluidSimulator(
            self.width // 2, self.height // 2, self.vertex_layout
        )
        self.fluid_simulator.vorticity = 1.0
        self.fluid_simulator.viscosity = 0.0
        self.fluid_simulator.iterations = 100

        self.particle_area = SmoothParticlesArea(
            self.fb_width, self.fb_height, self.fluid_simulator, self.vertex_layout
        )
        self.particle_area.dissipation = 0.980

        # Create static vertex buffer
        vb_memory = bgfx.copy(as_void_ptr(cube_vertices), sizeof(PosColorVertex) * 4)
        self.vertex_buffer = bgfx.createVertexBuffer(vb_memory, self.vertex_layout)

        ib_memory = bgfx.copy(as_void_ptr(cube_indices), cube_indices.nbytes)
        self.index_buffer = bgfx.createIndexBuffer(ib_memory)

        self.output_texture = bgfx.createTexture2D(
            self.fb_width,
            self.fb_height,
            False,
            1,
            bgfx.TextureFormat.RGBA8,
            BGFX_TEXTURE_COMPUTE_WRITE,
        )

        self.texture_uniform = bgfx.createUniform(
            "InputTexture", bgfx.UniformType.Sampler
        )

        # Create program from shaders.
        self.main_program = bgfx.createProgram(
            load_shader(
                "demo.VertexShader.vert", ShaderType.VERTEX, root_path=root_path
            ),
            load_shader(
                "demo.FragmentShader.frag", ShaderType.FRAGMENT, root_path=root_path
            ),
            True,
        )
        self.cs_program = bgfx.createProgram(
            load_shader(
                "demo.ComputeShader.comp", ShaderType.COMPUTE, root_path=root_path
            ),
            True,
        )

        ImGuiExtra.imguiCreate(36.0)