Example #1
0
 def __init__(self):
     Image.__init__(self, "gem.png")
Example #2
0
 def __init__(self, viewport):
     Image.__init__(self, "frame256.png")
     self.viewport = viewport
    def _setup_assets(self):
        scene = self.scene

        # Images
        helmet_f = KTXFile.open("damaged_helmet.ktx")
        helmet_f = helmet_f.slice_array(slice(2,
                                              3))  # Only keep the normal maps
        helmet_f = helmet_f[1:2]  # Only keep the first mipmap
        helmet_f.cast_single(
        )  # Interpret the image as a single texture (not an array)
        helmet_maps = Image.from_ktx(helmet_f, name="HelmetTextureMaps")

        # Sampler
        helmet_sampler = Sampler.from_params(
            max_lod=helmet_maps.mipmaps_levels)

        # Shaders
        shader_normals_map = {
            "POSITION": "pos",
            "NORMAL": "normal",
            "TANGENT": "tangent",
            "TEXCOORD_0": "uv"
        }
        shader2_normals_map = {
            "POSITION": "pos",
            "NORMAL": "normal",
            "TEXCOORD_0": "uv"
        }

        shader_normals = Shader.from_files(
            f"debug_normals/debug_normals.vert.spv",
            f"debug_normals/debug_normals.frag.spv",
            f"debug_normals/debug_normals.map.json",
            name="DebugNormals")

        shader2_normals = Shader.from_files(
            f"debug_normals2/debug_normals2.vert.spv",
            f"debug_normals2/debug_normals2.frag.spv",
            f"debug_normals2/debug_normals2.map.json",
            name="DebugNormalsNoTangent")

        shader_normals.uniforms.debug = {"debug1": (0, 1, 0, 0)}
        shader2_normals.uniforms.debug = {"debug1": (0, 1, 0, 0)}

        # Meshes
        helmet_m = Mesh.from_gltf(GLBFile.open("damaged_helmet.glb"),
                                  "HelmetMesh",
                                  attributes_map=shader_normals_map,
                                  name="HelmetMesh")
        helmet_m2 = Mesh.from_gltf(GLTFFile.open("DamagedHelmet.gltf"),
                                   "HelmetMesh",
                                   attributes_map=shader2_normals_map,
                                   name="HelmetMesh2")

        # Objects
        helmet = GameObject.from_components(shader=shader_normals.id,
                                            mesh=helmet_m.id,
                                            name="Helmet")
        helmet.model = Mat4.from_rotation(radians(360),
                                          (0, 1, 0)).translate(-1, 0, 0)
        helmet.uniforms.normal_maps = CombinedImageSampler(
            image_id=helmet_maps.id,
            view_name="default",
            sampler_id=helmet_sampler.id)

        helmet2 = GameObject.from_components(shader=shader2_normals.id,
                                             mesh=helmet_m2.id,
                                             name="Helmet")
        helmet2.model = Mat4().from_rotation(radians(90),
                                             (1, 0, 0)).translate(1, 0, 0)
        helmet2.uniforms.normal_maps = CombinedImageSampler(
            image_id=helmet_maps.id,
            view_name="default",
            sampler_id=helmet_sampler.id)

        scene.shaders.extend(shader_normals, shader2_normals)
        scene.meshes.extend(helmet_m, helmet_m2)
        scene.images.extend(helmet_maps)
        scene.samplers.extend(helmet_sampler)
        scene.objects.extend(helmet, helmet2)

        self.objects = (
            helmet,
            helmet2,
        )
        self.shaders = (shader_normals, shader2_normals)
