Orkin
d1R3c764 & g1|\|64 m4|<3R
I've re-read the documentation, and I think I've finally figured it out!
Now, it may at first seem that you need to use area to calculate the LOD, but in fact you don't, I'll use the following as an example:
Say you have mip maps set up like this:
Tile 0: 32x32
Tile 1: 16x16
Tile 2: 8x8
Tile 3: 4x4
Tile 4: 2x2
Tile 5: 1x1
And you want to render a primitive (say a rectangle for now since the math is easier), with the following sizes:
Texture size = 32x32
On-screen size = 8x8
Let's first try calculating the LOD using area:
Texture area = 32 * 32 = 1024
Screen area = 8 * 8 = 64
LOD = Texture area / Screen area = 1024 / 64 = 16
And we select the tile to use based on the LOD:
LOD_tile = log2( (int)LOD ) = log2( 16 ) = 4
If the LOD_tile is 4, then tile 4 is used (assuming prim_tile is 0), but that is only 2x2, not the 8x8 we need.
Now let's try again by calculating the ratio between size, instead of area:
LOD = Texture size / Screen size = 32 / 8 = 4
LOD_tile = log2( (int)LOD ) = log2( 4 ) = 2
Now, with an LOD_tile of 2, we use tile 2 which is 8x8, the size we needed.
The LOD_fraction is computed like this:
LOD_frac = fraction( LOD / 2^LOD_tile ) // With fraction() returning the fractional part of the result
You may at first look at this and think "wait a second, since LOD_tile is log2( LOD ), the LOD_fraction will always end up being 0". Well, it is 0 if the screen size is exactly the same size as the mip map level, but, since the LOD_tile is truncated to an int, if the LOD is fractional, you will end up with a value that gives the amount to blend between the texture described by the tile at prim_tile + lod_tile, and the one described by the tile at prim_tile + lod_tile + 1.
I hope I explained it clearly enough, this is all based on what is stated in the N64 programming manual. There are other things to take into account such as which tiles to use when detail or sharpen modes are enabled. Plus, when sharpen mode is enabled, the LOD_fraction is negated so you end up doing extrapolation instead of interpolation (now that'll be fun to do in a combiner).
Orkin
Now, it may at first seem that you need to use area to calculate the LOD, but in fact you don't, I'll use the following as an example:
Say you have mip maps set up like this:
Tile 0: 32x32
Tile 1: 16x16
Tile 2: 8x8
Tile 3: 4x4
Tile 4: 2x2
Tile 5: 1x1
And you want to render a primitive (say a rectangle for now since the math is easier), with the following sizes:
Texture size = 32x32
On-screen size = 8x8
Let's first try calculating the LOD using area:
Texture area = 32 * 32 = 1024
Screen area = 8 * 8 = 64
LOD = Texture area / Screen area = 1024 / 64 = 16
And we select the tile to use based on the LOD:
LOD_tile = log2( (int)LOD ) = log2( 16 ) = 4
If the LOD_tile is 4, then tile 4 is used (assuming prim_tile is 0), but that is only 2x2, not the 8x8 we need.
Now let's try again by calculating the ratio between size, instead of area:
LOD = Texture size / Screen size = 32 / 8 = 4
LOD_tile = log2( (int)LOD ) = log2( 4 ) = 2
Now, with an LOD_tile of 2, we use tile 2 which is 8x8, the size we needed.
The LOD_fraction is computed like this:
LOD_frac = fraction( LOD / 2^LOD_tile ) // With fraction() returning the fractional part of the result
You may at first look at this and think "wait a second, since LOD_tile is log2( LOD ), the LOD_fraction will always end up being 0". Well, it is 0 if the screen size is exactly the same size as the mip map level, but, since the LOD_tile is truncated to an int, if the LOD is fractional, you will end up with a value that gives the amount to blend between the texture described by the tile at prim_tile + lod_tile, and the one described by the tile at prim_tile + lod_tile + 1.
I hope I explained it clearly enough, this is all based on what is stated in the N64 programming manual. There are other things to take into account such as which tiles to use when detail or sharpen modes are enabled. Plus, when sharpen mode is enabled, the LOD_fraction is negated so you end up doing extrapolation instead of interpolation (now that'll be fun to do in a combiner).
Orkin
Last edited: