Terrain Alpha Blending


(sock) #1

This is something I slaved over on ET and spent many a day just moving vertex points around on stupid triangle grids. Well those days are over (thank god) and thks to Ydnar we can use any brush size we want.

Sample screenies of my test map I did last night …



You will need the latest compiler from the q3map2 forums. Explaination later, got a xmas lunch.

Sock
:moo:

EDIT: Had moved the images, links updating


(joop sloop) #2

can’t wait to hear the extended explanation Sock! cause that terrain looks awesome =)

Oh and have a nice x-mas lunch :wink:


(rgoer) #3

Extended explanation:

Write a shader like this:

textures/yourmap/terrain
{
	// standard terrain shader stuffs:

	qer_editorimage textures/yourmap/rock.tga	
	q3map_nonplanar
	q3map_shadeAngle 179
	q3map_tcGen ivector ( 512 0 0 ) ( 0 512 0 )
	q3map_tcMod rotate 33
	q3map_lightmapAxis z
	q3map_lightmapSampleOffset 8
	
	// this means dot product squared, for faster falloff between vertical and horizontal planes:

	q3map_alphaMod dotproduct2 ( 0 0 .85 )	

	// mapping stages:

	{
		map textures/yourmap/dirt.tga
		rgbGen identity
	}

	{
		map textures/yourmap/rock.tga
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		alphaFunc GE128
		rgbGen identity
		alphaGen oneMinusVertex
	}

	{
		map textures/yourmap/grass.tga
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		alphaFunc GE128
		rgbGen identity
		alphaGen vertex
	}

	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
	}
}

And then put it all over the surface of your terrain entity instead of common/terrain. No alphamaps required!

In order for this to work, however, your grass.tga and rock.tga images need to have a bright alpha channel (~85-95% bright). The reason it needs to be bright for both images is that rock.tga gets mapped according to the alpha’s inverse.

Here’s an explanation of how this works: this shader draws dirt.tga all over your terrain. Then, according to the vertex alpha (which defaults to white, and is scaled toward black according to the vertex normal by the q3map_alphaMod line), it blends on either rocks or grass. It’s really a great effect, and with a little bit of toying around with the values in the shader it’s very tweakable. q3map_alphaMod dotproduct2 defines the “falloff” of shader blending; it takes values for ( x y z ), and falloff gets harder/sharper as values approach zero. For soft, soft falloff, use values greater than 1 (or just use the old q3map_alphaMod dotproduct instead of dotproduct2).

<img src=http://www4.ncsu.edu/~rlcordes/MAD_BONERS/shot0058.jpg width=400 height=300>

Just for the curious: what dotproduct2 is doing is multiplying the alpha of a given vertex by the square of the result of a dotproduct operation between the normal of said vertex and the ( x y z ) vector defined in the shader.


(kat) #4

I’ll have to give that a go and see what the difference is visually as tri-souping is too damn slow… nice shot btw


(sock) #5

There are currently two new methods of creating terrain with ydnar’s new system.

Method 1

  • Create your brushwork and paint with a special shader. The example map by ydnar has details of this, plus rgoer above has listed out an sample too.
  • Its limited to 2 texture blends per shader, but you can have multiple shaders. I used 2 shaders to create blends from grass to rock, dirt to sand. (There is another way of doing 3 textures with one shader but it does add a whole extra pass to the complete terrain)
  • No heightmap, just create brushwork (see point 1 above)
  • No alphamap, the compiler generates alphablending values based on vertex normals. (steepness of brushwork) Where you have a vertex point, blending will occur. So you control where the blending happens on the terrain. No more stupid fixed grids.

Method 2

  • Create terrain from a heightmap/alphamap
  • Load the terrain as a model into GTK.
  • Tweak terrain from heightmap
  • Still 2 texture blending as above
  • picoterrain is one shader only. Need multiple models for multiple textures.

ATM I like method 1 because I can freeforming the stuff in GTK and then compiling it. I created the cliff face from a template brush:

http://www.planetquake.com/simland/images/terrain/funkya11.jpg

See this tutorial for more details of rockwork templates:
http://www.planetquake.com/simland/ldr1_1/tut_rockwork1.html

The cliff face is made totally from brushes twisted/sheered/trisouped into place. Here is the in game tris angle:

Here is the editor view of the terrain:

Sock
:moo:

EDIT: Had moved the images, links updating


(kat) #6

I was just trying this out, and it’s a very different way to work when compaired to trisouping, it’s a hole lot less labour intensive but you do actually need to adjust the way you work/think slightly. It’s very quick and I can see that once you’ve got the technique down pat it’ll produce some stunning stuff (as you’ve shown)

(btw I just knew you could include the ground in the template…!!! hehe)


(joop sloop) #7

Then all I need to learn is shaders and tri-souping :slight_smile:

And could you show me an example alpha map please?

(isn’t tri-souping 3 point clipping? or am I really having no clue now? :))


(MadMaximus) #8

that is an amazing looking terrain sock, i will have to try it out. it would definately make better riverbeds with the steepness of the bank not limited to preset triangles now. i’ll give it a shot tomorrow and see what i can come up with.


(kat) #9

‘tri-souping’ is basically where you cut a normal brush across the diagonal from corner to corner, spliting a square (quad) based shape into 2 triangles

