Terrain Texture Layers - The Solution (and code)

Blitz3D Forums/Blitz3D Programming/Terrain Texture Layers - The Solution (and code)

John Blackledge(Posted 2011) [#1]
Terrain Texture Layers - The Solution (and code)

I've finally cracked the Terrain Texture Layer question.
All of you will be exultant (well, two of you).

Granted that FastExt has already done this (see FastExt_Example_TextureBlends.bb example) with pre-supplied alphas.
What I wanted to do was
(a) Be able to draw to a newly created blank alpha texture
(b) Be able to save it, and later reload it.

Drawing was not a problem; I drew(?) to the Image and also the Textures stored in memory and reapplied them to the surface.
But I couldn't work out how to save an alpha image correctly.
(At least not the type that FastExt would load and implement properly.)

The included code shows how: make the alpha byte a 0(zero) not 255.

I've used two textures 'stone' and 'clay' to punch through the grass.
(I prefer 'punch'; I think 'texture splatting' tells no-one anything.)

The principle is:
Layer 0: Your usual grass texture.
Layer 1: The alpha texture which will allow the stone texture to 'punch' through.
Layer 2: The actual stone texture.
Layer 3: The alpha texture which will allow the clay texture to 'punch' through.
Layer 4: The actual clay texture.

See the code for the actual FastExt parameters to use for Load and TextureBlend.
You also need the FastExt and FreeImage additions

The crucial thing here is that we can save the results out of a Blitz program for later use, without having to reprocess through another program such as PSP.
Changes are made 'live', again without having to externally reprocess.

This uses a cube for simplicity, but should work just as well on a Blitz terrain or mesh terrain.
You will need your own 'grass.jpg', 'rock.jpg', 'clay.jpg', but alpha's are created for you if you haven't previously created and saved them.

This is as far as I want to take this example.
My next job is to build it into my own engine, so that I can stand on a hill and draw roads and paths directly onto the terrain.




Warner(Posted 2011) [#2]
Thanks for sharing! I have no FastExt, but I'm sure it will be helpful for anyone who has. Good luck with your engine. The path painting sounds like a fun idea.


John Blackledge(Posted 2011) [#3]
Thanks Warner.
FastExt seem to deliver what it promises, though until now I didn't have much use for what it does.
They really do seem to have extended B3D with calls such as TextureBlend, which calls their own version which then allows utilisation of the latest MS parameters such as TextureBlend rockalphatex, FE_ALPHAMODULATE.
Once I've got my engine where I want it I've promised myself that I will look through each call in turn in detail.
I suspect I will say a few times, "Oo- i wish I'd had that before."


Kryzon(Posted 2011) [#4]
I say, hex numbers are evil! :)
I would never have thought of that. Thanks for sharing the success.


John Blackledge(Posted 2011) [#5]
This forum has given so much to me over the last ten years.... it's nice to be able to give something back.