Guide - Working with Shaders (WIP)

Borrie BoBaka

Local Bothan
Staff member
Super Moderator
Joined
Mar 16, 2014
Messages
91
Location
Dark Rebellion RP
Shaders are an element of visual rendering that controls how something appears on a screen via coded instructions. Shaders dictate how something appears lit or unlit, transparent, or how it visually behaves in the world on your screen. Star Wars Galaxies' shaders are very exposed and easily modifiable with only a select few (temporary) restrictions at the time of this guide's authoring.

Before we begin, a disclaimer: This tutorial will focus primarily on how to integrate or modify shaders within SWG as per SWG's rendering pipeline. It will not go into depth about actual shader writing, though I will give a brief synopsis on what you might need to know to start writing shaders.

What to know about the coding aspect
Star Wars Galaxies uses HLSL, the C-like high-level shader language that you use with programmable shaders in DirectX. SWG utilizes DirectX 9 for it's renderer, which operates using Pixel Shader (PS) version 2.0. SWG can run shaders compiled with PS 3.0, however, at this current time, players who are using AMD graphics cards are unable to see any shaders compiled with 3.0 due to the lack of backwards compatability in AMD drivers. (AMD hates Retro gamers.)

HLSL is used in some form for a lot of shader programming. You will mostly be concerned with the Vertex Shader/Program and the Pixel Shader/Program. Outside of SWG, the Pixel shader can often be referred to as a Fragment Shader. This tutorial will not go into the details and specifics of vertex and pixel shaders, but it is noteworthy that pixel shaders (PSH) in SWG must be pre-compiled, whereas vertex shaders are compiled in runtime from plaintext and do not need to be compiled by the user.

For information on compiling pixel shaders, check Timbab's Tutorial on compiling pixel shaders.

The Pipeline of Files for SWG
VSH > PSH > EFT > SHT > Game

VSH - The Vertex Shader
(Found in the vertex_program folder in TREs)
Contains the gathering of data to be sent to the pixel shader, as well as modification to the vertices of the mesh.

PSH - The Pixel Shader
(Found in the pixel_program folder in TREs)

Determines how each pixel within a rendered triangle appears on the screen.

EFT - The Effect File
(Found in the effect folder in TREs)
This file determines which VSH and PSH files to use for a given version of renderer being used, as well as declaring various parameters, like texture map names for the shader to use as assigned by the SHT file.

SHT - The Shader Template File
(Found in the shader folder in TREs)
Calling this a shader is disingenuous. A more appropriate analog would be calling it a "Material," as found in engines like Unity or Unreal. The SHT file assigns which EFT file to use, and which textures to put in each map. It also connects which variables will be used for this shader when rendering customization, and other small variables like emissive or specular lighting color. SHT files have a suffix tag at the end of their name as a way of quickly identifying which EFT file they're using. This is not neccesary for use in the client, but helps readability by yourself and other developers in figuring out which effect is being used. The name of this suffix is usually the first letter of every word in an effect file.


-To Be Continued-
 
Top Bottom