Lighting with Multi-Texturing

Blitz3D Forums/Blitz3D Programming/Lighting with Multi-Texturing

inneractive(Posted 2003) [#1]
Okay I have a 3D tile terrain engine using multi-textured tiles consisting of a base texture, and alpha - noblend texture.

;----------
ClearTextureFilters

; base texture using UVW coord set 0
BFL_TERRAIN\base = LoadTexture(baseTex, 57)
TextureCoords BFL_TERRAIN\base, 0

; blend texture using UVW coord set 1
BFL_TERRAIN\blend = LoadTexture(blendTex, 59)
TextureCoords BFL_TERRAIN\blend, 1
TextureBlend BFL_TERRAIN\blend, 1
;----------

I add these textures to a surface using a brush.

;----------
BFL_TERRAIN\brush = CreateBrush()

BrushTexture BFL_TERRAIN\brush, BFL_TERRAIN\base, 0, 0
BrushTexture BFL_TERRAIN\brush, BFL_TERRAIN\blend, 0, 1
PaintSurface BFL_TERRAIN\surface, BFL_TERRAIN\brush
;----------

When I turn off the ambientlight
AmbientLight 0,0,0

my blend texture (flagged alpha) is still clearly visible, while the base texture is blacked out. Is this because I have TextureBlend set to 1? This is needed for alpha multi-texturing.

If this is the case then does anybody know a workaround so I can use the AmbientLight settings to ajust light on my levels while still using textures flagged alpha?


poopla(Posted 2003) [#2]
I dont remember what I did to solve this stuff... try putting the alpha texture UNDER your base texture in the "0 layer".


inneractive(Posted 2003) [#3]
Hmm, it didn't work. I set my alpha texture to index 0 and my non-alpha texture to index 1. Made it look like the alpha was set to multiply. One interesting thing though, my framerate jumped from 367 to 398...

Thanks though. I'll keep playing around with the settings.


inneractive(Posted 2003) [#4]
I guess I can use BrushAlpha to fake it, but then my other lights won't effect the brush. I'll probably just go with vertex alpha or colors and some kind of manual lighting system.... was hoping I could avoid the extra work ;p


sswift(Posted 2003) [#5]
What you're trying to do won't work.

What you WANT to do is set layer 1 to your base texture and have that be affected by the color/lighting below it. So you leave that at the default multiply blend mode, which makes it look like a lit texture.

But then you also want to alpha blend a second texture with the first, and have that affected by lighting. To do that you're trying to put it on layer 2 and set some blending mode to make it work. But that can never work.

Ignoring the fact that you may not even be able to set a texture to both multiply AND add blend, the idea of multiplying a second texture with the first to make it appear lit is mistaken.

What you really need to do is have two surfaces. With two surfaces you can do a lot of things that you can't do with basic multitexturing. There's a number of ways that you could set things up with two surfaces to achieve what you want.

One way would be to have the first surface be your base texture, and have the second surface be the alpha. BOTH surfaces will be lit, so BOTH surfaces will have properly lit textures. The alpha map then blends the LIT second layer with the first lit layer with varying levels of transparency.

This gives the correct result, whereas multiplying two textures together, and then lighting the end result by using multitexturing would give you really dark textures that don't look like they're blended together.

Another thing you could do would be to place both textures on the first layer, but with lighting disabled, using the alpha to blend them together, and then on the second surface have lighting eneabled, with no texture, but set that surface to multiply blend with the first. Then the textures which have been blended will be darkened where apprpriate. This method however will not allow you to have overbrightened areas as would be caused if you had shininess enabled to create specular highlights. However, when Blitz gets 2x multiply blending, then that problem will be solved because you can use that and then get really nice looking vertex based lighting that you may not be able to get with the first method I described. This method may have problems handling fog though, whereas the first method should handle fog.

Using two surfaces also allows you to use vertex alpha instead of an alpha map, which allows you to create effects you might not be able to do with an alpha map.


inneractive(Posted 2003) [#6]
oh jeez, I just tested it out in the 2 surface tiled terrain lib I started making first and you are right!

...and after all that work converting it into a single surface multi-textured tiled terrain lib. Just as I was putting in my camera and lighting functions I noticed the problem. Oh well, the 2 surface lib runs almost as fast. I guess I was taking the single-surface concept a bit too far.

Thanks for the help!