Shaders - an explanation

Post anything to do with editing Nexuiz here. Whether its problems you've had, questions, or if you just want to show off your work.

Moderators: Nexuiz Moderators, Moderators

Thu Mar 09, 2006 4:12 am

  • As there seems to be some confusion as to what shaders are and what they do in relation to nexuiz/quake3, I thought I might write a little something that might help people to understand them better.

    Shaders are simple text-based files that is used by both the compiler (q3map2), and the engine (darkplaces/quake3). They contain instructions for both of these things in relation to specific textures, telling whether or not the texture moves, whether it's a liquid, how to blend the texture, etc. Darkplaces (nexuiz's engine) is only able to interpret a smaller set of instructions from the shaders than Quake3 (which the shader system was originally created for), and thus less needs to be explained.

    A large part of the shader system that people have trouble with is how GTKRadiant and Q3map2 work with them. I'll start with GTKRadiant, as it's interaction with shaders is relatively irrelevant.

    GTKRadiant:

    Radiant uses the shaders in a two basic ways:

    -to display specific transparencies on textures such as slime and water
    -to denote which textures have an accompanying shader

    It looks for shaders in the /scripts/ directory of your nexuiz or quake3 base folder (either /data/ or /baseq3/), and it specifically checks a file called shaderlist.txt for a listing of texture and shader directories.

    For example, if you had some textures inside of /textures/test/ that you wanted displayed, you would open up shaderlist.txt and add test to the list. Then, under the textures tab in GTKRadiant, test would show up in the list of directories.


    Now, on to q3map2:

    Q3map2 is what compiles maps for nexuiz. Part of it's job is to make sure the engine recognizes which textures are lava/water/slime, which brushes are transparent, etc. To do this, it needs to load shaders when it is compiling. It, like Radiant, looks for shaders inside of the /scripts/ directory, and also references shaderlist.txt.

    For example:

    If you had textures/test/slime.tga applied to a brush, and had a shader that described that texture as being slime inside of scripts/test.shader, then you would want to add test to the list inside of shaderlist.txt. Q3map2 would then read shaderlist.txt, see test listed, check /scripts/test.shader for any textures that had special properties, and then properly flag any brushes that had slime.tga applied to them as being a slimey liquid.

    Now, on to the actual shaders, with a few specific examples that apply to nexuiz:

    Example 1: Lava/Slime/Water shaders

    Lets say you want a slime texture somewhere in your map. What you need first is a slime texture. Let's name it slime1.tga and place it inside of /textures/liquids/. So you should now have:

    textures/liquids/slime1.tga

    Now, let's write the shader. First off, open notepad, or whatever text editor you want to use. Copy and paste the following inside:

    Code: Select all
    textures/liquids/slime1
       {
          qer_editorimage textures/liquids/slime1.tga
          q3map_lightimage textures/liquids/slime1.tga
          q3map_globaltexture
          qer_trans .5

          surfaceparm noimpact
          surfaceparm slime
          surfaceparm nolightmap
          surfaceparm trans      

          q3map_surfacelight 100
          tessSize 32
          cull disable

          {
             map textures/liquids/slime1.tga
          }
    }


    Save this file as liquids.shader inside of your /scripts/ directory. You should now have two files:

    textures/liquids/slime1.tga

    and

    scripts/liquids.shader

    We now need to modify shaderlist.txt, which should be inside of your /scripts/ directory. Open it up, and add liquids to the list, if it is not already there.

    Now, open up GTKRadiant, and load the liquids texture selection. You should have a texture called slime1 with a white outline around it. This tells you that the shader is being recognized by Radiant. Assign this texture to a brush, and compile. Q3map2 should recognize the shader and flag the surfaces that use the texture as being slime.


    --I'll add more examples for transparency, and explain what each part of the shader does at a later time, I'm too tired from typing ATM :P--

    Hope this helps, feel free to ask questions, and we can compile a FAQ.
    User avatar
    Kaz
    Newbie
     
    Posts: 6
    Joined: Mon Mar 06, 2006 1:25 am

Sat Jul 22, 2006 10:47 am

  • hi,

    is it possible to have explanations about transparency... please :)
    parksto
    Member
     
    Posts: 25
    Joined: Sun May 07, 2006 1:30 pm

