README 8.86 KB

This app demonstrates some of the uses and usage of multi-tile textures
(refer to the Texture document for a description of how tile memory is used
in texture mapping).

To run the app, type 'gload' in the directory.

When the app comes up, it puts the user above a gorge with running 
water. On the left is a scrub forest and a sand dune behind it. On
the right is a farm with fields and a mud mountain behind it.
Each one of these demonstrates a different use of multi-tile textures.

The controller can be used to fly around this database. The controls
are mapped as follows:

Joystick 'y' axis : pitch
Joystick 'x' axis : roll

'up' button 	  : accelerate forward
'down' button 	  : decelerate
'left' button	  : yaw left (accelerate)
'right' button	  : yaw right (accelerate)

'start' button	  : come to a complete stop


All textures except the river are mipmapped. 


o THE SCRUB FOREST

The scrub forest on the left uses detail-texture mode. In this case 
the texture itself (at a different scale) is used as the detail texture.
If you look at the display list for the forest texture in gorge_dl.h
you can see that tmem is loaded with the base mipmap RGBA16forest32_buf
texture and the tiles 1,2,3,4,5,6 are set to implement mipmapping.
Tile 0 (the detail tile) points to tmem address 0 where the base texture 
is loaded so that the base texture ITSELF can be used as a detail texture.
The s and t shift values in tile 0 is set to 0xf,0xf (-1,-1) which means
that one main texel when magnified, will contain 4 (2x2) detail texels.



So if we look at the texture from a distance, we can see the base texture.
As we fly closer, we can see the detail texture coming in until we are
close enough that the detail texture COMPLETELY replaces the base texture
(as opposed to having some amount of the base texture blended in). This
complete replacement is effective only in cases where the base texture
and the detail texture are well correlated (as in this case where they're
the same). This blending between the base texture and the detail texture
is controlled by the parameter 'm' in the setPrimColor macro. The ls 5-bits
of this 8-bit parameter set the min value that the LOD fraction is clamped
to when in magnification. The ls 5 bits are interpreted as a 0.5 fixed point 
number. In this case 'm' is set to 0 => LOD frac can go all the way to zero 
(infinite magnification) which means that eventually the base texture will 
completely fade out and the detail texture will completely replace it. If this 
parameter was set to 15 say, then the LOD fraction will never go below 0.5
when in magnification. So however close we get to the ground, we'll still
have 0.5 of the base texture blended in with  0.5 of the detail texture.

This usage of the base texture as the detail also is very effective in the 
sense that it allows us to have enough visual cues when flying close to the 
ground without having to see a gazillion repeats of the texture when at a 
distance. Also, the detail texture and the base texture are automatically 
correlated


o THE FARM

The farm uses a field texture as the base texture and a similarly colored
leaf texture as the detail texture. If you look at the display list for
texture RGBA16field32_buf in gorge_dl.h, you can see that at first the
field texture is loaded as a mipmap with Tile 1 pointing to the finest level
the mipmap. Then, the RGBA16leaf32 texture is loaded in tmem AFTER the mipmap
and Tile 0 is set to point to it. The s,t shifts in Tile 0 are set to 0xf (-1)
which means that upon magnifying a base texel, we can see 4 detail texels in
it (a 2x2). The min LOD frac parameter is set to 23 which implies that only a 
very small amount of the detail texture is added to the base texture in 
magnification. This is because adding more would cause a noticable shift
in the color of the base texture thus making the cut-in of the detail texture
very obvious. 

NOTE1: Only half the 32x32 leaf texture is loaded and used as detail texture
since there is only space for a 32x16 in tmem.

The hardest part in using a seperate texture as a detail texture is finding
a detail texture that is well coordinated with the base texture in the sense
that the detail texture should not cause a large color shift in the base 
texture and that it looks natural. Also setting an appropriate min LOD frac 
parameter is important.

