checkerboard transparency not showing properly

Blitz3D Forums/Blitz3D Beginners Area/checkerboard transparency not showing properly

tsmpaul(Posted 2009) [#1]


I have two terrain squares. One has a green texture applied to it, the other a brown texture applied to it.
I have a checkboard black and white pattern, and a reversed-image of the same checkerboard pattern.
I apply the first checkerboard pattern as an alpha to the green terrain, and the opposite checkerboard pattern as an alpha to the brown terrain.

The result is the brown shows where the green is transparent, and the green shows where the brown is transparent.
The problem though - the checkerboard alpha map is not being displayed as squares! There are gaps between each square, and holes in the corners, instead of clear square edges. The squares should touch in the corners, like a checkerboard, but for some reason, there's all this transparency around each square?

Here's the code I'm currently using to display this:

ground_layer1=LoadTerrain("design images\height0.bmp")
PositionEntity ground_layer1,0.5,0,0.5
ground_layer2=LoadTerrain("design images\height0.bmp")
PositionEntity ground_layer2,0.5,-0.001,0.5

layer1_tile=LoadTexture("design images\layer1_tile.bmp")
layer2_tile=LoadTexture("design images\layer2_tile.bmp")

layer1_mask=LoadTexture("design images\layer1_mask.bmp",4)
layer2_mask=LoadTexture("design images\layer2_mask.bmp",4)

TextureBlend layer1_mask,1
TextureBlend layer1_tile,2
ScaleTexture layer1_tile,1,1
ScaleTexture layer1_mask,2048,2048
EntityTexture ground_layer1,layer1_tile,0,1
EntityTexture ground_layer1,layer1_mask,0,0

TextureBlend layer2_mask,1
TextureBlend layer2_tile,2
ScaleTexture layer2_tile,1,1
ScaleTexture layer2_mask,2048,2048
EntityTexture ground_layer2,layer2_tile,0,1
EntityTexture ground_layer2,layer2_mask,0,0


tsmpaul(Posted 2009) [#2]
Sorry to double post, but I thought this was interesting doing more trial and error.

The checkerboard texture is 2048 in size (as is the terrain). The checkerboard pattern was 1 pixel black, 1 pixel white, 1 pixel black, 1 pixel white, and so on.

What I found was, that when I tripled the size of the texture (that's one BIG texture) the alpha effect on the grid pattern was much more defined, with sharp edges along the sides of the squares - but the squares still don't meet touch in the corners, even though the black and white alpha texture map is perfectly aligned squares. It would be unreasonable to just keep making the texture bigger and bigger to try and get more defined squares...

I saw that under TextureFilters, it automaticaly applies mipmapping to textures when you load them. It says that blurs things at a distance, so I tried the clear texture filters command, but that hasn't had any effect at all...


Ross C(Posted 2009) [#3]
It is to do with your 1x1 texture. I believe it's called bi-linear filtering. It is the process of blurring the edges of each pixel/texel, to produce a smoother look to textures. Unfortunetly, in your case, it's having the opposite effect here. I believe there was a way to disable it from some outside lib, but to be honest, i think your better just using a 16x16 texture, to get better clarity.

Mipmapping is a process that in most texture formats, automatically produces lower quality versions (smaller sizes) of the textures. At a certain distance from the screen (it takes into consideration the screen resolution) the textures are automatically downsized to smaller sized ones. It keeps every screen pixel displaying one texel i believe.


Pongo(Posted 2009) [#4]
Is there any reason that you cannot make a single checker pattern (at say 128x128, where you have 4-64x64 squares on it) and use scaletexture to make it tile?


Ross C(Posted 2009) [#5]
Yeah, thats a good point. You will notice a big slowdown if you try to tile a 1x1 texture across a large area. As Pongo says, tiling a larger texture, will have performance gains.


tsmpaul(Posted 2009) [#6]
Hi guys.
The texture is 2048 x 2048 in size, the pattern on it is made of 1x1 pixels. In other words, there's 2048 dots wide, and 2048 dots high, on the texture, alternating between black and white pixels, to make a checkerboard pattern. The image is stretched over a 2048 x 2048 terrain, which represents 1 unit = 1 meter. So every pixel of texture represents 1 meter of ground.
It was just a transparency test, because my aim was to use it as a method of multi-texturing a map. I could simply turn areas black or white on a texture to make different ground layers show through, so the grid pattern itself isn't really the aim of my exercise...
It's okay though, I've decided to try a different approach to map design instead.