Mon Jul 24, 2006 8:03 pm

  • oligraphes wrote:hi,

    is it possible to have explanations about transparency... please :)


    Sure thing.

    You need two things to make transparency happen in darkplaces. A TGA image with a alpha channel and a shader. The tga is done with your favorite image editing app, put black in the alpha channel for transparent and while for soild. Next thing you need is a shader looking something like this:
    Code: Select all
    textures/tznex03/mgrid01
    {
       qer_editorimage textures/tznex03/mgrid01.tga
       surfaceparm nomarks
       surfaceparm trans
       surfaceparm alphashadow
       cull none
       nopicmip
       {
          map textures/tznex03/mgrid01.tga
          rgbGen identity
          depthWrite
          alphaFunc GE128
       }
       {
          map $lightmap
          blendfunc filter
          rgbGen identity
          tcGen lightmap
          depthFunc equal
       }
    }


    The thing in that shader that acctualy makes the transparency happen is this line:
    alphaFunc GE128

    This line:
    surfaceparm alphashadow
    is also worth nothing, it uses the alpha channel for the shadows insted of the brushes shape, making things look alot better.
    HOF:
    <Diablo> the nex is a "game modification"
    <Diablo> quake1 never had a weapon like that.
    <Vordreller> there was no need for anything over 4GB untill Vista came along
    <Samua>]Idea: Fix it? :D
    <Samua>Lies, that only applies to other people.
    User avatar
    tZork
    tZite Admin
     
    Posts: 1337
    Joined: Tue Feb 28, 2006 6:16 pm
    Location: Halfway to somwhere else

Tue Jul 25, 2006 8:08 am

  • ok, that work... but that's not what i want.
    i'd like to do a glass wall. like 0.5 in alpha channel :?

    is it possible ?
    parksto
    Member
     
    Posts: 25
    Joined: Sun May 07, 2006 1:30 pm

Tue Jul 25, 2006 8:15 am

  • thx tZork :)

    is it possible to make a simple transparent colored block which makes a bit light only with the shader file and without texture file ? (a bit like some non-moving and one-colored slime)

    i have another question, i don't know if its really about shaders actually... How to do to give the engine informations for relief mapping things ? i dunno how to ask it correctly, but i would like more informations about what nexuiz can handle for texture related things. What do i need to prepare to be sure that my textures will work with nexuiz at every eye-candy level ?

    thx for the answers :)
    [NSB] ppwer !
    User avatar
    obi_wan
    Alien trapper
     
    Posts: 256
    Joined: Mon Mar 13, 2006 9:24 am
    Location: France

Tue Jul 25, 2006 6:19 pm

  • oligraphes wrote:ok, that work... but that's not what i want.
    i'd like to do a glass wall. like 0.5 in alpha channel :?

    is it possible ?


    I guess what you waqnt is something like the dsiglass texture. Its not strictky .5 tras, but it does look preddy glass like.

    Code: Select all
    textures/dsi/dsiglass
    {
       qer_editorimage textures/dsi/dsiglass2.tga
       surfaceparm trans
       cull disable
       qer_trans 0.5
       {
          map textures/dsi/dsiglass2.tga
          blendfunc blend
          rgbGen vertex
       }   
    }
    HOF:
    <Diablo> the nex is a "game modification"
    <Diablo> quake1 never had a weapon like that.
    <Vordreller> there was no need for anything over 4GB untill Vista came along
    <Samua>]Idea: Fix it? :D
    <Samua>Lies, that only applies to other people.
    User avatar
    tZork
    tZite Admin
     
    Posts: 1337
    Joined: Tue Feb 28, 2006 6:16 pm
    Location: Halfway to somwhere else

