Simulating Destructible Terrain with Brushes?

Blitz3D Forums/Blitz3D Beginners Area/Simulating Destructible Terrain with Brushes?

x2(Posted 2006) [#1]
Ok, I'm stuck and need community help. :-)

I have a small B3D tank like program which uses blitz terrains and would like to apply damage to the terrain texture (not the actual terrain) when shells hit. Think: scorch marks or bullet holes.

My main world code works fine and I can navigate around and use camerapick to place spheres at the desired location of the scorch marks. I toyed with the idea of placing sprites at the damage location but was disappointed in the results. I'm guessing that I need apply a brush to the terrain texture but have not done this before and achieve unexpected results.

My terrain is a 512x512 bmp scaled to 1x40x1 to create a hilly terrain.

My texture is 1024x1024 png and scaled to 1024x1024 (looks better this way).

My test brush was created in code as follows:

myTexture = LoadTexture("resources\test\texture_yellow.png")
ScaleTexture myTexture ,0.0001,0.0001
;
myBrush= CreateBrush(255,255,0)
BrushTexture myBrush,myTexture 


I've tried various methods of applying myBrush to the terrain texture but I either end up with nothing or my entire terrain is yellow when I only want to add a scorch spot. What am I missing here????

For two days I've googed, searched blitzbasic + a few of the other sites but have not found a solutions.

Please help save my sanity!

-- x2


puki(Posted 2006) [#2]
There is an example in the code archives for this type of thing.

EDIT:
I just had a quick look but couldn't find it - just a quick look though.


jfk EO-11110(Posted 2006) [#3]
you could draw to the texture. Just calculate the UV location of a XZ coordinate, then draw some dark pixels.

The problem is drawing to a big texture may be slow. When you use the 256 texture flag, access may be faster, but Mipmapping is turned off for that texture, resulting in "uber-crispy" look. You may use a second layer texture for the terrain, using mask mode (flag 4).
eg:
tex2=createtexture(1024,1024,4 or 256)
entitytexture terrain,tex2,0,1

You may need to set the blendmode of the texture as well.


Ross C(Posted 2006) [#4]
You could put decals down on the terrain. A large texture may work, but, you'll get extreme stretching depending on the size of the terrain.


x2(Posted 2006) [#5]
Thanks for the feedback guys! I spent more time on the problem after my post and discovered the following...

By changing the yellow texture square to a half yellow and half red square, my terrain changed to an orange color. This indicated a scaling problem with the texture so I scaled it up to 512x512. After brushing the texture on to the terrain entity, I was presented with a half yellow / half red mesh. Progress!

Now that I've read the replies, I think jfk probably has what I need. Combining this with my scaling problem may do the trick. However, I too am concerned about the quality of the stretched texture. Are there any other solutions?

Ross, what are these decals you mentioned? Can you point me to an example or post some code I could try out?

-- x2


jfk EO-11110(Posted 2006) [#6]
decals may work for flat terrains, but they may intersect hills and things. Decals are simple quads, positioned a bit over the ground, using an alpha texture to fade out the edges.

Blitz terrains force you to use one texture stretched across the entire terrain. A further solution would be to create a mini-terrain for each explosion location. you would then lay the mini terrain onto the main terrain and apply a fine texture to it. you could use TerrainY() etc. to position the Mini Terrain, although this would force you to use the same segment size and to position the mini terrain on a segment borderline.

what I would do is: I would use a number of prefab crater meshes and simply position them at the impact coordinate. Simple, easy and nice looking.

Oh, and BTW: if you use one big texture for the whoe terrain and draw to it, as I suggested first, you need to scale the texture this way:
scaletexture tex,terrainsize(ter)*ter_scalex#,terrainsize(ter)*ter_scalez#
Note: ter_scalex and y is the factor you used to scale the terrain in x and z.