Shader ====== **Classic Q3A .shader files** - Traditional Quake 3 Arena-style shader definitions that define how textures appear in-game. Location -------- The convention is to place shaders in either - ``scripts`` - Or ``fxshaders`` (for textures used in fx) Format ------ .. code-block:: shader shader_name { // Global shader parameters parameter value // Stage 1 { map texture/path // Stage-specific parameters } // Stage 2 (optional) { map textures/my_overlay // Stage-specific parameters } } shader2_name { // ... } Common Shader Patterns ---------------------- Some common patterns for shaders for different purposes from the game files Standard Lit Texture ____________________ .. code-block:: shader shader_name { { map textures/path/texture rgbGen exactVertex nextbundle map $lightmap } } Transparent Texture ___________________ .. code-block:: shader texture_name { surfaceparm trans { map textures/path/texture blendFunc blend rgbGen vertex } } Static Water Shader ___________________ Basic static water with scrolling texture and lightmap: .. code-block:: shader textures/sfx/stalingradwater { qer_editorimage env/watercolor_dn tessSize 512 q3map_globaltexture surfaceparm trans surfaceparm nonsolid surfaceparm water surfaceparm nolightmap surfaceparm noshadow sort water { map textures/sfx/damwater.jpg tcMod Scroll .05 0 tcMod scale 4 4 rgbGen constlighting ( 0.65 0.68 0.69 ) } { map textures/sfx/damwateroverlay.jpg tcMod scroll -0.01 .01 tcMod scale 2 2 tcMod turb 1.03 0.2 1.03 rgbGen exactVertex blendFunc add nextbundle map textures/sfx/damwateroverlay.jpg tcMod scroll 0.02 .02 tcMod scale 4 4 tcMod turb 0.01 0.2 0.03 } } River/Flowing Water Shader __________________________ Advanced river water with normal mapping and reflections: .. code-block:: shader textures/sfx/stalingradwater_pj { qer_editorimage textures/sfx/wave_bump tessSize 256 deformVertexes wave 100 sin 2 2 0 .25 deformVertexes syncNormal 0.25 // For high-end cards (4+ texture units) { requires GL_MAX_TEXTURE_UNITS_ARB >= 4 requires GL_ARB_texture_cube_map requires GL_ARB_texture_env_combine requires GL_ARB_texture_env_dot3 rgbGen identity map heightToNormal textures/sfx/wave_bump tcMod scale .03125 .03125 tcMod scroll .0025 .00125 nextbundle map heightToNormal textures/sfx/wave_bump tcMod scale -.03125 -.03125 tcMod scroll .00125 -.0025 texEnvCombine { const = ( 0.5 0.5 0.5 0.5 ) rgb = INTERPOLATE_ARB(Cp, Ct, Ac) } nextbundle cubemap $renormalize tcGen sunHalfAngle tcMod bumpmapFrame texEnvCombine { rgb = DOT3_RGB_ARB(Cp, Ct) } nextbundle map $whiteimage texEnvCombine { const = ( .32 .36 .4 ) * identityLighting rgb = MODULATE(Cp, Cc) } } // For mid-range cards (3 texture units) { requires GL_MAX_TEXTURE_UNITS_ARB == 3 requires GL_ARB_texture_cube_map requires GL_ARB_texture_env_combine requires GL_ARB_texture_env_dot3 rgbGen identity alphaGen constLighting .37 blendFunc GL_SRC_ALPHA GL_ZERO depthWrite map heightToNormal textures/sfx/wave_bump tcMod scale .03125 .03125 tcMod scroll .00025 .00125 nextbundle map heightToNormal textures/sfx/wave_bump tcMod scale -.03125 -.03125 tcMod scroll .00025 -.00125 texEnvCombine { const = ( 0.5 0.5 0.5 0.5 ) rgb = INTERPOLATE_ARB(Cp, Ct, Ac) } nextbundle cubemap $renormalize tcGen sunHalfAngle tcMod bumpmapFrame texEnvCombine { rgb = DOT3_RGB_ARB(Cp, Ct) alpha = REPLACE(Af) } } // Base water color for all cards { requires GL_MAX_TEXTURE_UNITS_ARB >= 3 requires GL_ARB_texture_cube_map requires GL_ARB_texture_env_combine requires GL_ARB_texture_env_dot3 map textures/sfx/stalinriver.jpg rgbGen identity alphaGen constLighting .3 blendFunc GL_SRC_ALPHA GL_ONE tcMod scale .25 .25 tcMod scroll -.0375 .0375 nextbundle cubemap env/stalingrad tcgen reflection alphagen const .25 blendFunc blend } } Sky Shader __________ Basic sky shader with environment mapping ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader textures/sky/chateau { qer_editorimage textures/sky/chateau.tga surfaceparm sky surfaceparm nolightmap surfaceparm noimpact surfaceparm nomarks skyParms env/chateau 512 - sunfile chateau } Advanced sky with fog and multiple layers ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader textures/sky/test01 { qer_editorimage textures/sky/topclouds.tga surfaceparm sky surfaceparm nolightmap surfaceparm noimpact surfaceparm nomarks surfaceparm nodlight q3map_globaltexture q3map_lightsubdivide 512 q3map_sun 1.0 0.8 0.7 100 220 55 skyParms full 200 - fogvars ( .7 .7 .55 ) .000040 skyfogvars ( .7 .7 .55 ) .00040 { map textures/skies/newclouds.tga tcMod scroll -0.00025 -0.00075 tcMod scale 6 6 depthWrite } } Night sky with stars ^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader textures/sky/starfield { qer_editorimage textures/sky/starfield.tga surfaceparm sky surfaceparm nolightmap surfaceparm noimpact surfaceparm nomarks q3map_sun 1.0 0.8 0.7 100 220 55 skyParms env/starfield 512 - fogvars ( .05 .05 .07 ) .00033 skyfogvars ( .05 .05 .07 ) .00035 } Fire/Flame Shader _________________ Animated fire texture shader ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader gfx/effects/animated/jh_animfire { sort additive { AnimMap 14 map gfx/effects/animated/jh_animfire1 map gfx/effects/animated/jh_animfire2 map gfx/effects/animated/jh_animfire3 map gfx/effects/animated/jh_animfire4 map gfx/effects/animated/jh_animfire5 map gfx/effects/animated/jh_animfire6 map gfx/effects/animated/jh_animfire7 blendFunc add rgbGen vertex tcmod scale -1 1 } } Static fire texture with scrolling mask ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader skins/firetexture { surfaceparm nonsolid surfaceparm noshadow deformVertexes flap s 2 sin 2 2 0 5 { map skins/firetexture blendfunc add rgbGen identityLighting nextbundle map textures/sfx/firemask } { map textures/sfx/firescroll tcmod scroll -1 1.5 blendFunc add nextbundle map textures/sfx/firemask } } Smoke Effects _____________ Animated smoke column ^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader textures/effects/smokecolumn { sort seethrough { animMap 17 map clamp gfx/effects/animated/smokecolumn1 map clamp gfx/effects/animated/smokecolumn2 map clamp gfx/effects/animated/smokecolumn3 map clamp gfx/effects/animated/smokecolumn4 map clamp gfx/effects/animated/smokecolumn5 map clamp gfx/effects/animated/smokecolumn6 map clamp gfx/effects/animated/smokecolumn7 map clamp gfx/effects/animated/smokecolumn8 map clamp gfx/effects/animated/smokecolumn9 map clamp gfx/effects/animated/smokecolumn10 map clamp gfx/effects/animated/smokecolumn11 map clamp gfx/effects/animated/smokecolumn12 map clamp gfx/effects/animated/smokecolumn13 map clamp gfx/effects/animated/smokecolumn14 map clamp gfx/effects/animated/smokecolumn15 map clamp gfx/effects/animated/smokecolumn16 map clamp gfx/effects/animated/smokecolumn17 blendFunc multiply rgbGen vertex } } Simple smoke particle ^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader gfx/effects/dark_smoke { entityMergable { map /gfx/effects/dark_smoke blendfunc blend rgbGen vertex } } Explosion Effects _________________ Explosion smoke plume ^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader gfx/effects/explosion/smokeplume1 { entityMergable { map /gfx/effects/explosion/smokeplume1 blendfunc blend rgbGen vertex } } Impact Effects ______________ Flesh impact ^^^^^^^^^^^^ .. code-block:: shader gfx/impact/flesh_hit1 { entityMergable { map gfx/impact/flesh_hit1 blendfunc blend rgbGen vertex } } Spark impact (additive) ^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader gfx/impact/sparkflash { entityMergable sort additive { map gfx/impact/sparkflash blendFunc GL_ONE GL_ONE rgbGen vertex } } Metal spark ^^^^^^^^^^^ .. code-block:: shader gfx/impact/metal_spark1 { entityMergable sort additive { map gfx/impact/metal_spark1 blendFunc GL_ONE GL_ONE rgbGen vertex } } Weapon Effects ______________ Muzzle flash ^^^^^^^^^^^^ .. code-block:: shader gfx/weaponfx/88muzflash1 { entityMergable sort additive cull disable { map clamp gfx/weaponfx/88muzflash1 blendFunc GL_ONE GL_ONE rgbGen vertex } } Weapon trail ^^^^^^^^^^^^ .. code-block:: shader gfx/weaponfx/88runner { sort additive cull disable { map clamp gfx/weaponfx/88runner blendFunc GL_ONE GL_ONE rgbGen vertex } { map clamp gfx/weaponfx/88runner blendFunc GL_ONE GL_ONE rgbGen vertex tcMod rotate 30 } } Rocket plume ^^^^^^^^^^^^ .. code-block:: shader gfx/misc/rocketplume { { map /gfx/misc/rocketplume blendfunc blend tcMod transform -1 0 0 1 1 0 rgbGen vertex } } Sun and Light Effects _____________________ Global sun ^^^^^^^^^^ .. code-block:: shader gfx/sun/global { nomipmaps nopicmip { map clamp gfx/sun/global blendFunc add rgbGen identitylighting } } Sun flare ^^^^^^^^^ .. code-block:: shader gfx/sun/global_flare { nomipmaps nopicmip { map clamp gfx/sun/global_flare blendFunc gl_src_alpha gl_one rgbgen vertex alphaGen vertex } } Moon ^^^^ .. code-block:: shader gfx/sun/moon_full { nomipmaps nopicmip { map clamp gfx/sun/moon_full blendFunc add rgbGen identitylighting } } Searchlight/Beam Effects ________________________ Light beam with gradient ^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader skins/gradient1 { surfaceparm nonsolid surfaceparm noshadow nopicmip { map clamp textures/sfx/gradient1 blendfunc blend rgbGen identityLighting rgbGen dot 0 1.5 } { map textures/sfx/dustair tcmod scroll 0 0.1 blendFunc add } } Searchlight beam with autosprite ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader skins/searchlight_beam { surfaceparm nonsolid surfaceparm noshadow DeformVertexes autosprite2 { requires GL_ARB_texture_env_add map clamp skins\searchlight_beam rgbGen identityLighting blendfunc add } } Caustic/Underwater Effects __________________________ Sewer caustics with distortion ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader textures/sfx/sewercaustic { qer_editorimage textures/denmark/walls/brick@sewerblue_wall1 nopicmip // For cards with 2 TMUs { requires GL_MAX_TEXTURE_UNITS_ARB == 2 depthwrite map textures/sfx/sewercaustic.tga tcMod scroll -0.07 .05 tcMod scale 2 2 tcMod turb 0.11 0.2 0.03 nextbundle map textures/sfx/sewercaustic.jpg tcMod scroll 0.05 -0.05 tcMod scale 1 1 tcMod turb 0.10 0.2 0.20 } { requires GL_MAX_TEXTURE_UNITS_ARB == 2 depthfunc equal rgbGen exactVertex map $lightmap blendFunc filter } // For cards with 3+ TMUs { requires GL_MAX_TEXTURE_UNITS_ARB >= 3 depthwrite map textures/sfx/sewercaustic.tga tcMod scroll -0.07 .05 tcMod scale 2 2 tcMod turb 0.11 0.2 0.03 nextbundle map textures/sfx/sewercaustic.jpg tcMod scroll 0.05 -0.05 tcMod scale 1 1 tcMod turb 0.10 0.2 0.20 nextbundle map $lightmap blendFunc filter } // Final stage for all cards { depthfunc equal map textures/denmark/walls/brick@sewerblue_wall1.jpg rgbGen vertex blendFunc add nextbundle map $lightmap } } Sun Rays/God Rays _________________ Sun rays effect ^^^^^^^^^^^^^^^ .. code-block:: shader textures/sfx/sunray_sewer { qer_editorimage textures/sfx/sunray_sewer surfaceparm nonsolid cull none nopicmip { map textures/sfx/sunray_sewer.jpg tcMod scroll .05 0 blendFunc GL_ONE GL_ONE } { map textures/sfx/dustmotes_sewer.jpg tcMod scroll -0.05 .03 tcMod scale 2 4 tcMod turb 0.01 0.2 0.03 blendFunc GL_ONE GL_ONE } } Wake/Water Splash Effects _________________________ Player wake in water ^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader wake { { map clamp textures/sfx/splashalpha.tga blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA rgbGen vertex tcMod stretch sin 1 0.2 0 0.2 rgbGen wave sin 0.3 0.3 0 0.2 } } Animated wake ^^^^^^^^^^^^^ .. code-block:: shader wakeAnim { { map clamp textures/sfx/splashalpha.tga blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA rgbGen vertex tcMod stretch sin 0 1 0 .25 } } Surface Effects (Bubbles, Froth) ________________________________ Surface bubbles ^^^^^^^^^^^^^^^ .. code-block:: shader gfx/effects/misc/surface_bubble { entityMergable sort additive { map gfx/effects/misc/surface_bubble blendFunc GL_ONE GL_ONE rgbGen vertex } } Surface froth ^^^^^^^^^^^^^ .. code-block:: shader gfx/effects/misc/surface_froth { entityMergable sort additive { map gfx/effects/misc/surface_froth blendFunc GL_ONE GL_ONE rgbGen vertex } } Dust and Particle Effects _________________________ Dust sheet ^^^^^^^^^^ .. code-block:: shader gfx/effects/misc/dustsheet1 { entityMergable { map /gfx/effects/misc/dustsheet1 blendfunc blend rgbGen vertex } } Snow sheet ^^^^^^^^^^ .. code-block:: shader gfx/effects/misc/snowsheet1 { entityMergable { map /gfx/effects/misc/snowsheet1 blendfunc blend rgbGen vertex } } Water sheet ^^^^^^^^^^^ .. code-block:: shader gfx/effects/misc/watersheet1 { entityMergable { map clamp /gfx/effects/misc/watersheet1 blendfunc blend rgbGen vertex } } Special Surface Types _____________________ Cloth/Flag with animation ^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader skins/russianboatflag { surfaceparm cloth cull none deformVertexes flap s 2 sin 2 3 0 5 { map skins/russianboatflag rgbGen lightingDiffuse } } Spinning propeller ^^^^^^^^^^^^^^^^^^ .. code-block:: shader skins/stuka_prop { surfaceparm metal cull none { map clamp skins/stuka_prop tcMod rotate 5000 blendFunc blend } } Metal with environment mapping ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader skins/stalin_statue { surfaceparm metal nomipmaps nopicmip { map textures/sfx/environmap_bronze.tga tcgen environment rgbgen lightingdiffuse } { map skins/stalin_statue blendFunc GL_ONE_MINUS_SRC_ALPHA GL_SRC_ALPHA rgbgen lightingdiffuse } } Common Utility Shaders ______________________ No-draw shader (invisible) ^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader textures/common/nodraw { surfaceparm nodraw surfaceparm nomarks surfaceparm playerclip surfaceparm monsterclip surfaceparm vehicleclip surfaceparm trans } Water clip (collidable water) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader textures/common/water_clip { qer_editorimage textures/common/water.tga surfaceparm water surfaceparm playerclip surfaceparm monsterclip surfaceparm nodraw } Trigger/clip shaders ^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader textures/common/aitrig { qer_trans 0.32 surfaceparm nodraw surfaceparm nomarks surfaceparm nonsolid surfaceparm trans surfaceparm trigger } Vehicle clip ^^^^^^^^^^^^ .. code-block:: shader textures/common/vehicleclip { qer_trans 0.3 surfaceparm metal surfaceparm nodraw surfaceparm nomarks surfaceparm nonsolid surfaceparm vehicleclip surfaceparm trans } Dlight (Dynamic Light) Shader _____________________________ .. code-block:: shader dlightshader { nofog { map $dlight rgbGen exactVertex blendFunc GL_DST_COLOR GL_ONE texGen lightmap depthFunc equal } } Shadow Shader _____________ .. code-block:: shader markShadow { nofog polygonOffset { map textures/sfx/shadow_soft.tga blendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR rgbGen exactVertex } } 2D/UI Shaders _____________ Console background ^^^^^^^^^^^^^^^^^^ .. code-block:: shader console { { map $whiteimage rgbGen constLighting ( 0.15 0.15 0.15 ) } } Lagometer (netgraph) ^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader lagometer { nopicmip { map gfx/2d/lag.tga } } View fade (black) ^^^^^^^^^^^^^^^^^ .. code-block:: shader viewFadeBlack { sort nearest { map *white blendFunc GL_ZERO GL_ONE_MINUS_SRC_ALPHA rgbGen wave square 0 0 0 0 alphaGen entity } } View blood blend ^^^^^^^^^^^^^^^^ .. code-block:: shader viewBloodBlend1 { sort nearest { map gfx/2d/viewblood1.tga blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA rgbGen identityLighting alphaGen vertex } } White shader (default) ^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader white { { map *white blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA rgbGen vertex } } Terrain with Alpha Blending ___________________________ Alpha-blended terrain (grass, foliage) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: shader textures/normandy/ground/trench_base { surfaceparm grass surfaceparm noncolliding polygonOffset qer_editorimage textures/normandy/ground/dirt@trench_goundbase.tga { map textures/normandy/ground/dirt@trench_goundbase rgbGen exactVertex alphagen vertex blendFunc blend nextbundle map $lightmap blendFunc filter } }