About "alphaGen portal"
The shader directive alphaGen is used to modulate a surface's vertex alpha values. alphaGen features a number of basic functions, but the portal function is a special case typically used to "fade" a teleportation portal or mirror from view, occluding the camera's view at the other end. The distance value is the maximum distance from which the effect begins to appear. Specifically, it generates vertex alpha values based on the distance from the viewer to the surface.
- Directive: alphaGen
- Function: portal
- Value: (distance in world units)
Several Quake 3 maps (q3dm7, for example) have a teleporter where a portal camera entity is linked to the shader surface. Of interest here is the cloudy layer that fades away as the player approaches the surface, revealing the teleporter destination.

Here is a shader from Quake 3 Arena, used on a teleportation portal:
textures/sfx/portal_sfx { portal surfaceparm nolightmap deformVertexes wave 100 sin 0 2 0 .5 { map textures/sfx/portal_sfx3.tga blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA depthWrite } { map textures/sfx/portal_sfx1.tga blendfunc gl_dst_color gl_zero tcMod rotate 360 } { map textures/sfx/portal_sfx.tga blendfunc gl_one gl_one rgbgen wave inversesawtooth 0 .5 .2 .5 } { map textures/sfx/portalfog.tga blendfunc gl_src_alpha gl_one_minus_src_alpha alphagen portal 256 rgbGen identityLighting tcmod rotate .1 //.1 tcmod scroll .01 .03 } }
The portal general shader directive is only used if a camera portal entity is intended for use with the surface. This allows the misc_portal_surface entity to "lock on" to the surface and use it as a display for the camera.
For the actual blending, blendFunc gl_src_alpha gl_one_minus_src_alpha sets the blending to occur by vertex alpha and alphaGen portal tells the surface that the vertex alpha changes should start occurring at 256 world units away.
Exploiting "alphaGen portal" for Other Special Effects
As interesting as a fading portal is, it's presence in a typical map is pretty sparce. Thankfully, alphaGen portal goes further than just for slipgates into worlds unknown. We can exploit this feature for any number of effects where the surface is required to fade in or out of view based on variable distance from the player.

Here is an example, some light flares that either fade in or out of view:
textures/obsidian_test/flare-fade-in { cull none deformVertexes autosprite surfaceparm nodlight surfaceparm nolightmap surfaceparm nonsolid surfaceparm trans qer_trans 0.75 { map textures/obsidian_test/beam_halogen.tga //fade in approaching blendFunc GL_ONE_MINUS_SRC_ALPHA GL_ONE //distance to start fading alphaGen portal 512 } } textures/obsidian_test/flare-fade-out { cull none deformVertexes autosprite surfaceparm nodlight surfaceparm nolightmap surfaceparm nonsolid surfaceparm trans qer_trans 0.75 { map textures/obsidian_test/beam_halogen.tga //fade out approaching blendFunc GL_SRC_ALPHA GL_ONE //distance to start fading alphaGen portal 512 } }
The general directive portal isn't needed here since there is no camera or mirror surface needed. The flare begins to fade in or out at 512 world units away from the player as set by alphaGen portal.
To control whether the effect fades in or out, two different blendFuncs are used, GL_ONE_MINUS_SRC_ALPHA GL_ONE to fade the flare in as the player approaches, and GL_SRC_ALPHA GL_ONE to fade the flare out.
Taking It Further
Flares are just one example of what you can do with this. Think about fading out foliage or grates from view in the distance to prevent them from mipmapping out of detail, a ghostly figure in the dark corner which disappears when you approach, weapon location markers that appear as you approach, a sad face that changes to a happy face when you arrive.