Multitexturing on Blitz Terrains

Blitz3D Forums/Blitz3D Programming/Multitexturing on Blitz Terrains

Dale Nation(Posted 2013) [#1]
Hello!

I am messing around in the blitz3d Demo, and I want to multitexture a Blitz terrain.

The example below works well, except instead of grass, the terrain is black. The rock, however, shows up perfectly. Could anybody please tell me why the terrain is black where the grass should be?

-see next post for code-


Kryzon(Posted 2013) [#2]
Hi. You are assigning the blendmap texture to the same "layer" as the grass texture, so it's overwriting the grass texture.

In the end, what you're seeing is only the blendmap and the rock that's above it.

EDIT: If you can post a screenshot of those textures then I can help you get the appropriate layering and blend modes - I don't really know what they look like.


Dale Nation(Posted 2013) [#3]
Here is the code


Here is the blendmap:



Here is the result:



I want the black portions of the terrain to be rock, not black.


Kryzon(Posted 2013) [#4]
Okay.

There's no convenient blend-mode that does what you want in a simple way (that is, to let that 'blendmap' serve as a mask to one texture so that the other texture can show through).

There is, however, a way to get exactly this effect you want by making a modified texture that's a special combination of the rock and grass textures.
You need an image editing program, such as Photoshop, GIMP or Paint.NET (if you don't have any of these, Paint.NET is the most friendly to beginners).

The steps needed are as follows:
1) Your grass and rock texture need to have the same image size. Regardless of whatever size they may have (64x64, 256x256 etc.), they need to have the same one.

2) Open your grass and rock textures in one of those image-editing programs I mentioned.

3) Copy and paste the rock texture as a new layer on top of the grass texture.

4) Invert the colors of the rock layer. If you don't know how to do this, search in the help of your image-editing program.

5) Still in this image-editing program, set the blend-mode of this rock layer to MULTIPLY. It will blend with the layer below it, which is the grass texture layer, in a specific way.

6) Save the composite of these two layers as a texture named "grass_modified" or whatever. You just have to select "Save As...", select JPG and when you hit save the program will probably complain about having to merge the two layers together (this is what is compositing them). It's ok, go ahead and click continue.

6b) You can verify if the texture you just exported has the same look as the composited layers in the program. If it's the same, then you're ok.

7) Then set up your scene with the following code:
blendmap	=	LoadTexture( "saves\" + worldname$ + "\blendmap.png", 2 )
			ScaleTexture( blendmap, 256, 256 )

rock	=	LoadTexture("bin\textures\rock.png")
		TextureBlend( rock, 3) ;Add blend-mode.

grass	=	LoadTexture( "bin\textures\grass_modified.jpg" )
	
EntityTexture( terrain, grass, 0, 0 )		;Multiply blend.
EntityTexture( terrain, blendmap, 0, 1 )	;Multiply blend.
EntityTexture( terrain, rock, 0, 2 )		;Add blend.
If you did the image manipulation right, it should give the result you want.
If you want me to explain what is going on with all this blending, the manipulation etc., just ask.


Dale Nation(Posted 2013) [#5]
Aha! One step closer. At least no parts of the terrain are black now.

However, the grass part is not actually grass... just a lightly green tinted version of the stone texture.



How would I fix this?


Kryzon(Posted 2013) [#6]
I made a mistake. --- EDIT, I'll post the correction later on, lol. I'm not thinking straight right now.


Kryzon(Posted 2013) [#7]
Yet another attempt.

1) Open the grass, the rock and the blendmap textures in your image editor.

2) Invert the blendmap's colors, and save it as "inverse_blendmap".
No need to have layer others on top of it, you just invert its colors so the black turns to white and vice-versa. We'll use this inverted version as well as the original, so keep both.

3) Copy and paste the grass texture as a layer on top of the rock texture.

4) Set the blend mode of this grass layer as SUBTRACT (other programs also call this mode as EXCLUSION, but it's the same).
In any case it's not the DIFFERENCE mode.

5) Save this grass+rock composite as "rock_modified".

6) The code to make it happen:

blendmap	=	LoadTexture( "saves\" + worldname$ + "\blendmap.png", 2 ) ;Original blendmap.
			ScaleTexture( blendmap, 256, 256 )

inverse_blendmap	=	LoadTexture( "saves\" + worldname$ + "\inverse_blendmap.png", 2 ) ;Inverted blendmap.
				ScaleTexture( inverse_blendmap, 256, 256 )
				TextureBlend( inverse_blendmap, 3 ); Add blend-mode.

rock	=	LoadTexture("bin\textures\rock_modified.png") ;Modified rock texture.
		TextureBlend( rock, 3) ;Add blend-mode.

grass	=	LoadTexture( "bin\textures\grass.jpg" ) ;Original grass.
	
EntityTexture( terrain, grass, 0, 0 )		;Multiply blend.
EntityTexture( terrain, inverse_blendmap, 0, 1 );Add blend
EntityTexture( terrain, blendmap, 0, 2 )	;Multiply blend.
EntityTexture( terrain, rock, 0, 3 )		;Add blend.
I hope it works.


Dale Nation(Posted 2013) [#8]
Used the EXCLUSION blendmode and got this:



Using SUBTRACT made everything purple. Using the Exclusion gave me the result from last time, only with ugly white outlines (presumably from the inverted blendmap?)



I am completely lost :(


Kryzon(Posted 2013) [#9]
Okay, try this demo:


http://www.mediafire.com/?glvrjrbec1wafe8


Using two terrains is a much slower solution. If you want a bit more speed, you can try something more robust such as this: http://blitzbasic.com/codearcs/codearcs.php?code=2620
This one is even better: http://blitzbasic.com/Community/posts.php?topic=84809


Dale Nation(Posted 2013) [#10]
Thank you. I will be sure to look at the code.


Wings(Posted 2013) [#11]
Blitz terrain is nice but there is another way. as gfx processor now days dont have the limits.

Try vertex shadeing.
1) create mesh1 (Matrix of whole world)
2) create mesh2 (Matrix of whole world)
3) position mesh2 a little higher 0.01 than mesh1
4) Adjust alpha channels on mesh2 this is realy magic :)

smal notice alpha channel gets busted by vertex shader..


John Blackledge(Posted 2013) [#12]
Most 'standard' Blitz solutions use either meshes or 2 terrains.
I didn't want that, but I was able to use Fast extensions to achieve it on one Blitz terrain:
http://www.blitzbasic.co.nz/Community/posts.php?topic=94922 ; Terrain Texture Layers


Rroff(Posted 2013) [#13]
I've been down this road before - you will run into all sorts of lighting and alpha issues and with more than 2 texture layers you will start to get flickering textures.

I've been playing around with a single surface system using vertex alpha w/ overlapping tris using a larger texture like a texture atlas but not progressed enough to know how viable it is for use.


Kryzon(Posted 2013) [#14]
There's the AShadow engine as well, which's been released as freeware.
It uses a different approach to effects, but it wraps some interesting interfaces of Direct3D 7.
Some of which you can use for texture splatting.

http://blitzbasic.com/Community/posts.php?topic=100970#1196402

- - - - -
Although I'm not entirely sure if tex. splatting or even terrains for that matter are what's best for the OP. In hindsight, it'd be best if he just used a 3D map made of adjacent quad tiles, created "manually" through code.
It's easier to texture in that tile fashion he wants, and he can still partition the map in sectors for occlusion and performance.


Wings(Posted 2013) [#15]
Here i a nice texture showing 4 layer multi texturing. Verthex alpha.
i dont remeber but this will destroy z buffer. every thing else must not use alpha channel. unless you make z sorting rutine.