Page 1 of 1
Fading blended surfaces with vertex alpha and masks.
Posted: Tue Jul 01, 2008 3:04 pm
by Herr W
Hi everyone!
I'm trying to create a rising column of smoke with this texture
... 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:
... and an appropiate blendfunc, but have no idea which. Trial and error hasn't worked so far
Anyone with an idea?!
Re: Shader for a column of smoke
Posted: Tue Jul 01, 2008 3:09 pm
by o'dium
What game?
Re: Shader for a column of smoke
Posted: Wed Jul 02, 2008 4:32 am
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.
Re: Shader for a column of smoke
Posted: Wed Jul 02, 2008 9:11 am
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
... This is the alpha channel of the "mask"-texture (with it's other channels pure black):
Surprisingly the result looks like this:
... 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...

Re: Shader for a column of smoke
Posted: Wed Jul 02, 2008 9:57 am
by o'dium
I didn't even know alpha masks were supported in Q3, shows how much I knew about that shader language

Re: Shader for a column of smoke
Posted: Wed Jul 02, 2008 4:08 pm
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.
Re: Shader for a column of smoke
Posted: Thu Jul 03, 2008 3:30 pm
by Herr W
@obsidian: Cool! Works & looks great! Thanks a lot for spending so much time on this!!!
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!
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.
Re: Shader for a column of smoke
Posted: Thu Jul 03, 2008 4:15 pm
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.
Re: Fading blended surfaces with vertex alpha and masks.
Posted: Fri Jul 04, 2008 9:57 am
by dichtfux
Both that screenshot & the smoke look sweeet!