Caligari_87 wrote:This is really cool, I just wish I could actually make sense of how that shader code works, or at least get a "for dummies" reference. Wouldn't mind trying my hand at a few.

As I said I'm not really good with shaders myself, but I'll try to explain how the shaders works (so don't expect this to be the ideal or even good way). The shader computes the color of
one pixel on your screen and not of the actual texture. If you look closely you'll see that the animation works on a sub-texture-pixel level.
Here's a breakdown of the silver texture shader:
- Code: Select all • Expand view
vec2 background = gl_TexCoord[0].st;
vec2 foreground = gl_TexCoord[0].st;
vec2 highlight = gl_TexCoord[0].st;
This sets three 2-dimensional vector variables. gl_texCoord[0].st gets the x/y components of the current texture position. They are all the same, but will then be modified point to other pixels. background will be the blue part, foreground the silver part, highlight the light stripe part. It's important to understand that the values are not in real texture dimensions (in this example192x128), but in the range of 0.0 to 1.0, where (0.0, 0.0) is the top left and (1.0, 1.0) is the bottom right. So the actual texture has these positions:

(note that the x values written as 0.333 and 0.666 are actually 1/3 and 2/3)
- Code: Select all • Expand view
background.x += 1.0/3.0;
This adds an offset of 1/3 (one third) of the texture dimension to the x position of the background vector. That means if the topmost leftmost pixel (0, 0) is processed, this vector will now point to (0.333..., 0), or to the topmost leftmost pixel of the blue part of the texture.
- Code: Select all • Expand view
highlight.x += 1.0/3.0*2.0;
This adds 2/3 (two thirds) of the texture dimension to the x position of the highlight vector. That means if the topmost leftmost pixel (0, 0) is processed, this vector will now point to (0.333..., 0), or to the topmost leftmost pixel of the highlight part of the texture.
- Code: Select all • Expand view
highlight.y += timer * 0.5;
This modifies the y position of the vector pointing to a pixel on the highlight part of the texuture. It takes the game time into account, so as time goes on the position will change, which will give the illusion that the texture is scrolling. It's multiplied by 0.5 (or divided by 2) so that it doesn't scroll superfast.
Let's say we're processing the topmost leftmost pixel of the texture (0, 0), at time 0 highlight.y will be 0. At time 0.1 highlight.y will be 0.05. At time 0.2 highlight.y will be 0.1 and so on.
- Code: Select all • Expand view
highlight.y = highlight.y - floor(highlight.y);
As said as the beginning, the texture dimension is between 0.0 and 1.0, so this makes sure highlight.y stays in that range. This is necessary because the value of highlight.y computed in the previous step grows bigger and and bigger as time goes on. For example a time 314.6 highlight.y will be 157.3, which will be reduced to 0.3 here. So basically it starts back at 0 once 1.0 is reached.
- Code: Select all • Expand view
vec4 backgroundTexel = getTexel(background);
vec4 forgroundTexel = getTexel(foreground);
vec4 highlightTexel = getTexel(highlight);
Gets the texel information at the position of each in RGBA format (I guess getTexel is a function defined by GZDoom). So at this point the shader has color information of three different pixels from the texture.
The following part says what color the pixel shown on the screen shoud have.
- Code: Select all • Expand view
if(forgroundTexel.a > 0)
return forgroundTexel * color;
This checks if the pixel we want to show is transparent or not. If it is not transparent the silver texture will be displayed, otherwise we'll go into the else branch below. Effectively this will draw everything but the "windows" of the texture. It's multiplied by color (which is supplied to the shader) to take light level, color, fog etc. into account.
- Code: Select all • Expand view
else
return (backgroundTexel * highlightTexel) * color;
If the alpha of foregroundTexel is 0 the shader will draw the light. It will do so by multiplying the background (blue) color with the highlight color. The highlight color is in a range of black and white, so multiplying it with the background color makes the blue either brighter or darker. Finally it's multiplied with the color supplied to the shader.
And that's pretty much it. Hope it helps.