Fading blended surfaces with vertex alpha and masks.

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Post Reply
Herr W
Posts: 90
Joined: Tue May 16, 2006 8:53 am

Fading blended surfaces with vertex alpha and masks.

Post by Herr W »

Hi everyone!

I'm trying to create a rising column of smoke with this texture

Image

... and this shader:

Code: Select all

textures/13isl_toon/smoke
{
surfaceparm trans	
surfaceparm nomarks	
cull none
nopicmip   
deformvertexes autosprite
		{
        map textures/13isl_toon/smoke.jpg
        blendfunc filter
        tcMod scroll 0 .75  			
		}
}
- Problem is that the texture doesn't fade in/out at the bottom and the top. I guess I have to mask it with another texture...

... maybe one like this:
Image

... and an appropiate blendfunc, but have no idea which. Trial and error hasn't worked so far :sly:

Anyone with an idea?!
[color=#FF0000]Visit MONKEYS of DOOM at [url]http://www.monkeysofdoom.org[/url][/color]
o'dium
Posts: 11712
Joined: Sun Mar 25, 2001 8:00 am

Re: Shader for a column of smoke

Post by o'dium »

What game?
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Shader for a column of smoke

Post by obsidian »

@o'dium: Q3, presumably.

HINT: Take a look at the Q3 stock grate textures. Pretend that the grate is your mask and the lightmap stage is your smoke.

First stage will have alphaFunc GE128, depthWrite. That basically tells the shader to use THIS alpha.

Second stage will have depthFunc equal, basically saying use THAT alpha.

Alternatively (and probably easier all the while reducing the need for the extra stage) you can also use Q3Map2 alphaMod volume brushes to control the alpha effect.
Herr W
Posts: 90
Joined: Tue May 16, 2006 8:53 am

Re: Shader for a column of smoke

Post by Herr W »

... Yes, Q3.

Thanks, obsidian!

The "cybergrate3"-shader seems to have everything on board you were talking about, plus an animated texture in the background...

(it originally looks like this:)

Code: Select all

textures/base_floor/cybergrate3
{
    cull disable
    surfaceparm alphashadow
    surfaceparm	metalsteps	
    surfaceparm nomarks
        {
                map textures/sfx/hologirl.tga
                blendFunc add
                tcmod scale  1.2 .5
                tcmod scroll 3.1 1.1
		
        }
        {
                map textures/base_floor/cybergrate3.tga
                alphaFunc GE128
		depthWrite
        }
        {
		map $lightmap
		rgbGen identity
		blendFunc filter
		depthFunc equal
	}
}
... Putting in my textures results in this:

Code: Select all

textures/13isl_toon/smoke
{
    cull disable
    surfaceparm alphashadow
//    surfaceparm	metalsteps	
    surfaceparm nomarks
	surfaceparm trans
	deformvertexes autosprite
        {
        map textures/13isl_toon/smoke.tga
		blendfunc filter
        tcMod scroll 0 .25 
        }
        {
        map textures/13isl_toon/smoke_mask.tga
        alphaFunc GE128
		depthWrite
        }
        {
		map $lightmap
		rgbGen identity
		blendFunc filter
		depthFunc equal
	}
}
- By far the most complicated shader ever in Monkeys of Doom :cool:

... This is the alpha channel of the "mask"-texture (with it's other channels pure black):

Image

Surprisingly the result looks like this:

Image

... with black borders where the smoke should fade in and out. - And even if they weren't there: The fading looks pretty unsmooth. Could have something to do with that "alphaFunc GE128", but the alternatives ("GT0", "LT128") don't work either... :confused:
[color=#FF0000]Visit MONKEYS of DOOM at [url]http://www.monkeysofdoom.org[/url][/color]
o'dium
Posts: 11712
Joined: Sun Mar 25, 2001 8:00 am

Re: Shader for a column of smoke

Post by o'dium »

I didn't even know alpha masks were supported in Q3, shows how much I knew about that shader language :p
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Shader for a column of smoke

Post by obsidian »

Oh... wait... I wrote that at 2A.M. so wasn't thinking clearly. The Q3 mask takes all or nothing values rather than the full alpha values. That won't work in this case. I'm sorry for sending you on a goose chase.

The second method will certainly work. It's usually used on Q3Map2 blended terrain, but you can set up a similar shader and add alphaMod volume brushes on the top vertexes of the smoke trail and it will assign vertex alpha values to the brush. It'll also simplify things down to a single stage shader, so better for performance. It works by vertex alpha, so you'll need a couple more tessellation points halfway between the top and bottom of the smoke trail (see screenshot). Note that I'm using autosprite2 so the brush segments must be taller than they are wide.

[lvlshot]http://members.lycos.co.uk/quakeroats/q3wtemp/alphaMod_smoke.jpg[/lvlshot]

The only thing absolutely required is alphaGen vertex. This tells Q3Map2 that this surface will be assigned vertex alpha values.

Code: Select all

textures/test/smoke
{
	cull none
	deformVertexes autosprite2
	surfaceparm nodlight
	surfaceparm nonsolid
	surfaceparm trans
	qer_alphaFunc gequal 0.5
	{
		map textures/test/smoke.tga
		tcMod scroll 0 0.25
		blendFunc blend
		alphaGen vertex
	}
}
Note the use of common/alpha_0 at the top and bottom of the smoke. It must overlap the vertex points. It's a shader found in the extras for Q3Map2, add this to your common.shader if you don't have it already.

Code: Select all

textures/common/alpha_0
{
	qer_trans 0.5
	q3map_alphaMod volume
	q3map_alphaMod scale 0
	surfaceparm nodraw
	surfaceparm nonsolid
	surfaceparm trans
}
BTW, you have a lot of whitespace on that texture. Any reason why you're not reducing it down to something like 64x256?

That map looks awesome. You're making some good progress on this thing.
Herr W
Posts: 90
Joined: Tue May 16, 2006 8:53 am

Re: Shader for a column of smoke

Post by Herr W »

@obsidian: Cool! Works & looks great! Thanks a lot for spending so much time on this!!!

Image
BTW, you have a lot of whitespace on that texture. Any reason why you're not reducing it down to something like 64x256?
I thought the texture had to be square for the "deformvertexes autosprite" command. Hadn't heard about "... autosprite2" so far. - I definitely learned something these days! :D
That map looks awesome. You're making some good progress on this thing.
Thanks! It's still great fun to see Q3 becoming cartoonier and cartoonier. The map on the screenshots is sst13's "13 Islands". I got it from him to add some Monkeys-of-Doom-style eye-candy. Think it's making good progress...

PS: Could you change the topic into something smarter? "Q3 alpha masking" or so... Might be better to find for people with a similar problem.
[color=#FF0000]Visit MONKEYS of DOOM at [url]http://www.monkeysofdoom.org[/url][/color]
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Shader for a column of smoke

Post by obsidian »

The brush face needs to be square for autosprite (not necessarily the texture, though 99% of the time it is anyway), not so for autosprite2 (needs to be longer on one side).

I think you can change the topic title yourself if you're the original poster by editing your first post. Anyway, I've changed it for you.
dichtfux
Posts: 571
Joined: Thu Feb 02, 2006 10:51 pm

Re: Fading blended surfaces with vertex alpha and masks.

Post by dichtfux »

Both that screenshot & the smoke look sweeet!
[color=#FFFFFF][url=http://maps.rcmd.org]my FPS maps[/url][/color]
Post Reply