Texture blending and Z buffer problem

Blitz3D Forums/Blitz3D Programming/Texture blending and Z buffer problem

Makepool(Posted 2005) [#1]
I have a problem that I¡Çm not sure can be solved but I¡Çll ask anyway. I wanted to do texture blending on my levels but found that Blitz couldn¡Çt actually do this. There are a few blending options in blitz but none will let you create for example a terrain textured with one texture and then say a path going round it. You can manage to fake it with the right combination of colours as in the demo provided with Blitz called ¡Æinsaner¡Ç but that does work with the level colour scheme we have.

We finally managed to fake it using models with two layers, the top layer having an alpha channel, and that appeared to work very well. Unfortunately I then found that when I fire the rocket launcher in my game over the ground the areas that are blended appear in front of the smoke trail that has an alpha value of 0.5. I assume this is due to a hardware error when multiple objects with lower than full alpha are rendered on top of each other. The renderer can get confused about the Z-order and render the scene incorrectly.

Has anybody encountered this before and does anybody have a solution?


Makepool(Posted 2005) [#2]
ANYBODY AT ALL?


Shambler(Posted 2005) [#3]
Try this http://www.d-grafix.com/


Makepool(Posted 2005) [#4]
TED's programmed in Blitz so I don't see how its multitexturing could have been achieved any other way than the way we're doing it and hence we'd get the same problem occurring.


Shambler(Posted 2005) [#5]
[Edit] Perhaps d-grafix can tell us if overlaying an alpha effect over that sort of terrain is possible?


Duck(Posted 2005) [#6]
I believe Blitz3D sorts transparent entities by their distance from the camera. The distance used would be to the entity's position. Depending on where the smoke trail sprites are relative to the terrain chunk's position the sort order could fail to produce correct results. This is not a hardware error.

Try using EntityOrder with a value less than zero. This will draw your sprites after everything else has rendered. It will not update the Z-Buffer but I think it will use it to render them. This will probably have problems but might be worth a try.


sswift(Posted 2005) [#7]
Here's some information that may prove useful:

In Blitz, each surface in a mesh is rendered in the order it is created.

Also, transparent objects are compared against the zbuffer, but do not write to it.

If you enable the vertex alpha flag on a surface without transparency, it will be rendered as a transparent surface.

So the solution to your problem is to have a mesh with one solid surface, and additional surfaces with identical polygons that have a different texture and the vertex alpha flag set. Then you simply set the vertex alpha the way you want to in order to make some areas of the terrain show the top texture(s), and others show the bottom opaque layer.

You might also combine this technique with alpha maps to get better looking blends between tiles, but that's probably a lot more complicated.

If it helps though, you can render alpha without an alpha map by multiplying the bottom layer by the inverse of the alpha map, then adding the top layer after it has been multiplied by the original alpha map. That last bit is the tricky part though. If you use multiple entities to accomplish it, you'll probably have problems with stuff drawing in the wrong order.


D4NM4N(Posted 2005) [#8]
ted uses a limiting aproach to alpha blending. When i started writing it i did tonnes of research and experiments. I eventually found out that as long as the camera doesnt overtake the terrains axis and the alpha values balance each other it seem to be a bit more Z stable.



here is a tree with alpha on the leaves, with multitexturing and is stable (& thats on my old geforce 4 and my laptop w/intel 82815)


Damien Sturdy(Posted 2005) [#9]
why do i have a feeling cameraclsmode may be handy here?

Just theory, as im at work:

Have a solid, non alpha of the surface you wish to render in alpha.
Hide the original alpha mesh and show the solid version.

Use cameraclsmode to clear both colour and zbuffer.
Render this. This writes that information to the zbuffer.

Now, use cameraclsmode to clear colour but not Zbuffer.

Now, hide the solid mesh you used above, and show the alpha one, render the rest of the scene. Return CameraCLSmode to normal if necesarry

Could someone test that? im at work :D haha. just a thought though :D


D4NM4N(Posted 2005) [#10]
sussed it ( i think )

try this
www.d-grafix.com/sourcecode.html
this is a TED terrain which uses vertex alpha with some alpha bushes sitting happily on it with no apparent problems.

This is after the T.Ed v2.1 update which is still being tested for bugs.


Makepool(Posted 2005) [#11]
Ay up lads, TED uses Blitz's own dodgy multitexturing so that you can't completely get one texture looking correct on top of others. In other words if you had a texture with a pattern on top of it then put a texture of solid colour over the top you'd be able to see the pattern underneath where it should be solid colour.

ALE uses alpha channels as we were doing and so we get the same Z buffer problems with smoke as we did before.

I now believe that it's not possible to properly solve this problem in Blitz 3D and hope to GOD that MAX includes proper support for multitexturing.


D4NM4N(Posted 2005) [#12]
Which version are you running? if its before 2.1 there is problems with alpha textures. 2.2 however seems stable with alpha textures and can be seen running on the latest mountain and island demos from here www.d-grafix.com/softwareted.html

Here is one on a multimesh from the mountain demo showing the alpha working too.

If anyone has problems after rel 2.2 let me know the video hardware as it may be a card specific thing.


Wayne(Posted 2005) [#13]
Makepool, I use a base layer of all black in T.ED, and the blending works fantastic, you can then see as much or little of each layer as you want.

I'm having NO Z buffer problems with demos using smoke, or bushes.

Check the T.ED demos and see for yourself. The z buffer issues are not present.

*preception is reality*


D4NM4N(Posted 2005) [#14]
In other words if you had a texture with a pattern on top of it then put a texture of solid colour over the top you'd be able to see the pattern underneath where it should be solid colour.

As it says in the manual, base layer 1 should not have a strong pattern or color, as it will show through. This is not an error, i designed ted this way so no alpha layer can go higher than .5 this allows the water to be displayed with no problems and also (after 2.1) the alpha textures too.

Using a black layer will make the others stand out more

Using a black layer will make the others stand out a lot more and look really good as wayne says. bHowever, that is not what ive done in the demos. I used the sand 4 the island and neural stone on the mountains