Tue Jul 25, 2006 6:36 pm

  • obi_wan wrote:thx tZork :)

    is it possible to make a simple transparent colored block which makes a bit light only with the shader file and without texture file ? (a bit like some non-moving and one-colored slime)

    i have another question, i don't know if its really about shaders actually... How to do to give the engine informations for relief mapping things ? i dunno how to ask it correctly, but i would like more informations about what nexuiz can handle for texture related things. What do i need to prepare to be sure that my textures will work with nexuiz at every eye-candy level ?

    thx for the answers :)


    First question, somthing like this. If you want it lightmaped repalce $whiteimage with $lightmap. Also im not 100% sure this will work in darkplaces.

    Code: Select all
    textures/someshader
    {
       cull disable
       q3map_surfacelight 150
       {
          map $whiteimage
          blendfunc filter
          rgbGen const ( 1 0 0 )
       }
    }


    the line that says q3map_surfacelight 150 control the light amount

    the line that says rgbGen const ( 1 0 0 ) control the color. This is normalized rgb values. In the example its a pure red color. To make it short normalized values uses 1 as maximum. So where you normaly put 255 for a max r,g or b value you put 1 in the normalized form. A ordinaty value of 128 would be 0.5 and so on (1 / 255 * 128).

    [EDIT]
    Theres a strong possibility that rgbGen wont work. In this case take that line out and make a small (4x4) texture ith the color of you liking and put its path where $whitemap is (textures/mycoolstuff/myfunkehcolor.jpg)
    [/EDIT]
    Second question, im not realy sure here but my guess it that it uses the bumpmap info. This info is providied to the enigine in one of two ways. If theres a texture named textures/mycooltex.jpg the engine looks for textures/mycooltex_bump.jpg for bumpmap info. if this file aint there the engine will generate a grayscale image from mycooltex.jpg and use this.
    HOF:
    <Diablo> the nex is a "game modification"
    <Diablo> quake1 never had a weapon like that.
    <Vordreller> there was no need for anything over 4GB untill Vista came along
    <Samua>]Idea: Fix it? :D
    <Samua>Lies, that only applies to other people.
    User avatar
    tZork
    tZite Admin
     
    Posts: 1337
    Joined: Tue Feb 28, 2006 6:16 pm
    Location: Halfway to somwhere else

Fri Aug 18, 2006 2:28 pm

  • could someone help me on adding bumpmaps to textures?
    Cervix
    Member
     
    Posts: 11
    Joined: Sun Mar 12, 2006 5:32 pm

Fri Aug 18, 2006 2:49 pm

  • tZork wrote:If theres a texture named textures/mycooltex.jpg the engine looks for textures/mycooltex_bump.jpg for bumpmap info. if this file aint there the engine will generate a grayscale image from mycooltex.jpg and use this.


    so ;)
    [NSB] ppwer !
    User avatar
    obi_wan
    Alien trapper
     
    Posts: 256
    Joined: Mon Mar 13, 2006 9:24 am
    Location: France

Fri Aug 18, 2006 2:54 pm

  • easy thx
    Cervix
    Member
     
    Posts: 11
    Joined: Sun Mar 12, 2006 5:32 pm

Thu Feb 15, 2007 7:52 pm

  • What are all the surface parms? Or, where can they be found?
    Genegineer
    Advanced member
     
    Posts: 50
    Joined: Fri Nov 17, 2006 8:01 pm
    Location: East Coast, USA

Mon Feb 19, 2007 8:28 pm

  • A google search should help you find them.
    Not being a mapper all i can do is to look at the sources and there i can find those:
    if (!strcasecmp(parameter[1], "alphashadow"))
    else if (!strcasecmp(parameter[1], "areaportal"))
    else if (!strcasecmp(parameter[1], "botclip"))
    else if (!strcasecmp(parameter[1], "clusterportal"))
    else if (!strcasecmp(parameter[1], "detail"))
    else if (!strcasecmp(parameter[1], "donotenter"))
    else if (!strcasecmp(parameter[1], "dust"))
    else if (!strcasecmp(parameter[1], "hint"))
    else if (!strcasecmp(parameter[1], "fog"))
    else if (!strcasecmp(parameter[1], "lava"))
    else if (!strcasecmp(parameter[1], "lightfilter"))
    else if (!strcasecmp(parameter[1], "lightgrid"))
    else if (!strcasecmp(parameter[1], "metalsteps"))
    else if (!strcasecmp(parameter[1], "nodamage"))
    else if (!strcasecmp(parameter[1], "nodlight"))
    else if (!strcasecmp(parameter[1], "nodraw"))
    else if (!strcasecmp(parameter[1], "nodrop"))
    else if (!strcasecmp(parameter[1], "noimpact"))
    else if (!strcasecmp(parameter[1], "nolightmap"))
    else if (!strcasecmp(parameter[1], "nomarks"))
    else if (!strcasecmp(parameter[1], "nomipmaps"))
    else if (!strcasecmp(parameter[1], "nonsolid"))
    else if (!strcasecmp(parameter[1], "origin"))
    else if (!strcasecmp(parameter[1], "playerclip"))
    else if (!strcasecmp(parameter[1], "sky"))
    else if (!strcasecmp(parameter[1], "slick"))
    else if (!strcasecmp(parameter[1], "slime"))
    else if (!strcasecmp(parameter[1], "structural"))
    else if (!strcasecmp(parameter[1], "trans"))
    else if (!strcasecmp(parameter[1], "water"))
    else if (!strcasecmp(parameter[1], "pointlight"))
    User avatar
    esteel
    Site admin and forum addon
     
    Posts: 3924
    Joined: Wed Mar 01, 2006 8:27 am

