Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture writing overhaul #194

Merged
merged 52 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3a327cf
Added warning and error if CI formats not compatible, moved setting f…
sauraen Nov 27, 2022
1f255cc
Added not actually reloading tex 1 if same as tex 0
sauraen Nov 27, 2022
2f185a5
Fixed bug in not loading tex 1 change
sauraen Nov 27, 2022
a44b1c8
added hashing to gbi base classes
Nov 28, 2022
14b097e
Almost done refactoring texture writing code
sauraen Nov 29, 2022
2863fdc
Initial incomplete draft of texture rewrite
sauraen Dec 3, 2022
c470358
Merge remote-tracking branch 'fast64/main' into fast64_main
Dec 4, 2022
d4df077
Draft of texture saving changes
sauraen Dec 11, 2022
7bfc073
Converted exportTexRectCommon
sauraen Dec 11, 2022
830a723
Merged main, but flipbook not converted
sauraen Dec 12, 2022
99e3d1d
Converting flipbook
sauraen Dec 12, 2022
a404a57
Converting flipbook
sauraen Dec 12, 2022
dbaf27c
Finished draft of converting flipbook
sauraen Dec 14, 2022
9239631
blacked
sauraen Dec 14, 2022
bc1352b
Exporting mat with two CI4 textures seems to work
sauraen Dec 14, 2022
88dd3d6
Merge remote-tracking branch 'fast64/main' into fast64_main
Dec 17, 2022
2df33f9
Merge remote-tracking branch 'origin/main' into CITexFixes
sauraen Dec 21, 2022
32bfeaf
Merge remote-tracking branch 'fast64/main' into fast64_main
Dec 23, 2022
f3b4895
Draft working, not tested large textures or flipbooks yet
sauraen Dec 26, 2022
aa69414
Updated surface sound names
sauraen Jan 13, 2023
6ba397e
Basic large textures working
sauraen Jan 16, 2023
b12dd1c
In progress TileLoad supporting wrapping
sauraen Jan 17, 2023
cc805b5
Loads across wrap boundaries implemented but not tested
sauraen Jan 18, 2023
8dbb18f
Merge remote-tracking branch 'fast64/main' into fast64_main
Jan 19, 2023
dabffe7
Seamless tiling of large textures working
sauraen Jan 20, 2023
617791b
Working on large texture mesh operator
sauraen Jan 21, 2023
1081be3
Fixed some formatting
sauraen Jan 21, 2023
e5494cf
Working on large texture mesh creation
sauraen Jan 22, 2023
b7f522e
Large texture mesh generation working
sauraen Jan 23, 2023
9bf6e9b
Merge remote-tracking branch 'fast64/main' into fast64_main
Jan 27, 2023
658bb3b
Merged main
sauraen Feb 7, 2023
933f0f4
Some bugfixes with changes to flipbook texture writing
sauraen Feb 7, 2023
d9a87e6
Flipbook export mostly working
sauraen Feb 8, 2023
f2ee0a5
Some flipbook fixes
sauraen Feb 8, 2023
bb67fe3
Fixed bug with reused textures between multiple flipbooks
sauraen Feb 11, 2023
ddb75cb
PR nearly done, just have to reorganize
sauraen Feb 12, 2023
7fad88d
Draft of refactor
sauraen Feb 13, 2023
2311789
Fixes to refactor
sauraen Feb 13, 2023
a801054
Applied black
sauraen Feb 13, 2023
e93d808
Made changes for dragorn
sauraen Feb 14, 2023
7259fd1
Merge remote-tracking branch 'fast64/main' into fast64_main
Feb 19, 2023
80fffe8
merge fixes for mat bleed PR
Feb 19, 2023
57a7124
Merge remote-tracking branch 'fast64/main' into tex_writer_fixes
Feb 19, 2023
a096c1f
updated instances of use large textures with checking large texture u…
Feb 19, 2023
c3962ed
re-wrote tile bleed to work with new texture writer, and made all tex…
Mar 17, 2023
2238313
tile scroll gfx tag only will apply if tile scroll exists in material
Mar 17, 2023
c0089b1
Fixed superfluous passing of loadGfx to writeAll
sauraen Mar 19, 2023
6d87d4d
Merge pull request #1 from jesusyoshi54/tex_writer_fixes
sauraen Mar 19, 2023
2d574cc
Merge remote-tracking branch 'origin/main' into CITexFixes
sauraen Mar 19, 2023
e124a4d
added else statement to bleed case for textures when large textures a…
Apr 4, 2023
c87fc7c
Changes for cozies
sauraen Apr 4, 2023
0992a9d
Merge pull request #2 from jesusyoshi54/tex_writer_fixes
sauraen Apr 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ __pycache__/
.vscode
*.blend1
/.venv
fast64_updater/
.python-version

4 changes: 4 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .fast64_internal.f3d.f3d_writer import f3d_writer_register, f3d_writer_unregister
from .fast64_internal.f3d.f3d_parser import f3d_parser_register, f3d_parser_unregister
from .fast64_internal.f3d.flipbook import flipbook_register, flipbook_unregister
from .fast64_internal.f3d.op_largetexture import op_largetexture_register, op_largetexture_unregister, ui_oplargetexture

