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

Shaders - an explanation

Postby Kaz » 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.
Kaz
Newbie
 
Posts: 6
Joined: Mon Mar 06, 2006 1:25 am

Postby parksto » 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

Postby tZork » 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.
tZork
tZite Admin
 
Posts: 1337
Joined: Tue Feb 28, 2006 6:16 pm
Location: Halfway to somwhere else

Postby parksto » 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

Postby obi_wan » 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 !
obi_wan
Alien trapper
 
Posts: 256
Joined: Mon Mar 13, 2006 9:24 am
Location: France

Postby tZork » 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.
tZork
tZite Admin
 
Posts: 1337
Joined: Tue Feb 28, 2006 6:16 pm
Location: Halfway to somwhere else

Postby tZork » 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.
tZork
tZite Admin
 
Posts: 1337
Joined: Tue Feb 28, 2006 6:16 pm
Location: Halfway to somwhere else

bumpmaps

Postby Cervix » 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

Postby obi_wan » 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 !
obi_wan
Alien trapper
 
Posts: 256
Joined: Mon Mar 13, 2006 9:24 am
Location: France

Postby Cervix » Fri Aug 18, 2006 2:54 pm

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

Next

Return to Nexuiz - Editing

Who is online

Users browsing this forum: No registered users and 1 guest