triangle steepness and its effect on dotproduct 2 blending


(thore) #1

now with sock’s tutorial on terrain blending techniques time has come for my first (and
futile) attempt to put hands on dotproduct2 terrain. i’ve seen some pics around here in
the the forums and some tutorials stated the same: triangle steepness should take
effect on texture blending. now with sock’s freshly released sample maps there was no
more hassle to pay attention to some shaders… i could experiment by moving things
around and then looking at what has changed. great thing indeed. dotproduct blending
works fine when using alpha brushes, but though all the reading i have come to the
assumption triangle steepness will “automagically” fade between primary and secondary
texture.

now the prob is: there is no fading without alpha brushes :confused: and i simply won’t believe
the “first pass” generated by using the dotproduct2 system as sock is describing it in his
tutorial will turn out completely invisible. i used the textures and shaders he included with
his sample maps and it really makes no difference whether i apply the plain tga texture
or the corresponding shader… they’ll both look the same ingame (plain green grass)

q3map2 version should be fine, as the dotproduct blending works well when manually
applied via alpha brushes…

here’s a shot of how it looks in radiant:

hopefully not much to say about :smiley:

this is (nearly) the same perspective ingame:

you can see the plain tga texture and the shader look exactly the same, while the alpha
brush works as expected on the side of the shader. additionally i would have expected
some blending triggered by terrain steepness - but that’s missing.

this is sock’s shader that i expected to fade between primary and secondary tex according to terrain steepness:

textures/terrain_example/ter_mossmud
{
        qer_editorimage textures/terrain_example/ter_mossmud.tga
	
	q3map_nonplanar
	q3map_shadeangle 120
	q3map_tcGen ivector ( 256 0 0 ) ( 0 256 0 )
	q3map_alphaMod dotproduct2 ( 0.0 0.0 0.75 )
	
	{
		map textures/terrain_example/ter_moss1.tga	// Primary
		rgbGen identity
	}
	{
		map textures/terrain_example/ter_mud1.tga	// Secondary
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		alphaFunc GE128
		rgbGen identity
		alphaGen vertex
	}
	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
		rgbGen identity
	}
}

now i don’t think there’s anything wrong with the shader, but i might be wrong on my
understanding of what the dotproduct2 system really does (without the use of alpha
brushes)?


(ydnar) #2

Are you sure you put the shader in shaderlist.txt?


(thore) #3

edited the post above and added some pics.

yep, “terrain_example” is included and found during compile process (that’s what the log says).
i wouldn’t expect the alpha brush to take effect on the moss-mud shader otherwise :moo:

q3map2 is version 2.5.16 fired up via q3map2build v1.0 build 25…


(sock) #4

Getting DotProduct2 to work without alpha fade brushes is difficult at best. The terrain blending does work from the vertex normal angle but there is other things to consider. Probably the most important factor is the texture alpha map. Here is an example below which has identical shaders, identical terrain and uses the latest q3map2 compiler.

The image on the left is mud (secondary) on the flat terrain and grass (primary) on the steep sections. The image to the right is just a mush of grass (primary) with spots of mud (secondary). If you want to only test DotProduct2 then u have to manually tweak the alpha channel yourself.

The image above shows the two different alpha channels that are used in the top image above. As you can see the image on the left has virtually no alpha detail and will really only work with vertex normal angles and the image on the right has alpha detail which will work best when using both systems together.

The bottom line is you cannot expect one texture to work in all situations and I spent weeks tweaking my textures to work how I wanted them. Most of the textures in my example files are designed to work with both systems and not one or the other.

When I created the terrain in my final map “Pyramid of the Magician” I hand built every brush to what I wanted. I did not start with a pre-generated mesh, I built the landscape to reflect what shapes I wanted. Then I decided where the all base materials were going to be and the blending edges. I accented all paths and routes with alpha fade brushes. Finally I tweaked the finally landscape with alpha fade brushes so that it looked right.

The key to working with the new system is to stop treating the landscape as one type of material, but instead several materials all stitched/blended together. The natural look of dotproduct2 alpha blends only really works when used together with a subtle amount of alpha fade brushes.

If you use DotProduct2 by itself, you will only produce alot of mushy blends. If you use Alpha Fade by itself, you will only produce limited alpha values or forced looking blends. Its only when you use both together that the terrain looks different.

Sock
:moo:


(thore) #5

