Difference between revisions of "Textures:Shaders"

From Custom Map Makers Wiki
Jump to: navigation, search
(Understanding)
 
(21 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{WIP}}
 
 
 
== Shaders ==
 
== Shaders ==
 
+
Check out this nifty cheatsheet for blendmodes!
 +
[[File:blendmodes_cheatsheet.jpg]]
 
=== Basics ===
 
=== Basics ===
 
A shader is a short text string, that defines the properties of a texture. Using texture in Radiant on solid brush which has to be a simple wall doesn't require to write a shader for it. Every other surface with special attribute - it does. Shaders tells Q3 engine what kind of surface it has to deal with. Wall, water, sky, mirror, etc. You can have sky texture, but it wont act as a 'real' sky in game until you write a shader for it.
 
A shader is a short text string, that defines the properties of a texture. Using texture in Radiant on solid brush which has to be a simple wall doesn't require to write a shader for it. Every other surface with special attribute - it does. Shaders tells Q3 engine what kind of surface it has to deal with. Wall, water, sky, mirror, etc. You can have sky texture, but it wont act as a 'real' sky in game until you write a shader for it.
Line 15: Line 14:
 
<pre>
 
<pre>
 
textures/ut_subway/plant_bush01
 
textures/ut_subway/plant_bush01
 
 
{
 
{
        qer_editorimage textures/ut_subway/w2k_bush1.tga
+
  qer_editorimage textures/ut_subway/w2k_bush1.tga
    surfaceparm trans
+
  surfaceparm trans
  surfaceparm nonsolid
+
  surfaceparm nonsolid
//DeformVertexes autosprite2
+
  //deformVertexes autosprite2
cull none
+
  cull none
        nopicmip
+
  nopicmip
{
+
  {
map textures/ut_subway/w2k_bush1.tga
+
    map textures/ut_subway/w2k_bush1.tga
blendFunc GL_ONE GL_ZERO
+
    blendFunc GL_ONE GL_ZERO
alphaFunc GE128
+
    alphaFunc GE128
depthWrite
+
    depthWrite
rgbGen identity
+
    rgbGen identity
}
+
  }
{
+
  {
map $lightmap
+
    map $lightmap
rgbGen identity
+
    rgbGen identity
blendFunc GL_DST_COLOR GL_ZERO
+
    blendFunc GL_DST_COLOR GL_ZERO
depthFunc equal
+
    depthFunc equal
}
+
  }
 
}
 
}
  
Line 41: Line 39:
 
textures/ut_subway/chain_link
 
textures/ut_subway/chain_link
 
{
 
{
        qer_editorimage textures/ut_subway/fence.tga
+
  qer_editorimage textures/ut_subway/fence.tga
    surfaceparm trans
+
  surfaceparm trans
  //surfaceparm nonsolid
+
  //surfaceparm nonsolid
//DeformVertexes autosprite2
+
  //deformVertexes autosprite2
cull none
+
  cull none
        nopicmip
+
  nopicmip
{
+
  {
map textures/ut_subway/fence.tga
+
    map textures/ut_subway/fence.tga
blendFunc GL_ONE GL_ZERO
+
    blendFunc GL_ONE GL_ZERO
alphaFunc GE128
+
    alphaFunc GE128
depthWrite
+
    depthWrite
rgbGen identity
+
    rgbGen identity
}
+
  }
{
+
  {
map $lightmap
+
    map $lightmap
rgbGen identity
+
    rgbGen identity
blendFunc GL_DST_COLOR GL_ZERO
+
    blendFunc GL_DST_COLOR GL_ZERO
depthFunc equal
+
    depthFunc equal
}
+
  }
 
}
 
}
 
</pre>
 