Thu Jun 07, 2007 6:57 pm

  • Well, you should also take a look at the quake shader bible. I googled it up, should still be available. If you can't find it, I could mail it to you. I think it's a little big, tho. I don't remember.
    Genegineer
    Advanced member
     
    Posts: 50
    Joined: Fri Nov 17, 2006 8:01 pm
    Location: East Coast, USA

Thu Jun 07, 2007 8:04 pm

Thu Jun 07, 2007 10:55 pm

  • Really? The lack of tcMod was pretty annoying. Nice to know its finally been added :D
    User avatar
    Revenant
    Alien
     
    Posts: 122
    Joined: Sat Mar 04, 2006 9:38 pm
    Location: Canada

Fri Jun 08, 2007 12:47 am

Fri Jun 08, 2007 12:56 am

  • What is this "changelog" you speak of?
    User avatar
    Revenant
    Alien
     
    Posts: 122
    Joined: Sat Mar 04, 2006 9:38 pm
    Location: Canada

Fri Jun 08, 2007 8:43 am

Fri Jun 08, 2007 1:04 pm

  • It was a joke meaning that I didnt bother to read it. :P
    User avatar
    Revenant
    Alien
     
    Posts: 122
    Joined: Sat Mar 04, 2006 9:38 pm
    Location: Canada

Fri Jun 08, 2007 4:00 pm

Mon Aug 06, 2007 12:14 pm

Mon Aug 06, 2007 1:28 pm

Fri Jan 04, 2008 12:55 pm

  • I'm trying to make an animated shader but it must have gloss, bump, spec and alpha enabled.
    Is there a list somewhere of the DARKPLACES shader commands? I'm most interested in specular lighting.
    User avatar
    ihsan
    Alien trapper
     
    Posts: 305
    Joined: Fri Mar 03, 2006 3:33 pm
    Location: Trinidad (Where Obama met Chavez)

Mon Jan 28, 2008 10:30 am

Mon Jan 28, 2008 6:34 pm

  • afaik same rules apply to animaps as all other textures in dp:
    animap text1 tex2 tex3

    needs
    Code: Select all
    tex1_glow tex1_gloss text1_norm ... tex3_glow tex3_gloss text3_norm

    to have those fxs enabled for each frame.
    HOF:
    <Diablo> the nex is a "game modification"
    <Diablo> quake1 never had a weapon like that.
    <Vordreller> there was no need for anything over 4GB untill Vista came along
    <Samua>]Idea: Fix it? :D
    <Samua>Lies, that only applies to other people.
    User avatar
    tZork
    tZite Admin
     
    Posts: 1337
    Joined: Tue Feb 28, 2006 6:16 pm
    Location: Halfway to somwhere else

Wed Dec 10, 2008 6:56 pm

Mon Nov 23, 2009 5:38 am

  • DeVsh wrote:so am i to understand there is no GLSL involved?


    Yes, that is correct.

    All GLSL shader code is in the engine, it simply chooses shader features to fit your q3 shader file and the current circumstances (lighting, fog, etc).

    All the engine uses the q3 shader files for is to understand the material that is desired, support a few effects (scrolling stuff, water reflections, etc), and off it goes with the standard material renderer.

    Custom GLSL shader code is not really supported, I prefer to take requests for material features and implement them in a general way, rather than directly support custom shader code.
    LordHavoc
    Site Admin
     
    Posts: 191
    Joined: Wed Mar 29, 2006 7:39 am
    Location: western Oregon, USA

Mon Nov 23, 2009 4:43 pm



Return to Nexuiz - Editing




Information
  • Who is online
  • Users browsing this forum: No registered users and 1 guest