Skip to content

Commit

Permalink
Start adding KTX2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Naxela committed Sep 30, 2024
1 parent 6e9e3a8 commit 8b45043
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addon/panels/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ def draw(self, context):
if sceneProperties.tlm_encoding_mode_a == "HDR":
row = layout.row(align=True)
row.prop(sceneProperties, "tlm_format")

if(sceneProperties.tlm_format == "KTX"):
row = layout.row(align=True)
row.prop(sceneProperties, "tlm_ktx_path")
else:

if sceneProperties.tlm_encoding_mode_b == "RGBM":
Expand Down
7 changes: 7 additions & 0 deletions addon/properties/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class TLM_SceneProperties(bpy.types.PropertyGroup):
description="Supersamples the baked lightmap. Increases bake time",
default="2x")

tlm_ktx_path : StringProperty(
name="KTX Path",
description="The path to the KTX2 binaries",
default="",
subtype="FILE_PATH")

tlm_setting_savedir : StringProperty(
name="Lightmap Directory",
description="Your baked lightmaps will be stored here.",
Expand Down Expand Up @@ -293,6 +299,7 @@ class TLM_SceneProperties(bpy.types.PropertyGroup):

tlm_format : EnumProperty(
items = [('RGBE', 'HDR', '32-bit RGBE encoded .hdr files. No compression available.'),
('KTX', 'KTX', 'KTX2 Format'),
('EXR', 'EXR', '32-bit OpenEXR format.')],
name = "Format",
description="Select default 32-bit format",
Expand Down
54 changes: 54 additions & 0 deletions addon/utility/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,56 @@ def begin_build():

if sceneProperties.tlm_encoding_mode_a == "HDR":

if sceneProperties.tlm_format == "KTX":

tlm_log.append("KTX Format")
if bpy.context.scene.TLM_SceneProperties.tlm_verbose:

print("KTX Format")

ren = bpy.context.scene.render
ren.image_settings.file_format = "OPEN_EXR"
#ren.image_settings.exr_codec = "scene.TLM_SceneProperties.tlm_exr_codec"

end = "_baked"

baked_image_array = []

if sceneProperties.tlm_denoise_use:

end = "_denoised"

if sceneProperties.tlm_filtering_use:

end = "_filtered"

#For each image in folder ending in denoised/filtered
dirfiles = [f for f in listdir(dirpath) if isfile(join(dirpath, f))]

for file in dirfiles:
if file.endswith(end + ".hdr"):

img = bpy.data.images.load(os.path.join(dirpath,file))
img.save_render(img.filepath_raw[:-4] + ".exr")

if(sceneProperties.tlm_ktx_path != ""):

ktx_path = sceneProperties.tlm_ktx_path
exr_path = img.filepath_raw[:-4] + ".exr"

# Build the KTX command
ktx_command = [
ktx_path,
"create",
"--format", "R32G32B32A32_SFLOAT",
exr_path,
exr_path[:-4] + ".ktx2"
]

# Execute the KTX conversion command
subprocess.run(ktx_command, check=True)
print(f"Converted {exr_path} to KTX2 format.")

if sceneProperties.tlm_format == "EXR":

tlm_log.append("EXR Format")
Expand Down Expand Up @@ -799,6 +849,10 @@ def manage_build(background_pass=False, load_atlas=0):

if sceneProperties.tlm_encoding_mode_b == "HDR":

if sceneProperties.tlm_format == "KTX":

formatEnc = ".ktx2"

if sceneProperties.tlm_format == "EXR":

formatEnc = ".exr"
Expand Down

0 comments on commit 8b45043

Please sign in to comment.