</pre>
Line 67: Line 65:
  
  
The most basic shader will consist at least one texture and one script for it. By the time You will learn to create complicated ones, to achieve special and unique effects for your map. Complete manual explaining all the parameters, strings and variables is here: [http://www.custommapmakers.org/wiki/shaders/index.html here]
+
The most basic shader will consist at least one texture and one script for it. By the time You will learn to create complicated ones, to achieve special and unique effects for your map.  
 +
Complete manual explaining all the parameters, strings and variables is here: [http://www.custommapmakers.org/wiki/shaders/index.html here]
  
=== Understanding ===
+
== Understanding ==
 +
It's crucial you understand the syntax of shaders.
  
Shaders are written in a syntax that is really important.
+
First you write the line how the shader should be called. You can use folder names, that's how it will appear in Radiant also.
 
 
First you write the line how the shader is named - at which "shader" you call it in Radiant.
 
For Example plant_brush01
 
  
 
<pre>
 
<pre>
 
textures/ut_subway/plant_bush01
 
textures/ut_subway/plant_bush01
 +
{
 +
}
 
</pre>
 
</pre>
  
The Following we can conclude out of the Shader:
+
This shader can be found in the ut_subway folder in the Radiant texture browser.
It's in the folder 'textures' in the map-specific folder 'ut_subway' - If you have your own textures and your own shader it should be in that folder.
 
The Path only accepts forward slashes and single slashes - also I heard something like it should always be shorter than 64 signs... so complete sentences as shadername are a no-go :)
 
  
(Also some restrictions: Max of 4096 Shader Files, 16384 "shaders" in the Whole Game, 8 Stages, 8 Texture Animations, 4 Texture Modifiers, 3 Deformations and 64 chars for the whole "shader-name-line". Big Shoutout to [User:Rylius] for looking it up in the Quake 3 Arena Source. - some Values might have changed but that's basically it what you have to care for.)
+
Your shaders should always be put in a folder with the same or similar name of your map. A common way is to replace the ut4_ prefix of your map with aaa so it shows up right at the beginning of the list.
 +
You shouldn't give shaders the same name as image files in the same directory.
  
You should always name your shaders like your textures, however not _exactly_ the same as I got personally into some bugs with the Images.
+
(Some restrictions: Maximum of 4096 individual shader files, 8 shader stages, 8 animMap images, 3 deformations and 64 chars for the shader name)
Also you should have an own shader name - don't simply copy another shader 1:1 and just change some options. That breaks the Compatibility to one of the two.
 
So 'textures/<map-specific-folder>/<unique-shader-name>'.
 
  
 
== Conclusion ==
 
== Conclusion ==
Line 95: Line 91:
  
 
== Good Free Shaders ==
 
== Good Free Shaders ==
 +
  
 
== Common Mistakes ==
 
== Common Mistakes ==
 +
=== Wrong syntax ===
 +
<pre>textures/sky/box374
 +
{
 +
  surfaceparm noimpact
 +
  surfaceparm nomarks
 +
  surfaceparm nolightmap
 +
  surfaceparm sky
 +
  q3map_lightimage textures/sky/box374.tga
 +
  qer_editorimage textures/sky/box374.tga
 +
  //q3map_lightsubdivide 1024
 +
  //q3map_globaltexture
 +
  q3map_sun 1.0 0.55 0.1 725 180 30 //0.85 0.55 0.65 //0.005 0.0 0.0 25 350 20 mobb2
 +
  skyparms env/box374/box374 - -
 +
</pre>
 +
 +
This is an especially nasty case. The missing closing bracket at the end won't be recognized by the game and totally screws up the whole game.
 +
 +
=== Wrong paths ===
 +
<pre>textures/sky/box374
 +
{
 +
  surfaceparm noimpact
 +
  surfaceparm nomarks
 +
  surfaceparm nolightmap
 +
  surfaceparm sky
 +
  q3map_lightimage textures/WOOOOOOOOT????/box374.tga
 +
  qer_editorimage textures/sky/box374.tga
 +
  q3map_surfacelight 250 //80 mobb2
 +
  //q3map_lightsubdivide 1024
 +
  //q3map_globaltexture
 +
  q3map_sun 1.0 0.55 0.1 725 180 30 //0.85 0.55 0.65 //0.005 0.0 0.0 25 350 20 mobb2
 +
  skyparms env/box374/box374 - -
 +
}
 +
</pre>
 +
[[File:Missingtexture.jpg|200px|Missing texture is marked with rainbow placeholder in game]]
 +
 +
 +
In this case the skybox will show up as a missing texture because the path is wrong.
 +
 +
==CMM shader tools==
 +
CMM have created a simple tool to help generate both qer images and also shaders. The tool runs on a webpage and is a work in progress, any ideas for improvements are welcome.
 +
 +
===qer image generator===
 +
[http://www.custommapmakers.org/shaders.php CMM shaders tool]
 +
 +
To create a qer image (the image used in radiant to represent your texture) simple enter the name or word that will appear on your qer image and enter an #RGB colour and click the '''create qer image''' button.
 +
 +
For example
 +
 +
[[File:LADDER.png]]
 +
 +
===shader generator===
 +
 +
The shader generator prompts for you to enter the name of your map, this is your shader file and will be used to create your shader names.
 +
 +
Select which shaders you'd like to be created by checking the available options.
 +
 +
Click the''' create shader set''' button, the webpage will generate your shaders in a shader file and pack this along with any base images into a .zip file which you can download.
 +
 +
==Q3 shaders manual (locally hosted)==
 +
[http://www.custommapmakers.org/wiki/shaders/index.html Shader Manual]
  
 
[[Category:Textures]]
 
[[Category:Textures]]

Latest revision as of 12:04, 25 July 2012

Shaders

Check out this nifty cheatsheet for blendmodes! Blendmodes cheatsheet.jpg

Basics

A shader is a short text string, that defines the properties of a texture. Using texture in Radiant on solid brush which has to be a simple wall doesn't require to write a shader for it. Every other surface with special attribute - it does. Shaders tells Q3 engine what kind of surface it has to deal with. Wall, water, sky, mirror, etc. You can have sky texture, but it wont act as a 'real' sky in game until you write a shader for it.

Your main shader file should always be named as your map: ut4_mymap.shader. You should keep it in your /scripts folder and also make sure, it's in your shaderlist.txt file, which is also in /scripts folder. You can call shaderlist.txt 'the main list of shaders'. If it is not on the main list, it will not be on the list in the GTK Radiant Level Editor.

You must understand the difference between shader file and shader. ut4_yourmap.shader file consists shaders - it might sound complicated, but mappers use term "shader" for every single one texture with special attributes. So when someone speaks about 'shader', he speaks about a particular fragment of your shader file.


Let's use example:

textures/ut_subway/plant_bush01
{
  qer_editorimage textures/ut_subway/w2k_bush1.tga
  surfaceparm trans
  surfaceparm nonsolid
  //deformVertexes autosprite2
  cull none
  nopicmip
  {
    map textures/ut_subway/w2k_bush1.tga
    blendFunc GL_ONE GL_ZERO
    alphaFunc GE128
    depthWrite
    rgbGen identity
  }
  {
    map $lightmap
    rgbGen identity
    blendFunc GL_DST_COLOR GL_ZERO
    depthFunc equal
  }
}


textures/ut_subway/chain_link
{
  qer_editorimage textures/ut_subway/fence.tga
  surfaceparm trans
  //surfaceparm nonsolid
  //deformVertexes autosprite2
  cull none
  nopicmip
  {
    map textures/ut_subway/fence.tga
    blendFunc GL_ONE GL_ZERO
    alphaFunc GE128
    depthWrite
    rgbGen identity
  }
  {
    map $lightmap
    rgbGen identity
    blendFunc GL_DST_COLOR GL_ZERO
    depthFunc equal
  }
}


This is fragment of shader file for "ut4_subway" map. I pasted 2 shaders from it - for plant_bush01 and chain_link. Your shader file will also consists several shaders written by you.


The most basic shader will consist at least one texture and one script for it. By the time You will learn to create complicated ones, to achieve special and unique effects for your map. Complete manual explaining all the parameters, strings and variables is here: here

Understanding

It's crucial you understand the syntax of shaders.

First you write the line how the shader should be called. You can use folder names, that's how it will appear in Radiant also.

textures/ut_subway/plant_bush01
{
}

This shader can be found in the ut_subway folder in the Radiant texture browser.

Your shaders should always be put in a folder with the same or similar name of your map. A common way is to replace the ut4_ prefix of your map with aaa so it shows up right at the beginning of the list. You shouldn't give shaders the same name as image files in the same directory.

(Some restrictions: Maximum of 4096 individual shader files, 8 shader stages, 8 animMap images, 3 deformations and 64 chars for the shader name)

Conclusion

Like famous Rayne said once: 'It's all in the shaders'.

Good Free Shaders

Common Mistakes

Wrong syntax

textures/sky/box374
{
  surfaceparm noimpact
  surfaceparm nomarks
  surfaceparm nolightmap
  surfaceparm sky
  q3map_lightimage textures/sky/box374.tga
  qer_editorimage textures/sky/box374.tga
  //q3map_lightsubdivide 1024
  //q3map_globaltexture
  q3map_sun 1.0 0.55 0.1 725 180 30 //0.85 0.55 0.65 //0.005 0.0 0.0 25 350 20 mobb2
  skyparms env/box374/box374 - -

This is an especially nasty case. The missing closing bracket at the end won't be recognized by the game and totally screws up the whole game.

Wrong paths

textures/sky/box374
{
  surfaceparm noimpact
  surfaceparm nomarks
  surfaceparm nolightmap
  surfaceparm sky
  q3map_lightimage textures/WOOOOOOOOT????/box374.tga
  qer_editorimage textures/sky/box374.tga
  q3map_surfacelight 250 //80 mobb2
  //q3map_lightsubdivide 1024
  //q3map_globaltexture
  q3map_sun 1.0 0.55 0.1 725 180 30 //0.85 0.55 0.65 //0.005 0.0 0.0 25 350 20 mobb2
  skyparms env/box374/box374 - -
}

Missing texture is marked with rainbow placeholder in game


In this case the skybox will show up as a missing texture because the path is wrong.

CMM shader tools

CMM have created a simple tool to help generate both qer images and also shaders. The tool runs on a webpage and is a work in progress, any ideas for improvements are welcome.

qer image generator

CMM shaders tool

To create a qer image (the image used in radiant to represent your texture) simple enter the name or word that will appear on your qer image and enter an #RGB colour and click the create qer image button.

For example

LADDER.png

shader generator

The shader generator prompts for you to enter the name of your map, this is your shader file and will be used to create your shader names.

Select which shaders you'd like to be created by checking the available options.

Click the create shader set button, the webpage will generate your shaders in a shader file and pack this along with any base images into a .zip file which you can download.

Q3 shaders manual (locally hosted)

Shader Manual