i think the problem is my lack of understanding what results one can expect from dotproduct2 terrain.
following your tutorials i have a combination of both dp2 and alpha brushes in mind, i just think the
plain dp2 (withouth the help of alpha brushes) doesn’t come out enough (read: not at all), that’s why
i compared the original tga texture with the appropriate shader. by using the textures provided by you
i thought there is no need for me to worry about all those parameters affecting the blending so i could
solely concentrate on understanding how the system works. now i’m kinda shocked as i was wrong with this :wink:

let’s have a look at a picture that was originally posted by DickDastardly in his thread
about Problems with foliage on dotproduct terrain:

now when reading about terrain slope affecting dp2 blending i thought those rocks
shining through where solely done with the dp2 blending technique - and alpha brushes
only are to be used when i want to blend (or modify the strength) at spots the shader
parameter q3map_alphaMod dotproduct2 ( 0.0 0.0 0.75 ) doesn’t affect (or not
in the way i want).

would you say those blendings are dp2-only or manually applied via alpha brushes?
you can guess where the vertices are in this image… the thing that bugs me is that
the blending centers on triangle faces and not on the vertices as i know it from the use
of alpha brushes.

i understand tweaking the alpha channel (brighten it up) will let the secondary texture
shine through the more, the brighter the channel becomes - but looking at the images
i provided with my first post i would expect this change to take effect on the whole
surface, e.g. the whole surface gets more mud-ish, but overall appearance lacks of
the variety as seen at dick’s picture.

i’ll have a try on brightening the alpha channels… we’ll see what it turns out as… :poke:


(thore) #6

ooookay, i got it. kind of.

here are some more pics to show the process:


this image shows the same setup as before (plain tga left of the alpha brush, shader on the
right) apart from the alpha channels of both moss and mud textures have been darkened by
a whole 100%. the plain tga on the left now shows cracks of complete transparency. the
area the alpha brush takes effect on has now slightly increased, however the the moss
shader on the right doesn’t show any variety of blending between pri and sec texture.

with the darkened alpha channel the secondary (mud) texture has a rather sharp
blending with the moss. this isn’t that good to see due to jpeg compression, but one can
clearly see the border ingame.

actually i meanwhile have understood there is no need to alter (or even include) an alpha
channel of the primary texture, as the pri tex lays below the sec tex and will allways
be drawn at full opacity. it’s the sec tex that gets blended on top of the pri tex, so you
might want to ignore the cracky tga on the left side :wink:


now with the alpha channels darkened i suddenly stumbled over the dp2 parameter in the
shader: q3map_alphaMod dotproduct2 ( 0.0 0.0 0.75 ). since i want to blend on sloped
terrain i had to change these values, because with a value of “0” on both x and y axis there
couln’t be any blending. just to be radical and see dramatic changes in the case that
really something is happening when altering the values, i set both x and y axis to the
same as z axis, resulting in q3map_alphaMod dotproduct2 ( 0.75 0.75 0.75 )
and the above picture shows some variety and blending of pri and sec texture.

now time has come to reset the alpha chanels to their default (as supplied by sock) values
and have a look at the results with original alpha channels but with the altered q3map_alphamod dotproduct2 values:

i still have do do some experimenting on those values and examine the effect of alpha
channels together with altered dp2 params… but at least my hill isn’t that plain green
any more :moo:

thx sock for your tut and advice… sadly your tut hasn’t covered how dp2 works that
detailed (how alpha channels and dp2 vectors affect texture blending), maybe you’re
going to add this later on? would have saved a lot of hassle :bump:
but that’s the only thing i’ve missed in your otherwise very comprehensive tutorial…

thx & cheers


(nUllSkillZ) #7

sock has done some math calculation in his article:
http://www.planetquake.com/simland/pages/articles/terrain1_2.htm

If I get this right dotproduct2 can “seperate” the texturing of the vertical form the horizontal terrain.

horizontal:
At horizontal brushes the vertices have a z-component near 1.
So with sock’s calculation you get:
(0 0 1)(0 0 a) = 00 + 00 + (1a)(1a) = a*a

With a = 0.7 the result would be 0.49.
Which means (nearly) 50 % (a mixture) of both textures is visible.

vertical:
At vertical brushes the vertices have a z-component near 0.
So with sock’s calculation you get:
(0 0 0)(0 0 a) = 00 + 00 + 0a = 0

Which means only one texture is visible.