from .fast64_internal.f3d_material_converter import (
MatUpdateConvert,
Expand Down Expand Up @@ -225,6 +226,7 @@ def draw(self, context):
col = self.layout.column()
col.operator(ArmatureApplyWithMeshOperator.bl_idname)
# col.operator(CreateMetarig.bl_idname)
ui_oplargetexture(col, context)
addon_updater_ops.update_notice_box_ui(self, context)


Expand Down Expand Up @@ -457,6 +459,7 @@ def register():
f3d_writer_register()
flipbook_register()
f3d_parser_register()
op_largetexture_register()

# ROM

Expand Down Expand Up @@ -485,6 +488,7 @@ def register():
# called on add-on disabling
def unregister():
utility_anim_unregister()
op_largetexture_unregister()
flipbook_unregister()
f3d_writer_unregister()
f3d_parser_unregister()
Expand Down
100 changes: 61 additions & 39 deletions fast64_internal/f3d/f3d_bleed.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def bleed_fmesh(self, f3d: F3D, fMesh: FMesh, lastMat: FMaterial, cmd_list: GfxL
bleed_gfx_lists = BleedGfxLists()
if triGroup.fMaterial:
bleed_gfx_lists.bled_mats = self.bleed_mat(triGroup.fMaterial, lastMat, cmd_list, bleed_state)
if not triGroup.fMaterial.useLargeTextures:
if not (triGroup.fMaterial.isTexLarge[0] or triGroup.fMaterial.isTexLarge[1]):
bleed_gfx_lists.bled_tex = self.bleed_textures(triGroup.fMaterial, lastMat, cmd_list, bleed_state)
lastMat = triGroup.fMaterial
# bleed tri group (for large textures) and to remove other unnecessary cmds
Expand All @@ -80,42 +80,63 @@ def bleed_fmesh(self, f3d: F3D, fMesh: FMesh, lastMat: FMaterial, cmd_list: GfxL
self.on_bleed_end(f3d, lastMat, bleed_gfx_lists, cmd_list, default_render_mode)
return lastMat

def build_tmem_dict(self, cmd_list: GfxList):
im_buffer = None
tmem_dict = dict()
tile_dict = {i:0 for i in range(8)} # an assumption that hopefully never needs correction
thecozies marked this conversation as resolved.
Show resolved Hide resolved
for cmd in cmd_list.commands:
if type(cmd) == DPSetTextureImage:
im_buffer = cmd
continue
if type(cmd) == DPSetTile:
tile_dict[cmd.tile] = cmd.tmem
if type(cmd) in (DPLoadTLUTCmd, DPLoadTile, DPLoadBlock):
tmem_dict[tile_dict[cmd.tile]] = im_buffer
continue
return tmem_dict

def bleed_textures(self, curMat: FMaterial, lastMat: FMaterial, cmd_list: GfxList, bleed_state: int):
if lastMat:
bled_tex = []
# bleed cmds if matching tile has duplicate cmds
for j, (LastTex, TexCmds) in enumerate(zip(lastMat.texture_DLs, curMat.texture_DLs)):
# deep copy breaks on Image objects so I will only copy the levels needed
commands_bled = copy.copy(TexCmds)
commands_bled.commands = copy.copy(TexCmds.commands) # copy the commands also
lastList = LastTex.commands
# eliminate set tex images
set_tex = (c for c in TexCmds.commands if type(c) == DPSetTextureImage)
removed_tex = [c for c in set_tex if c in lastList] # needs to be a list to check "in" multiple times
rm_load = None # flag to elim loads once
for j, cmd in enumerate(TexCmds.commands):
# remove set tex explicitly
if cmd in removed_tex:
commands_bled.commands.remove(cmd)
rm_load = True
continue
if rm_load and type(cmd) in (DPLoadTLUTCmd, DPLoadTile, DPLoadBlock):
commands_bled.commands.remove(cmd)
rm_load = None
continue
# now eval as normal conditionals
iter_cmds = copy.copy(commands_bled.commands) # need extra list to iterate with
for j, cmd in enumerate(iter_cmds):
if self.bleed_individual_cmd(commands_bled, cmd, bleed_state):
if cmd in lastList:
commands_bled.commands[j] = None
# remove Nones from list
while None in commands_bled.commands:
commands_bled.commands.remove(None)
bled_tex.append(commands_bled)
# deep copy breaks on Image objects so I will only copy the levels needed
commands_bled = copy.copy(curMat.texture_DL)
commands_bled.commands = copy.copy(curMat.texture_DL.commands) # copy the commands also
# eliminate set tex images, but only if there is an overlap of the same image at the same tmem location
last_im_loads = self.build_tmem_dict(lastMat.texture_DL)
new_im_loads = self.build_tmem_dict(commands_bled)
removable_images = []
for tmem, image in new_im_loads.items():
if tmem in last_im_loads and last_im_loads[tmem] == image:
removable_images.append(image)
# now go through list and cull out loads for the specific cmds
# this will be the set tex image, and the loading cmds
rm_load = False
for j, cmd in enumerate(curMat.texture_DL.commands):
# remove set tex explicitly
if cmd in removable_images:
commands_bled.commands[j] = None
rm_load = True
continue
if rm_load and type(cmd) == DPSetTile:
commands_bled.commands[j] = None
if rm_load and type(cmd) in (DPLoadTLUTCmd, DPLoadTile, DPLoadBlock):
commands_bled.commands[j] = None
rm_load = None
continue
# now eval as normal conditionals
for j, cmd in enumerate(curMat.texture_DL.commands):
if not cmd:
continue # some cmds are None from previous step
if self.bleed_individual_cmd(commands_bled, cmd, bleed_state):
if cmd in lastMat.texture_DL.commands:
commands_bled.commands[j] = None
# remove Nones from list
while None in commands_bled.commands:
commands_bled.commands.remove(None)
bled_tex = commands_bled
else:
bled_tex = curMat.texture_DLs
return bled_tex
bled_tex = curMat.texture_DL
return bled_tex.commands

def bleed_mat(self, curMat: FMaterial, lastMat: FMaterial, cmd_list: GfxList, bleed_state: int):
if lastMat:
Expand All @@ -136,15 +157,15 @@ def bleed_mat(self, curMat: FMaterial, lastMat: FMaterial, cmd_list: GfxList, bl
# remove SPEndDisplayList
while SPEndDisplayList() in commands_bled.commands:
commands_bled.commands.remove(SPEndDisplayList())
return commands_bled
return commands_bled.commands

def bleed_tri_group(
self, f3d: F3D, triGroup: FTriGroup, bleed_gfx_lists: BleedGfxLists, cmd_list: GfxList, bleed_state: int
):
# remove SPEndDisplayList from triGroup
while SPEndDisplayList() in triGroup.triList.commands:
triGroup.triList.commands.remove(SPEndDisplayList())
if triGroup.fMaterial.useLargeTextures:
if (triGroup.fMaterial.isTexLarge[0] or triGroup.fMaterial.isTexLarge[1]):
triGroup.triList = self.bleed_cmd_list(triGroup.triList, bleed_state)

# this is a little less versatile than comparing by last used material
Expand All @@ -167,10 +188,9 @@ def bleed_cmd_list(self, target_cmd_list: GfxList, bleed_state: int):
# Put triGroup bleed gfx in the FMesh.draw object
def inline_triGroup(self, f3d: F3D, triGroup: FTriGroup, bleed_gfx_lists: BleedGfxLists, cmd_list: GfxList):
# add material
cmd_list.commands.extend(bleed_gfx_lists.bled_mats.commands)
cmd_list.commands.extend(bleed_gfx_lists.bled_mats)
# add textures
for tile, texGfx in enumerate(bleed_gfx_lists.bled_tex):
cmd_list.commands.extend(texGfx.commands)
cmd_list.commands.extend(bleed_gfx_lists.bled_tex)
# add in triangles
cmd_list.commands.extend(triGroup.triList.commands)
# skinned meshes don't draw tris sometimes, use this opportunity to save a sync
Expand Down Expand Up @@ -221,7 +241,9 @@ def bleed_individual_cmd(self, cmd_list: GfxList, cmd: GbiMacro, bleed_state: in
SPBranchLessZraw,
SPModifyVertex,
SPEndDisplayList,
DPSetTextureImage,
DPLoadBlock,
DPLoadTile,
DPLoadTLUTCmd,
DPFullSync,
]:
Expand Down Expand Up @@ -278,7 +300,7 @@ def bleed_DPLoadSync(self, cmd_list: GfxList, cmd: GbiMacro, bleed_state: int):
@dataclass
class BleedGfxLists:
bled_mats: GfxList = field(default_factory=list)
bled_tex: list[GfxList] = field(default_factory=list) # list of GfxList
bled_tex: GfxList = field(default_factory=list)
reset_cmds: set[GbiMacro] = field(default_factory=set) # set of cmds to reset

def __post_init__(self):
Expand Down
7 changes: 6 additions & 1 deletion fast64_internal/f3d/f3d_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
("TEXEL1", "Texture 1", "Texture 1"),
]

texBitSize = {
texBitSizeInt = {
"I4": 4,
"IA4": 4,
"CI4": 4,
Expand Down Expand Up @@ -364,3 +364,8 @@
("F3DEX2/LX2", "F3DEX2/LX2", "F3DEX2/LX2"),
("F3DEX2.Rej/LX2.Rej", "F3DEX2.Rej/LX2.Rej", "F3DEX2.Rej/LX2.Rej"),
]

enumLargeEdges = [
("Clamp", "Clamp", "Clamp outside image bounds"),
("Wrap", "Wrap", "Wrap outside image bounds (more expensive)"),
]
Loading