hulkholden / n64js

An n64 emulator in JavaScript
MIT License
616 stars 76 forks source link

Incorrect texture wrapping in Super Mario 64 #13

Open hulkholden opened 1 year ago

hulkholden commented 1 year ago

example of wrapping problem exmaple of wrapping problem

The textures themselves are being decoded ok

star texture

The tiles are configured with G_TX_WRAP at 16 pixels:

tile # format size line tmem palette cmS maskS shiftS cmT maskT shiftT left top right bottom width height unmasked w unmasked h
G_TX_RENDERTILE G_IM_FMT_RGBA G_IM_SIZ_16b 4 0 0 G_TX_WRAP 4 0 G_TX_WRAP 4 0 0 0 15 15 16 16 16 16
G_TX_LOADTILE G_IM_FMT_RGBA G_IM_SIZ_16b 0 0 0 G_TX_WRAP 4 0 G_TX_WRAP 4 0 0 0 0 0 1 1 1 1

RDP is set up with bilinear filtering:

setting value
textureConvert G_TC_FILT
textureFilter G_TF_BILERP

In the case of the star it's being rendered with texrect:

02636 e4404078003c803c gsSPTextureRectangle(242,15,258,31,G_TX_RENDERTILE,0,0,1,1);
cmd2 = 0x00000000, cmd3 = 0x10000400
st0 = (0, 0) st1 = (16, 16)

Some possibilities:

hulkholden commented 1 year ago

Also worth mentioning this is G_CYC_COPY. In this mode we're adding 1 to the width and height:

    // In Fill/Copy mode the coordinates are inclusive (i.e. add 1.0f to the w/h)
    if (cycleType === gbi.CycleType.G_CYC_COPY ||
      cycleType === gbi.CycleType.G_CYC_FILL) {
      xh += 1.0;
      yh += 1.0;
    }