gonetz / GLideN64

A new generation, open-source graphics plugin for N64 emulators.
Other
770 stars 177 forks source link

LOD emulation issue #2320

Open ghost opened 4 years ago

ghost commented 4 years ago

The N64 handles Level of Detail (LoD) in the following manner:

To emulate this correctly, something similar to this would have to be done.

I believe the third step is incorrect in current master. Subtraction of (sl,tl) and shift are applied before lod has been calculated. I believe descriptors prim_tile and prim_tile + 1 are used for this reason. This is not too problematic if the shift and (sl,tl) parameters have logical values. I worked around by calculating the lod_scale variable in the texture engine refactor, and before that normalized coordinates helped the same behaviour. But if (sl,tl) or shift are unexpected, strange things could happen.

I don't know very well how the fourth step is working currently. Are all tiles loaded into OpenGL's memory? How are they accessible from the fragment shader?

@gonetz I started refactoring the LoD code. The branch is in very early WIP state and I don't expect to have time to work on it for at least a couple of months. If you want to tackle the issue though, feel free to use any piece you find useful.

gonetz commented 4 years ago

I don't know very well how the fourth step is working currently. Are all tiles loaded into OpenGL's memory? How are they accessible from the fragment shader?

The first tile of mip-mapped texture is loaded as a common one-level texture. Tiles from 2 to gSP.texture.level are loaded as single mip-mapped texture. It is necessary because the first tile can be a detailed texture and can have different format. Fragment shader for LOD calculation is ShaderMipmap. It uses texelFetch(tex, coords, lod) to fetch from mip-mapped texture.

I have plans to rewrite LOD implementation using texture array instead of mip-mapped texture. OpenGL requires that size of any tile in mip-mapped texture must be half of size of the previous tile. It is not always the case for N64 mip-mapped textures, and the current code uses some texture size correction.

ghost commented 4 years ago

I have plans to rewrite LOD implementation using texture array instead of mip-mapped texture.

Sounds like a good idea. Good luck.