Example #4
0
    def _setup_assets(self):
        scene = self.scene

        # Images
        helmet_f = KTXFile.open("damaged_helmet.ktx")
        if __debug__:
            helmet_f = helmet_f[
                2:
                3]  # Speed up load time by only keeping a low res mipmap in debug mode

        specular_env_f = KTXFile.open("storm/specular_cubemap.ktx")
        irradiance_env_f = KTXFile.open("storm/irr_cubemap.ktx")

        with (IMAGE_PATH / "brdf.bin").open("rb") as f:
            brdf_args = {
                "format": vk.FORMAT_R16G16_UNORM,
                "extent": (128, 128, 1),
                "default_view_type": vk.IMAGE_VIEW_TYPE_2D
            }
            brdf_f = f.read()

        helmet_i = Image.from_ktx(helmet_f, name="HelmetTextureMaps")
        brdf_i = Image.from_uncompressed(brdf_f, name="BRDF", **brdf_args)
        env_i = Image.from_ktx(specular_env_f, name="CubemapTexture")
        env_irr_i = Image.from_ktx(irradiance_env_f,
                                   name="CubemapIrradianceTexture")

        # Sampler
        brdf_s = Sampler.new()
        env_s = Sampler.from_params(max_lod=env_i.mipmaps_levels)
        helmet_s = Sampler.from_params(max_lod=helmet_i.mipmaps_levels)

        # Shaders
        n = "pbr2/pbr2"
        shader_map = {
            "POSITION": "pos",
            "NORMAL": "normal",
            "TEXCOORD_0": "uv"
        }
        shader = Shader.from_files(f"{n}.vert.spv",
                                   f"{n}.frag.spv",
                                   f"{n}.map.json",
                                   name="PBRShader")

        color_factor = 1.0
        emissive_factor = 1.0
        exposure = 1.5
        gamma = 2.2

        shader.uniforms.render = {
            "light_color": (1.0, 1.0, 1.0),
            "env_lod": (0, env_i.mipmaps_levels),
            "factors": (color_factor, emissive_factor, exposure, gamma)
        }

        shader.uniforms.brdf = CombinedImageSampler(image_id=brdf_i.id,
                                                    view_name="default",
                                                    sampler_id=brdf_s.id)
        shader.uniforms.env_specular = CombinedImageSampler(
            image_id=env_i.id, view_name="default", sampler_id=env_s.id)
        shader.uniforms.env_irradiance = CombinedImageSampler(
            image_id=env_irr_i.id, view_name="default", sampler_id=brdf_s.id)

        # Meshes
        helmet_m = Mesh.from_gltf(GLTFFile.open("DamagedHelmet.gltf"),
                                  "HelmetMesh",
                                  attributes_map=shader_map,
                                  name="HelmetMesh")

        # Objects
        helmet = GameObject.from_components(shader=shader.id,
                                            mesh=helmet_m.id,
                                            name="Helmet")
        helmet.model = Mat4().from_rotation(radians(90), (1, 0, 0))
        helmet.uniforms.texture_maps = CombinedImageSampler(
            image_id=helmet_i.id, view_name="default", sampler_id=helmet_s.id)

        # Packing
        scene.images.extend(helmet_i, brdf_i, env_i, env_irr_i)
        scene.samplers.extend(helmet_s, brdf_s, env_s)
        scene.shaders.extend(shader)
        scene.meshes.extend(helmet_m)
        scene.objects.extend(helmet)

        self.objects = (helmet, )
        self.shaders = (shader, )
    def _setup_assets(self):
        scene = self.scene
        engine = self.engine

        # Images
        w, h = self.heightmap_size
        heightmap_i = Image.empty(
            name = "HeightmapImage",
            extent=(w, h, 1),
            format=vk.FORMAT_R8G8B8A8_SNORM,
            usage=DEFAULT_IMAGE_USAGE | vk.IMAGE_USAGE_STORAGE_BIT,
            default_view_type=vk.IMAGE_VIEW_TYPE_2D,
            layout=ImageLayout.ShaderWrite
        )

        placeholder_i = Image.empty(
            name = "PlaceholderImage",
            extent=(1,1,1),
            format=vk.FORMAT_R8G8B8A8_SNORM,
            default_view_type=vk.IMAGE_VIEW_TYPE_2D
        )

        # Samplers
        heightmap_sm = Sampler.from_params(
            address_mode_V=vk.SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
            address_mode_U=vk.SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
            mag_filter=vk.FILTER_NEAREST,
            min_filter=vk.FILTER_NEAREST
        )

        # Shaders
        dt = "debug_texture/debug_texture"
        debug_texture_attributes_map = {"POSITION": "pos", "TEXCOORD_0": "uv"}
        debug_texture_s = Shader.from_files(f"{dt}.vert.spv",  f"{dt}.frag.spv", f"{dt}.map.json", name="DebugTexture")

        # Compute shaders
        compute_queue = "render"
        if "compute" in engine.queues:
            compute_queue = "compute"

        ch = "compute_heightmap/compute_heightmap"
        local_x, local_y = self.compute_local_size
        compute_heightmap_c = Compute.from_file(f"{ch}.comp.spv", f"{ch}.map.json", name="ComputeHeightmap", queue=compute_queue)
        compute_heightmap_c.set_constant("local_size_x", local_x)
        compute_heightmap_c.set_constant("local_size_y", local_y)
        compute_heightmap_c.uniforms.heightmap = CombinedImageSampler(image_id=heightmap_i.id, view_name="default", sampler_id=heightmap_sm.id)

        # Meshes
        plane_m = Mesh.from_prefab(MeshPrefab.Plane, attributes_map=debug_texture_attributes_map, name="PlaneMesh")
        
        # Game objects
        preview_heightmap_o = GameObject.from_components(shader = debug_texture_s.id, mesh = plane_m.id, name = "ObjTexture")
        preview_heightmap_o.model = Mat4()
        preview_heightmap_o.uniforms.color_texture = CombinedImageSampler(image_id=placeholder_i.id, view_name="default", sampler_id=heightmap_sm.id)

        scene.images.extend(heightmap_i, placeholder_i)
        scene.samplers.extend(heightmap_sm)
        scene.shaders.extend(debug_texture_s)
        scene.computes.extend(compute_heightmap_c)
        scene.meshes.extend(plane_m)
        scene.objects.extend(preview_heightmap_o)

        self.objects = (preview_heightmap_o,)
        self.shaders = ()
        self.compute_heightmap = compute_heightmap_c
        self.heightmap_texture = heightmap_i
        self.heightmap_sampler = heightmap_sm
        self.heightmap_preview = preview_heightmap_o