cutting this diagonally | | would give you this || which is your tri-soup


(cicero) #10

Hello!

I’m really good to modelling houses (as I’m a student of architecture) though I’m more or less a noob when it comes to scripting… What program can I use to make terrain looking this good? Do I have to scan a map? Can I use Esaygen? GtkGensurf?

One more thing, this textstuff, I get what the commands in the textlines does, that’s not so hard, but where do I write it? In the same text file as I write instructions to make dynamitable objects and those things???

Ciao!


(sock) #11

You should learn at least the basics of shaders because the whole game deals with them. The above terrain method is alot easier on shaders than traditional methods. (triangle meshes)

Tri-souping and 3 point clipping are indeed different as Kat says. Tri-souping is playing with a mesh of triangles and 3 point clipping is cutting brushes in non-axial directions.

Sock :moo:


(LodeRunner) #12

Hmm…looks like using a patch as the clipping plane just became uber-important…I think it would make sheering a structure like this a bit faster, seeing as that looks like a bunch of 3 point clipping.


(michi.be) #13

So this green and yellow stuff are your textures with the grass and sand texture on it??


(sock) #14

Nope its nothing to do with patch clipping, this is about creating any size brushwork with a terrain shader painted on it. The ability to move away from fixed sized triangles and create something maybe a bit more freeform.

The green and yellow bits are just editor only textures for the terrain shaders. They show where on the brushwork to blend, exactly like the old style terrain system.

Sock
:moo:


(Big Bang Hank) #15

Any chance of a tutorial on this sock?


(MadMaximus) #16

sock, is it possible to post the shader you used for your example? and are the textures your using for the blending standard textures in the et pk3?

I did a test of it and it did seem to work, but the blending was at the very edge of the steep angle where it met the rock face, I tried different variations of the shader and got some wierd/cool effects… one effect were it almost looked like the grass was moving where it blended, however in the test map you did it blends at the very top of your grass area which looks really good and mine blended at the very bottom, and i’d like to see if i can get a similar effect as yours. I don’t have any screenies of what i’m saying as i just made every test in the same map and recompiled ( i didn’t think ahead ) but here is a sample of what i’m saying from an in-editor look,

if you could post the shader you used would be appreciated. :bump:


(rgoer) #17

What did the alpha channel for your grass image look like, MadMaximus? That’s probably the culprit.


(sock) #18

Here the shader I used for the rock/grass in my test map. The texture scale needs to be tweaked depending on the overall size of the map.


// ======================================================================
// Terrain blending
// ROCK -> GRASS
// ======================================================================
//
textures/sock_terrain/ter_rock1grass1
{
        qer_editorimage textures/common/ter_rock1grass1.tga
	q3map_lightImage textures/sock_terrain/grass_1.tga
	
	q3map_forceMeta
	q3map_nonplanar
	q3map_shadeAngle 179
	q3map_lightmapAxis z
	
	q3map_tcGen ivector ( 2048 0 0 ) ( 0 2048 0 )
	q3map_tcMod rotate 33
	q3map_alphaMod dotproduct2 ( 0.1 0 0.8 )
	q3map_lightmapSampleSize 64
	q3map_globalTexture
	
	{
		map textures/sock_terrain/rock_1.tga
		tcMod scale 8 8
		rgbGen identity
	}
	{
		map textures/sock_terrain/grass_1alpha.tga
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		alphaFunc GE128
		rgbGen identity
		alphaGen vertex
		tcMod scale 8 8
	}
	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
		rgbGen identity
	}
	{
		map textures/sock_terrain/detail_1.tga
		blendFunc GL_DST_COLOR GL_SRC_COLOR
		rgbgen identity
		tcMod scale 4 4
		detail
	}
}

Sock
:moo:


(MadMaximus) #19

you know rgoer, i didnt even check, when you mentioned in your earlier post that the alpha channel had to be 85% to 95% bright, i just used the textures that came with ydnars big snow mountain example map, i assumed ( which i shouldn’t i know ) that those textures should work out ok since they worked on his map.

i think it’s my shader layout, thanks sock, now i have something to go by.

i see your dotproduct setting is different, i’m still learning shaders, i do understand how they work though, but not every aspect. It’s easier to see how it’s done from a working example and then go line by line to understand what they do.


(rgoer) #20

Dotproduct take ( x y z ) values. If you want something like a “moss on the north side of the tree” effect, you might want to use dotproduct2 ( 0 0.9 0 ), assuming you have mapped such that the +y direction = north. For stuff like snow on top of mountains, the +z direction is what you’re looking for, so values around the ( 0 0 0.9 ) area work well. To have the falloff favor the “front” or the “side” (or both), you can add (or subtract) a little to (from) the x and/or y values, as well–a la Sock’s ( 0.1 0 0.8 ). Lower values = harder (sharper) falloff in that direction. A value of ( 0 0 0.1) would be a very sharp falloff from the top. ( 0 0 1 ) is a very smooth, gradated falloff from the same direction. Dotproduct can take negative values, also… something like corrosion on the bottom of metal oil tanks (like you see on the sides of buildings) might look cool, and could be done with a ( 0 0 -0.85 ) (or something equivalent) value. Just dick around with the values (and the alpha channels of your images)… you’ll find it’s a lot of fun to play with.