Edit:

Post has been edited.
The question I’ve at the moment is:
If the dotproduct is the used alpha value or if the value of the dotproduct is multiplied with the actual alpha value to get a new one.


(obsidian) #8

See here:
http://shaderlab.com/q3map2/shader_manual/ch3.html#alphamod

When using alphaMod dotproduct terrain, the user sets a single vector ( x y z ) value. This vector allows the user to have some basic control over how the blending will be distributed on the terrain surface.

A second vector is taken from the vertex normal of each vertice on the terrain mesh.

Multiplying the two vectors together using dp math, we get a new value. This new value represents the normalized percentage value of alpha transparency for that given vertice on the terrain mesh.

This yields a result where the steeper the terrain, the more transparent the primary texture will become.


(obsidian) #9

You can think of the dotproduct values as being the % opacity of the texture that you want to set as a default. This default value will then get altered depending on the steepness of the terrain (vertex normals). For example:

q3map_alphaMod dotproduct ( 0 0 1 ) - this implies that the primary texture will be 100% opaque on horizontal surfaces (dp normal is aligned with Z-axis).
(0 0 1)(0 0 1) = 00 + 00 + 11 = 1

q3map_alphaMod dotproduct ( 0 0 0.75 ) - this implies that the primary texture will be 75% opaque on horizontal surfaces.
(0 0 0.75)(0 0 1) = 00 + 00 + 0.751 = 0.75

q3map_alphaMod dotpoduct ( 0.25 0 1 ) - this implies that the primary texture will be 25% opaque on surfaces facing the x-axis, and 100% opaque on surfaces facing the z-axis. Sloped surfaces between the x and z-axes will lie somewhere between 25-100% opacity. Sloped surfaces between the y and z-axes will lie between 0 and 100% opacity.
Vertex normal facing x-axis: (0.25 0 1)(1 0 0) = 0.25
Vertex normal facing z-axis: (0.25 0 1)
(0 0 1) = 1
Vertex normal facing y-axis: (0.25 0 1)(0 1 0) = 0
Vertex normal between x and z-axis: (0.25 0 1)
(0.5 0 0.75) = 0.250.5 + 00 + 10.75 = 0.875 (87.5% opaque)
Vertex normal between y and z-axis: (0.25 0 1)
(0 0.7 0.12) = 0.250 + 00.7 + 1*0.12 = 0.12 (12% opaque)

As mentioned in the shader manual, q3map_alphaMod dotproduct2 squares the final results of the dotproduct math, resulting in a sharper falloff.


(nUllSkillZ) #10

Thank you very much for your explanation obsidian.


(thore) #11

actually it’s quite easy once you’ve understood how dp2 works… however you have to understand
first. and the hints in sock’s tut were very subtle if you don’t know yet what he’s talking about. the
whole vertex merging process is well described… but this little dotproduct parameter… darn, took
me quite a while to figure that one out. i’m currently playing with dp2 values and will soon experiment
with different alpha channels… maybe i can come up with something useful. maybe.

thx for clarification, obsi ^^


(nUllSkillZ) #12

A test I’ve made today:

Editor image:

In the foreground dotproduct.
In the background dotproduct2.
I’ve used the vector ( 0.0 0.0 1.0 ).

I’ve darkened the source image of the secondary texture to get a seamless transition.
Only if you are very near you can notice a seam.

The alpha-channel of the secondary texture is a grayscaled, inverted, darkened and sharpened (contrast) version of the primary texture.

Alpha-channel:

I’m using gimp for the picture manipulation (+ a self written tool to merge RGB- and ALPHA-channel).
In gimp the scales range from 0 to 127.

Here are my factors:
Brightness of the source of the secondary texture: -23 ( ~ -18%)

Alpha channel:
Brightness of the grayscaled and inverted primary texture: -23 ( ~ -18%)
Contrast of the grayscaled and inverted primary texture: +63 ( ~ 50%)


(Loffy) #13

But, doesn’t allies and axis spawn too close to each other now?
// Loffy

(joke)


(thore) #14

i rather wonder what the objectives are :>

i’m glad to see nullskillz is also testing… maybe we can complile some ideas and tipps
on how to get dotproduct working? strategies on how to find the values in order to
achieve a certain effect, basic setup rules for alpha channels and stuff like that…

there are some guides on how to apply dp2 blending… but not how to configure it.
this seems to be the hard part :\