Skip to content

Commit

Permalink
Prefer CI over rgba toggle for automatic texture format
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Jan 18, 2024
1 parent 37aacff commit def0655
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def draw(self, context):
prop_split(col, context.scene, "gameEditorMode", "Game")
col.prop(context.scene, "exportHiddenGeometry")
col.prop(context.scene, "fullTraceback")
col.prop(context.scene.fast64.settings, "prefer_ci_over_rgba")
prop_split(col, context.scene.fast64.settings, "anim_range_choice", "Anim Range")


Expand Down Expand Up @@ -267,6 +268,7 @@ class Fast64Settings_Properties(bpy.types.PropertyGroup):
],
default="intersect_action_and_scene",
)
prefer_ci_over_rgba: bpy.props.BoolProperty(name="Prefer Color Indexed Over RGBA")


class Fast64_Properties(bpy.types.PropertyGroup):
Expand Down
14 changes: 7 additions & 7 deletions fast64_internal/f3d/f3d_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -3377,7 +3377,7 @@ def getOptimalFormat(tex, curFormat, isMultitexture):
isGreyscale = True
hasAlpha4bit = False
hasAlpha1bit = False
pixelValues = []
pixelValues = set()

# N64 is -Y, Blender is +Y
pixels = tex.pixels[:]
Expand All @@ -3392,12 +3392,11 @@ def getOptimalFormat(tex, curFormat, isMultitexture):
hasAlpha4bit = True
if color[3] < 0.5:
hasAlpha1bit = True
pixelColor = getRGBA16Tuple(color)
if pixelColor not in pixelValues:
pixelValues.append(pixelColor)
pixelValues.add(getRGBA16Tuple(color))

tex_size = tex.size[0] * tex.size[1]
if isGreyscale:
if tex.size[0] * tex.size[1] > 4096:
if tex_size > 4096:
if not hasAlpha1bit:
texFormat = "I4"
else:
Expand All @@ -3408,9 +3407,10 @@ def getOptimalFormat(tex, curFormat, isMultitexture):
else:
texFormat = "IA8"
else:
if len(pixelValues) <= 16:
prefer_ci_over_rgba = bpy.context.scene.fast64.settings.prefer_ci_over_rgba
if (prefer_ci_over_rgba and len(pixelValues) <= 16) or (len(pixelValues) <= 16 and tex_size > 2048):
texFormat = "CI4"
elif len(pixelValues) <= 256 and tex.size[0] * tex.size[1] <= 2048:
elif prefer_ci_over_rgba and len(pixelValues) <= 256 and tex_size <= 2048:
texFormat = "CI8"
else:
texFormat = "RGBA16"
Expand Down

0 comments on commit def0655

Please sign in to comment.