mkst / sm64-port

My mirror of the sm64-port. You probably want to look at the 3DS port branch: https://github.com/mkst/sm64-port/tree/3ds-port
https://discord.gg/7bcNTPK
251 stars 34 forks source link

BUG - Jolly Roger Bay Walls alpha #3

Closed mkst closed 4 years ago

mkst commented 4 years ago

The tops of the walls should be transparent.

3DS: image

N64: TODO

"It's an alphacompare" - Fazana.

More info to be added as it's discovered.

Edit 1

Increasing the threshold for alpha affects this:

    if (cc_features.opt_texture_edge && cc_features.opt_alpha)
        C3D_AlphaTest(true, GPU_GREATER, 77); // screenshot below is with this set to 200
    else
        C3D_AlphaTest(true, GPU_GREATER, 0);

image

mkst commented 4 years ago

Just noticed this. It's simulated fog, right? The walls are supposed to be darker (until you get close enough) but the sky portion is supposed to be completely clear, right?

Edit: Somehow I remember there being a clearly visible alpha plane like this, but I guess that is also wrong

I guess I should fire up SM64 in an emulator to see how things are meant to look*; it's been a while.

Currently fog is implemented by drawing the triangles twice, once with colour, once as fog. citro3d has some fog functionality which might yield better results (and performance?) if I (or someone) figures it out.

ryotoko commented 4 years ago

I read up about alpha tests and this is my understanding: This condition triggers when the shader is processing an alpha layer and a hard edge texture with alpha for the same texel at the same time. A shadow and a tree, for example, or in the case of JRB, the fog and the crag tops. The alpha test then calculates, based on how this function is set, all texels with combined alpha values less than 77 (of 255) and culls them. That is where the visible fog gradient (the fog "wall" as I was calling it) is coming from. Alpha values above 77 remain, so you get the darker fog in the distance, but the thinner fog in the foreground has been culled, which is incorrect.

There is likely also a depth test, which I suspect is what's screwing the trees up in combination with an alpha test somewhere, that basically functions based on the Z buffer position instead of alpha level. The correct function is bound to be loads more nuanced, this looks like something someone was writing and then stopped half way.

ryotoko commented 4 years ago

This is an issue with the fog branch only: 2020-09-25_17-21-37 251_top I guess your fog function is not respecting the parameters of the RDP's scissoring and/or viewport? Probably the only place in the game where it happens, JRB is too dark to notice it, but you never know when these underlying issues crop up somewhere else as a glitch.

Also, a potential hint: Enabling 3D removes the fog from the scene, just like JRB fog disappears, but the credits background color change does NOT disappear. Seems to suggest you might be right with your fog being rendered at very high Z levels, so it's being clipped.

mkst commented 4 years ago

This is an issue with the fog branch only: 2020-09-25_17-21-37 251_top

I've just rebased 3ds-fog off of 3ds-port and beaten the game, TTC credits looked correct for me:

image

... no closer to solving Fog + 3D as yet.