Can you combine linear and non-linear alpha blending?


(Apple) #1

I can create a linear blend like the following by using an empty alpha channel:

And I can create a non-linear blend like the following by using a modified alpha channel:

But with the non-linear blend the grass never completley fades away, like you see with the linear blend. So is there a way to combine the two?

Where initialy it will blend with the modified alpha channel, giving a more natural looking transition, but then eventualy having the grass fade away completley.


(The Wanderer) #2

yes you can.
Just use an alphaMod brush with 0 alpha to cover the portions where you don’t want anymore grass.
The alphaMod brush value will override any other alpha setting for the vertex.


(thegnat) #3

I recommend reading Socks outstanding article on terrain creation here.


(Apple) #4

That’s exactly what I’m doing:

And while that works fine for the linear blending, the grass never totaly disappears with the non-linear blending.


(Apple) #5

I have, and it’s no help to me. In his examples you can see the non-linear blending never fully fades away either:


(The Wanderer) #6

Post your grass shader and the alpha 0 shader you’re using on the alphaMod brush


(Apple) #7

The alpha 0 shader is the one that comes with the latest version of Q3map2:


textures/common/alpha_0
{
	qer_trans 0.5
	q3map_alphaMod volume
	q3map_alphaMod scale 0
	surfaceparm nodraw
	surfaceparm nonsolid
	surfaceparm trans
}

And the grass to dirt shader:


textures/test/ter_grasstodirt
{
   qer_editorimage textures/test/grasstodirt.tga
	q3map_nonplanar
	q3map_shadeangle 120
	{
		map textures/test/dirt.tga
		rgbGen identity
	}
	{
		map textures/test/grass.tga
		blendFunc GL_ONE_MINUS_SRC_ALPHA GL_SRC_ALPHA
		rgbGen identity
		alphaGen vertex
	}
	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
		rgbGen identity
	}
}


(The Wanderer) #8

replace

q3map_alphaMod scale 0

with

q3map_alphaMod set 0

you need to recompile for this change to take effect


(Apple) #9

This change had no effect.


(The Wanderer) #10

oopss didn’t pay much attention to it before but your blendfunc is backwards.
you should have

blendFunc  GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA

( which is basically just blendFunc blend) in stead of what you have. Right now you’re using GL_ONE_MINUS_SRC_ALPHA for the grass texture which is basically 1, so your grass never fades.
This should give you the result you’re looking for.
Anyway i recommend you still change all your scale commands to set in the alphamod shaders because i’ve had some inconsistent results with scale.

Also you’re not using non-linear blending in your example. Non linear blending involves the use of dotproduct2 in your shader which calculates the vertex alphas based on the square(hence non-linear) of the dotproduct of your vertex normals and the vector parameter passed. I recomend you use dotproduct2 blending in your shader as it’s ideally suited for this kind of organic texture blending and it will give you excellent and very natrual distribution of your grass over the dirt.