Prevent Mipmapping Artefacts with masked Textures

Blitz3D Forums/Blitz3D Tutorials/Prevent Mipmapping Artefacts with masked Textures

There's a certain sort of masked texture that frequently makes troubles when displayed with full mipmapping/high speed settings, especially on Radeon chipsets. These are fences, gatters etc., finely structured masked things with a pattern character.

Let us assume we have a fence, textured with a masked wire fence texture. Let us assume the fence is rotated about 60°, relative to the camera, so it's a steep angle to the camera. It may happen that the more distant parts of the fence will become invisible. In the worst case this is a transparent fence that will pop up when the player gets closer, due to mipmaping artefacts.

There's a trick to prevent this:

The optimal number of the non-transparent pixels is 51 percent of the whole texture. It may be close to 51 percent, but it should under no circumstances be less than 50%.

You may use a simple blitz program to count the non-transparent texels:
graphics3d 640,480,32,2
tex=loadtexture("test.bmp",4)
setbuffer texturebuffer(tex)
lockbuffer()
w=texturewidth(tex)
h=textureheight(tex)
c#=0
for y=0 to h-1
 for x=0 to w-1
  rgb=readpixelfast(x,y) and $ffffff
  if rgb<>0 then
   c=c+1
  endif
 next
next
unlockbuffer()
setbuffer backbuffer()
print "non-transparent texels:"+((c/(w*h))*100)+" percent"
waitkey()


You may use the selection expand/contract functions of your graphics app to rise/lower the number of non-transparent texels on such pattern-like masked textures.

Thought I should let you know. Took me quiet a while until I figured out the 51% thing.

BTW: you may also reduce or fix this problem by loading the texture without mipmaping. But I think this has a lot of cons, so I prefere the 51% way.