Shaders (2021 Edition)

This is sort of a continuation of:

I’ve finally started to (barely and slowly) learn shaders and am starting to get some fun visible results. Step one was to take the ship shader and gut it to the very bare minimum of an unlit shader that displays textures and meshes.

Recently I’ve also managed to play around with the vertex distortion in the harvest shader.

Another thing I want to do is experiment with distortion and refraction.


What is the top one? Where are those different colours coming from?

I believe that’s the object space vertex positions. I think the colors are default opengl colors, but the important thing is they can tell you the origin point of the object. It’s similar to being able to determine the uv mapping coords of an object.

Figured out how to get camera position and was able to rebuild reflection and refraction shaders using formulas from



wow cool! I think I’ve totally been mission out on something: how did you open that debugging window?

1 Like

I believe it’s in uisettings.lua, change the activate value for the debug menu to 1 and it should show up. You can map a few commands to it, but the only “useful” ones I’ve found are disable engine glows and disable nav lights.

1 Like

Ah okay, thanks! Might still be worth checking out.

You can’t be disscussing this without me, arr!
Not sure about reflection/refraction. Stock ones look just fine to me.
Vertex distortion is nice to have, vertex shaders are a bit of beyond me. Not sure I like how it looks like, but it may have uses.
STCR (ping, @Nathanius) got nameplates, borgification and parallax mapping with a bit of my help, though I guess I’m too lazy to produce gifs or videos of those properly.

1 Like

Obligatory images to back up @Dark_Sentinel

Name Plates (aka "regos")


I’ve never succeeded in taking a picture of the parralax mapping successfully, we’re using it on our Dilithium crystal asteroids now and are intending to cross it with the Borg transwarp effect if possible to make the gate look even better

Transwarp Gate effect

I also stole this shader for use on the shields as below

Animated shields

1 Like

Worked out (stole) some stuff from the stock shaders in terms of getting the viewmatrix correct, but running into a new problem, and that is even with the debugreload turned on, it seems like post_ shaders (screenspace effects) don’t seem to actively reload.

Edit: ooh turns out they do after all, I was just messing up the shader.

1 Like

Has anyone had success using the depth texture global and/or drawing the zbuffer to the screen?

I don’t know what most of that means…


My first custom multi-pass shader! The oft-requested “Borderlands” outline look. There’s still some anomalies because the outline is a bunch of discrete panels instead of a solid blob (I presume I typed something wrong somewhere), but it’s a start! Next up is fixing the discrete panels, testing it with the normal map, etc, then integrating it with the toon lighting shader.


Alternate post processing approach, using a sobel filter implementation by enne87.


Took another stab at refraction. It’s a fine line between making it look clear and making it look chrome, imo. With and without alpha.


That refraction with alpha is an excellent cloaking effect alternative

OR! OR… a glass shader


Anyone know how to use #defprog?

Anyone know how to enable a new post process shader?

@sastrei have we done it already in STC? I’m pretty sure we’ve got a working example in our files with the crystal texture parallax map.

On that note, I want to get up to speed so I can personally augment our team’s shader abilities (I want me a ship build shader using a progress map). Is the best place to start?

1 Like

@Nathanius As far as I can tell STC hasn’t dabbled in any post-processing shaders. All of your new shaders appear to be applied directly to assets in-game, correct?

So, the issue I’ve run into is that I can’t find a way to launch a new post-processing shader. I can replace an existing one, but not create a new one. You can do branching, like STC and the stock shaders do, and you can possibly do a funky thing where you have a bunch of shaders stacked into one, like say monochrome/sepia/vivid filters, and then branch between them to one output.

That being said, there are many people here much smarter than me, so feel free to run with this and tweak/edit/use. In addition to which is definitely the best resource, I also recommend: Freya’s Intro to Shaders, Ronja’s Tutorials, and The Book of Shaders.

Outline Shader Public Release

To use, unzip and place contents into your data>shaders>gl_prog folder.
Start up HWR and you should have the outlines on everything.

Frag code pasted below for conversational value.
Sobel implementation from enne87
Smoothstep and clamp functions pulled from wikipedia

in vec2 outUV0;

uniform sampler2D inTexUI;
uniform sampler2D inTexScene;

layout (location = 0) out vec4 finalCol0;

mat3 sx = mat3( 
1.0, 2.0, 1.0, 
0.0, 0.0, 0.0, 
   -1.0, -2.0, -1.0 

mat3 sy = mat3( 
1.0, 0.0, -1.0, 
2.0, 0.0, -2.0, 
1.0, 0.0, -1.0 

float clamp(float x, float lowerlimit, float upperlimit) {
  if (x < lowerlimit)
x = lowerlimit;
  if (x > upperlimit)
x = upperlimit;
  return x;

float smoothstep(float edge0, float edge1, float x) {
  x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); 
  return x * x * (3 - 2 * x);

void main()
	vec4 texUI = texture(inTexUI, outUV0);
	vec4 texScene = texture(inTexScene, outUV0);

mat3 I;
for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
        vec3 sample  = texelFetch(inTexScene, ivec2(gl_FragCoord) + ivec2(i-1,j-1), 0 ).rgb;
        I[i][j] = length(sample); 
	float gx = dot(sx[0], I[0]) + dot(sx[1], I[1]) + dot(sx[2], I[2]); 
	float gy = dot(sy[0], I[0]) + dot(sy[1], I[1]) + dot(sy[2], I[2]);
	float g = sqrt(pow(gx, 2)+pow(gy, 2));
	g = smoothstep(0.94,0.99,g);

	vec4 scene = vec4(texScene.rgb - vec3(g), 1.0);
	vec4 sceneFinal = mix(scene, texUI, 1-texUI.a);
	finalCol0 = sceneFinal;

I was referring to #defprog actually, that’s the progress map right? Dark’s parallax crystals get mined away as the asteroid is depleted

I don’t think we’ve done anything in post, no :sweat_smile:

1 Like