Example #6
0
    sigma = np.array([[[7.72925584e-01, 5.23305564e-02],
                       [5.23305564e-02, 8.89078473e-01]],
                      [[9.84585869e+00, 7.79378820e-01],
                       [7.79378820e-01, 8.84764455e+00]],
                      [[2.02664489e+02, -8.16667434e-01],
                       [-8.16667434e-01, 1.87881670e+02]]])

    psf = GaussianMixturePSF(w, mu, sigma)

    shape = GalaxyShape(10., 0.5, 30.)
    pos = PixPos(100, 50)
    bright = Flux(1000.)
    egal = ExpGalaxy(pos, bright, shape)

    data = np.zeros((100, 200))
    tim = Image(data=data, psf=psf)

    p0 = egal.getModelPatch(tim)

    p1 = egal.getModelPatch(tim, 1e-3)

    bright.setParams([100.])

    p2 = egal.getModelPatch(tim, 1e-3)

    print 'p0', p0.patch.sum()
    print 'p1', p1.patch.sum()
    print 'p2', p2.patch.sum()

    plt.clf()
    ima = dict(interpolation='nearest', origin='lower')
    def _setup_assets(self):
        scene = self.scene

        # Textures
        texture = Image.from_ktx(KTXFile.open("vulkan_logo.ktx"), name="Texture")
        array_texture = Image.from_ktx(KTXFile.open("array_test.ktx"), name="ArrayTexture")
        cubemap_texture = Image.from_ktx(KTXFile.open("storm/specular_cubemap.ktx"), name="CubemapTexture")
        
        with (IMAGE_PATH/"brdf.bin").open("rb") as f:
            texture_raw_data = f.read()
            texture_args = {"format": vk.FORMAT_R16G16_UNORM, "extent": (128, 128, 1), "default_view_type": vk.IMAGE_VIEW_TYPE_2D}
            raw_texture = Image.from_uncompressed(texture_raw_data, name="TextureRaw", **texture_args)

        # Samplers
        sampler = Sampler.from_params(
            address_mode_V=vk.SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
            address_mode_U=vk.SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
        )

        sampler_lod = Sampler.from_params(
            address_mode_V=vk.SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
            address_mode_U=vk.SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
            max_lod=cubemap_texture.mipmaps_levels
        )


        # Shaders
        simple_name = "debug_texture/debug_texture"
        array_name = "debug_texture_array/debug_texture_array"
        cube_name = "debug_texture_cube/debug_texture_cube"
        
        shader_attributes_map = {"POSITION": "pos", "TEXCOORD_0": "uv"}

        shader_simple = Shader.from_files(f"{simple_name}.vert.spv",  f"{simple_name}.frag.spv", f"{simple_name}.map.json", name="DebugTexture")
        shader_array = Shader.from_files(f"{array_name}.vert.spv",  f"{array_name}.frag.spv", f"{array_name}.map.json", name="DebugArrayTexture")
        shader_cube = Shader.from_files(f"{cube_name}.vert.spv",  f"{cube_name}.frag.spv", f"{cube_name}.map.json", name="DebugCubeTexture")

        # Meshes
        plane_m = Mesh.from_prefab(MeshPrefab.Plane, attributes_map=shader_attributes_map, invert_y=True, name="PlaneMesh")
        plane_m2 = Mesh.from_prefab(MeshPrefab.Plane, attributes_map=shader_attributes_map, name="PlaneMesh")
        sphere_m = Mesh.from_gltf(GLBFile.open("test_sphere.glb"), "Sphere.001", attributes_map=shader_attributes_map, name="SphereMesh")

        # Objects
        plane1 = GameObject.from_components(shader = shader_simple.id, mesh = plane_m.id, name = "ObjTexture")
        plane1.model = Mat4()
        plane1.uniforms.color_texture = CombinedImageSampler(image_id=texture.id, view_name="default", sampler_id=sampler.id)

        plane2 = GameObject.from_components(shader = shader_simple.id, mesh = plane_m2.id, name = "ObjRawTexture", hidden=True)
        plane2.model = Mat4()
        plane2.uniforms.color_texture = CombinedImageSampler(image_id=raw_texture.id, view_name="default", sampler_id=sampler.id)

        plane3 = GameObject.from_components(shader = shader_array.id, mesh = plane_m.id, name = "ObjArrayTexture", hidden=True)
        plane3.model = Mat4()
        plane3.uniforms.color_texture = CombinedImageSampler(image_id=array_texture.id, view_name="default", sampler_id=sampler.id)

        sphere = GameObject.from_components(shader = shader_cube.id, mesh = sphere_m.id, name = "ObjCubeTexture", hidden=True)
        sphere.model = Mat4.from_rotation(radians(180), (1, 0, 0))
        sphere.uniforms.cube_texture = CombinedImageSampler(image_id=cubemap_texture.id, view_name="default", sampler_id=sampler_lod.id)
        
        # Add objects to scene
        scene.shaders.extend(shader_simple, shader_array, shader_cube)
        scene.samplers.extend(sampler, sampler_lod)
        scene.images.extend(texture, array_texture, raw_texture, cubemap_texture)
        scene.meshes.extend(plane_m, plane_m2, sphere_m)
        scene.objects.extend(plane1, plane2, plane3, sphere)

        self.cubemap_max_mipmap = cubemap_texture.mipmaps_levels
        self.visible_index = 0
        self.objects.extend((plane1, plane2, plane3, sphere))