Terrain blending tutorial for noobs by Seven_dc


(ratty redemption) #41

k, I finally got my shaders working again after adding in more base shaders, and I tested my volume shaders and ivector is making a difference, and to correct one of my earlier statements, without any scaling my volume and dotproduct shaders seem to scale really small, although I don`t know at what size.

as requested by MadJack, here`s one of my updated volume shaders… note this is a decal blend, so only use it if you have solid shaders on brushes underneath.

textures/_ratty_terrain/base1
{
 q3map_shadeangle 178
 q3map_tcmod rotate -66
 q3map_nonplanar
 q3map_forcemeta
 q3map_nolightmap
 q3map_tcgen ivector ( 256 0 0 ) ( 0 256 0 )
 surfaceparm nonsolid
 surfaceparm nomarks
 surfaceparm trans
}

textures/_ratty_terrain/dirt_volune_blend  // decal
{
 qer_editorimage textures/_ratty_terrain/red_grey_terrain.tga
 q3map_baseshader textures/_ratty_terrain/base1
 //cull disable  // uncomment to debug
 polygonoffset
 {
  map textures/_ratty_terrain/ratty_dirt_m03.tga  // dirt
  rgbgen vertex
  //rgbgen const ( 0.5 0 0 )  // uncomment to debug
  alphagen oneminusvertex
  alphafunc ge128
 }
}

textures/_ratty_water/alpha_0  // the alpha shader I use
{
 qer_editorimage textures/_ratty_terrain/alpha_0.tga
 qer_trans 0.75
 q3map_alphamod volume
 q3map_alphamod scale 0
 surfaceparm nonsolid
 surfaceparm nodraw
 surfaceparm trans
}



(MadJack) #42

Got some testing done. Results are … huh special? :smiley:

WARNING: Very long post

First, what happened with the non-scaling was me being an idiot. I had tried so many shaders that I was modifying the wrong one effectively not making any differences. Since that shader wasn’t used anywhere I couldn’t notice what I was doing wrong until I took the problem in its basic elements.

Now, the whole thing is pretty easy to setup. I have 2 textures I use. first one being dirt_m03icmp_brown.jpg with some params added to it.


textures/ebe/dirt_pebbly
{
	qer_editorimage textures/temperate_sd/dirt_m03icmp_brown
	surfaceparm gravelsteps
	implicitMap textures/temperate_sd/dirt_m03icmp_brown
}

That texture is used as the middle part of the road. It’s not blended at all.

Second texture is where the blending occurs.


textures/ebe/road_alpha
{
	qer_editorimage textures/temperate_sd/dirt_m03icmp_brown
	q3map_forceMeta
	q3map_nonplanar
	q3map_shadeAngle 179
	surfaceparm landmine
	surfaceparm gravelsteps
	{
		map textures/temperate_sd/dirt_m03icmp_brown.tga
		rgbGen identity
	}
	{
		map textures/temperate_sd/master_grass_dirt3.tga
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		rgbGen identity
		alphaGen vertex
	}
	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
		rgbGen identity
	}
}

That texture is applied on each side of the road part so it will blend with that road texture and the surrounding terrain. You could look at it as a buffer zone or blending zone between the road and the easygen terrain.

Now the problem is still texture scaling but in a different way. Note that there is a fix for those problems and that’s why I’m posting it.

First, if you don’t use scaling at all, meaning no q3map2_tcGen ivector or tcGen vector etc you should get something similar to this:

It IS blending nice BUT the blending isn’t done at the same scale as the surrounding terrain. So, let’s scale it up. Here’s the result of adding


q3map_tcGen ivector ( 512 0 0 ) ( 0 512 0 )

in the textures/ebe/road_alpha top part so the texture happens at the same scale as the terrain (which is scaled at 512).

As we can see above, the scaling occurs on the blending area, the grass looks ok but the pebbly area looks distorted and blurry. Middle area isn’t scaled at all. Not really what we’re looking for.

So, let’s scale that midldle part and see what it does. Let’s add


q3map_tcGen ivector ( 512 0 0 ) ( 0 512 0 )

to the textures/ebe/dirt_pebbly so indeed that middle part gets scaled.

The result is not bad but not that good. Blending occurs at the right scale on all textures but the middle part is too blurry and I personally don’t like it at all.

So, the best result would be to have the middle part scaled down and the blending from the middle to the edge (grass) being done at 512.

Not hard to get if you do that:

First, remove all the q3map2_tcGen above and change that part:


	{
		map textures/temperate_sd/master_grass_dirt3.tga
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		rgbGen identity
		alphaGen vertex
	}

with


	{
		map textures/temperate_sd/master_grass_dirt3.tga
		tcGen vector ( 0.001953125 0 0 ) ( 0 0.001953125 0 )
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		rgbGen identity
		alphaGen vertex
	}

Here’s the result of that:

Very nice blend with a road area that is nicely scaled.

I would be nice if we could use q3map_baseshader or q3map2_tcGen in a stage but it isn’t possible.

Another thing is that I didn’t test with all possible textures of course so mileage might vary with different textures.

I think that covers it all. :slight_smile:

Comments and ideas welcomed!


(ratty redemption) #43

@MadJack, I`m glad you got it working and I agree with your use of tcgen vector on the 2nd image stage.

but you could still use a q3map_tcgen ivector in the top stage, with different values to the tcgen vector, so the q3map one scales the image in the first stage, while not affecting the scaling in the 2nd stage as that uses it`s own scaling.

also if I dont see effects of tweaking a shader, even after compiling my maps, then I simply use an rgbgen const colored filter to debug which shaders are showing up in game, and where... if none of them do, then its likely the shader is a backup version not in the scripts folder, or I`d forgotten to add the shader file name to the shaderlist.txt

and today I found a good way of testing if base shaders are working is to temporary add a q3map_surfacelight and q3map_lightrgb to the base shader, so that any other shaders using it will glow, give off light in game, eg.

q3map_surfacelight 4000
q3map_lightrgb 1 0 0

it`s tips like this that save me hours or days trying to look for errors in my shader code.


(MadJack) #44

True enough ratty. The effect I was looking for was best acheived the way I set it up but I guess having a different size of texture I might have to go the way you’re proposing.

I agree those are nice debug tweaks. I do use stuff like that once in a while when I’m testing something though more than often I simply forget about it :slight_smile:


(ratty redemption) #45

cool :slight_smile: