Skip to content

Instantly share code, notes, and snippets.

@Pokechu22
Last active April 17, 2021 04:32
Show Gist options
  • Save Pokechu22/dac1a542f6b99ef0b4140564b5d118fc to your computer and use it in GitHub Desktop.
Save Pokechu22/dac1a542f6b99ef0b4140564b5d118fc to your computer and use it in GitHub Desktop.
Dolphin Luigi's Mansion portrait indirect texture issue
build/
indtest.elf
*.dff

Adapted from my normalize test case, in turn adapted from libogc texturetest.

I've updated this test to save screenshots to an SD card (using code borrowed from the Open Homebrew Channel), and run it on console and in Dolphin with the OGL renderer. Since I'm using libpng to save it in the homebrew itself, it can be a bit slow. The test also goes through all combinations of 0-2 tex gens, and the direct and indirect textures each using tex coord indices 0 through 2 (note that 2 is always out of bounds).

The results are in Results_HW.7z, Results_OGL.7z, and Differences.7z. The last one is the hardware and OGL results xord'd using compare_images.py. Note that the OGL results are with the change from PR 8296.

One thing to note is that even in the in-bounds cases, Dolphin is slightly off; a few pixels are wrong in all cases. This also happens with the software renderer (which is off in slightly different places), though I didn't generate images for all cases for that.

Another oddity is that the first frame rendered is usually different from the later frames. This was much harder to see in my original test, but since I save screenshots on frames 0 and 15, it's pretty obvious here. I don't know if this is something that will actually come up on more complicated situations (at least for Luigi's Mansion, Mario isn't visible on the first frame). This manifests as one of the two triangles making up the square using different texture coordinates from the other. Sometimes this happens on frame 0 too (e.g. Ident_160x160_Normal_BC1_IC0_1TG_F00)

One last thing that happens is that with 0 tex gens, the result is always black. I'm not sure whether this is drawing being skipped, or the current color being used, or what.

Unfortunately, with how I designed this test, it's really hard for me to tell whether dolphin is doing things correctly. The indirect texture is always being applied and since I never get up to 3 tex gens, I can't tell whether the clamping is happening.

# Original implementation (bash), didn't give very nice results
# function compareImages {
# # $1 is input dir 1, $2 is input dir 2, $3 is output dir
# for file in $(cd $1; ls *.png); do
# # Uses imagemagick
# compare $1/$file $2/$file $3/$file
# done
# }
# I also tried https://stackoverflow.com/a/8505681 but it was WAY too slow
# From https://stackoverflow.com/a/45362102
import cv2
import os
import sys
assert len(sys.argv) == 4
dira = sys.argv[1]
dirb = sys.argv[2]
outdir = sys.argv[3]
for f in os.listdir(dira):
if f.lower().endswith("png"):
a = cv2.imread(os.path.join(dira, f))
b = cv2.imread(os.path.join(dirb, f))
cv2.imwrite(os.path.join(outdir, f), cv2.bitwise_xor(a, b))
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
.SECONDARY:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
include $(DEVKITPPC)/wii_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := .
DATA :=
TEXTURES := .
INCLUDES :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS = $(CFLAGS)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -logc -lm -lfat -lpng -lz
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
$(foreach dir,$(TEXTURES),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf)))
TPLFILES := $(SCFFILES:.scf=.tpl)
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES)))
#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC)
#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
-L$(LIBOGC_LIB)
export OUTPUT := $(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)
$(OFILES_SOURCES) : $(HFILES)
#---------------------------------------------------------------------------------
# This rule links in binary data with the .bin extension
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
%.tpl.o %_tpl.h : %.tpl
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
run:
wiiload $(TARGET).dol
This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment