Shader Files
Quick Links
Overview
Shader files are, in my opinion, the most complex file to work with in the game that we’ll cover here. The effects editor / effect definition files are arguably worse to the point where I’m not touching it with a 20 foot pole. (I also have no experience and thus cannot talk about it)
Shader files are the .sha files you see in /resources/textures. They dictate a lot of visual things like mapping textures to objects and creating effects.
The difference between shader files and .rtm files/.def files for effects are that shader files work in tandem with a model while effect .def/.rtms do not. They are standalone and are called upon by spells or objects.
The Basics
I’m still very new to shaders, so bear with me.
All shader files are broken up into what is called a pass - a group of texture maps and rendering effects that are rendered in one go. There can be multiple passes to layer effects upon each other; the engine will render the first pass fully, then the second pass, and layer it, rather than rendering both at once. The first pass in the file is layered on the bottom.
Passes look like this:
Code:
textures/terrain/terrain_dirt_cracked_alpha_reg
{
{
map terrain_dirt_cracked_reg_reg.tga modulate
map terrain_detail_rough_reg_reg.png mod2x
tcMod scale 5.65 5.65 1
map terrain_macro_sand_reg_reg.png mod2x
tcMod scale 0.15 0.15 2
blendFunc SOURCE_ALPHA ONE_MINUS_SOURCE_ALPHA
rgbUseVertexColors
fog on
}
}
{
{
map terrain_dirt_cracked_reg_reg.tga modulate
map terrain_detail_rough_reg_reg.png mod2x
tcMod scale 5.65 5.65 1
blendFunc SOURCE_ALPHA ONE_MINUS_SOURCE_ALPHA
rgbUseVertexColors
fog on
}
}
There are two passes in this file. They are grouped with curly brackets - {}.
Encompassed in a pass is all of the functions that define how the engine renders the shader.
Prepare yourself for a long list of terminology for stuff that I know works. There are a LOT more parameters to these functions than I’m going to list. If I were to write everything there is to know about shaders, it would be a guide much longer than this one already is. Your best bet is to, like definition files, dig around and find what works for you.
Do note that not every extra parameter is needed and that this is NOT every shader function. These are just the most common ones.
map
Map is usually used to map a texture to an object. So, for example, in that block of code up there, “map terrain_dirt_cracked_reg_reg.tga modulate” maps the cracked dirt texture to the ground. ‘Modulate’ is one of the many parameters shaders support and it essentially tells the game how to display the texture’s colors.
Modulate or no parameter is generally the most common way I’ve seen as it displays the texture as-is for the most part, but there is also mod2x, mod4x, replace, add, subtract, addsmooth, and various others - the best way to describe this is is simply ‘toy with it’.
envMap
This stands for ‘environment map’ and I’ve mostly seen it used for simulating shiny things or ghostly things. An example is
Code:
envMap cameraspace sphere reflect ghost_darkaura.tga modulate
From dragonghost_u_body_00.sha.
In this example, the game applies the ghost_darkaura.agh texture to the character and moves it with the camera across the body as if it were reflecting a sphere of the texture around it. It’s very hard to explain through text, but essentially, envMap makes the associated texture reflective and responsive to the camera/environment.
tcMod
tcMod stands for ‘texture coordinate modification’. There’s a lot of examples all throughout the files, but this is what gives any movement-related effect.
The most common ones are:
tcMod rotate [value]
tcMod scale [scaleX] [scaleY]
tcMod scroll [speedX] [speedY]
rgbMod
This function changes the color of stuff, basically. It supports constant, sin, triangle, and square. I’m honestly not sure what the numbers mean or do, so toy with it if you need/want to use rgbMod. It works alongside rgbColor or rgbUseVertexColors.
blendFunc
This is a very important one but also a very complex one. It determines how the model layers/renders passes.
blendFunc [source function] [destination function]
There will ALWAYS be two and they both use one of the values from this list:
ZERO
ONE
SOURCE_COLOR
ONE_MINUS_SOURCE_COLOR
SOURCE_ALPHA
ONE_MINUS_SOURCE_ALPHA
DESTINATION_COLOR
ONE_MINUS_DESTINATION_COLOR
DESTINATION_ALPHA
ONE_MINUS_ DESTINATION _ALPHA
SOURCE_ALPHA_SATURATE
These are impossible to explain without a visual, but most of the time you’re only going to be using ONE ZERO or a mix of the source_alpha variations.
lighting
This is a simple one. There’s only fullbright and shaded as variables here. Fullbright makes your character have absolutely no shading on them whatsoeover. You’ll usually use this for stuff that glows. Shaded is default.
cull
Any of you who have messed with 3D modeling know what backface culling is. That’s basically what this is. Cull back, cull front, or cull none are the only parameters. For those that don’t know backface culling, it basically is when you render a texture inside an object as well as outside of it.
sort
Sort is another one you see around but I don’t really know how to explain/what it does. Go shader diving for this.
depthTest
This one is what makes ghosts partly see-through. Do mess with it to get a visual, but ghosts use “EQUAL” as their test. So you’ll see:
Code:
depthTest NEVER/LESS/EQUAL/LEQUAL/GREATER/NOT_EQUAL/GEQUAL/ALWAYS
Or
For the most part.
The capitalized ones refer to the mathematical comparisons of numbers - LEQUAL = less than or equal to, for example. Most solid stuff doesn’t really define it anywhere.
alphaTest
alphaTest is what decides whether textures have transparency in them or not. For things like dragons, alphaTest is needed for areas like the fins where otherwise there would be white blocks surrounding the partially transparent texture.
alphaTest uses the same NEVER/LESS/etc parameters as above but also has a value it looks for. The value refers to the opacity % of a pixel. 0% opacity is totally clear while 100% opacity is totally opaque.
Example from the dragon wing shader:
Code:
alphaTest GREATER 0.5
Using Shader Edit
For any of you who have used /setpref developer true, you’ll notice there’s a ‘shader editor’ window. This CAN be helpful with messing with shaders! However, only for objects you can select.
First, create your properly-named shader file in resources_override. Load into the game and go and find whatever you’re overriding. /setpref developer true and /loadui to get the shader edit to appear in the menu. Once you have it open you can /setpref developer false, but you might need it on to select some objects.
Second, select your edited object and make sure your empty shader appears when you highlight the shader you’re editing. If it works, then good! If not, then, well, you might not be able to edit that or might have an issue.
Once it all seems to be working, just edit your shader file outside of the game using any text editor. I prefer Notepad++. There is a button on the shader window to reload the shader. Hit that whenever you save the file and it should update in-game.