NOTE2: In this particular case the particular farm texture used is a bad
choice since it has so little detail for its size (32x32). In such a case,
the base texture can be filtered down to say an 8x8 and used with a detail
texture or a texture thate effectively utilizes all its texels to provide 
detail may be used with a detail texture providing more detail in high
magnification.

NOTE3: Since the detail texture is at a higher scale, trilinear interpolation
will be occuring between levels with widely varying LODs without the intermediate
levels. Thus the detail will alias in magnification. The larger (more -ve) the 
s and t shifts in the tile pointing to the detail texture, the more it will alias 
when in magnification. Larger shifts also have another unpleasant consequence. 
Since the coordinates are being shifted left, the number of fractional bits 
(of the S10.5) available decrements with each shift until at a shift of -5 (0xb), 
there are no fractional bits left. The effect of this is to reduce the effectiveness 
of the bilinear interpolation within the detail texture. This will be noticable as 
mach banding.

o THE SAND DUNE

The sand dune uses a concept known as 'sparse mipmaps'. A sparse mipmap
is a mipmap with lesser number of levels than one would get by filtering
down by a factor of 2 in each dimension between levels. A 'full' mipmap
of a 32x16 texture for example would have a 32x16, 16x8, 8x4, 4x2, 2x1 
and a 1x1 texture. A sparse-mipmap implementation of the same could only 
have every alternate map. This would of course cause the texture to blur
very early but might be a viable alternative for some types of textures.

In the sand dune case, the sparse mipmap uses only two levels, a 64x32
and a 1x1. It also uses the base texture, at a different scale as detail 
texture. Tile 1 points to the base 64x32 texture, Tile 2 points to the first 
texel of the same texture, a texel that is approximately the average color 
of the whole texture (One could also load a separate 1x1 texture instead of 
a reusing a texel in the base texture. Note that the max level parameter
in the gsSPTexture command is set to 1 (number of mipmaps -1) so that the
RDP doesnt try to access higher levels of mipmap that dont exist. Also to
implement a detail texture, Tile 0 points to the base texture but the
shifts are set to 0xe (-2) and the min LOD frac parameter is set to 0.
This will have the effect of replacing the sand dune lines with the same
line pattern at a scale that is finer by a factor of 16 (4x4). Since the
mipmap has only two levels, the texture will blur out to a constant color
pretty early but that is not really a loss for this particular texture
since if we had implemented a full mipmap for this, the very next level
(32x16) would probably have been a single color anyway due to the repetitive
pattern in the base texture.

o THE MUD MOUNTAIN

The mountain uses a feature known as sharpen mode which extrapolates
(vs interpolating) the base texture and the next level up to effectively
sharpen edges in the texture while magnifying. This can be very effective 
for objects like STOP signs which are monochromatic but can also be used
to give detail in multicolor textures like the drainage texture mapped onto 
the mountain. In this case the mountain is mipmapped although if we
expected an object to be in magnification mode most or all of the time
we could load only the first two levels of the mipmap for sharpen mode
to work although it would alias in minification.

o THE RIVER

The river is implemented very simply. An 8-bit intensity texture is used 
to interpolate between whitish (PrimColor) and  and a bluish (EnvColor)
color. This is done by setting the Color Combiner to the appropriate
mode. Intensity textures without an alpha channel set the alpha channel to
the intensity value. To use this alpha value as transparency the Blender
mode is set to xlucent mode. So in this case the darker areas of the I8 texture
will be bluish and translucent and the brighter areas would be whiteish
and opaque. This is done to match water which has white, opaque breakers
and bluish translucent calm areas. The translucency in this case isnt
very obvious but can be increased by choosing an appropriate texture or 
by using the PrimColor Alpha to modulate the overall alpha.


FINAL NOTE: Most of the textures in this example are RGBA16 which is 
expensive in tmem. Many of the textures can be implemented as a 4-bit or 
8-bit ColorIndex saving tmem and performance. This would also allow 
use of larger base and detail textures to improve overall detail and reduce 
the time spent in magnification.


Questions or Comments? Send e-mail to :

	ashoks@engr.sgi.com