Shaders, Custom Shaders, Awesome Shaders

So, had an awesome conversation with BitVenom where he imparted way more information than I could possibly hope to remember (curse my not recording the convo!)

Essentially, custom shaders are not only possible, he set up a system that makes it easy for us to do so.

Creating a custom shader is pretty damn easy. I’m a total noob at shader stuff, so he had to give me a crash course.

GBX is going to be updating the list on the left (hod_alias.manifest) - we modders get to use the list on the right (mod_alias.manifest) so our custom shaders don’t get broken by GBX updates.

You can override shader paramaters using markers in the 3dsMax file. Meaning you don’t have to write a one-off shader for a given ship, you can tweak an existing one.

Parallax shaders - possible, but expensive, why GBX chose not to implement them.

Add this string “-allowProgramReloads 1” to your HomeworldRM.exe shortcut to allow editing of your shader files while you have the game running. You also have to edit sob_share_ship.imp and uncomment the “debugReload” line and change the interval to suit.

If you create a custom shader, you’ll have to add it to SHADERS.MAP so Hodor can understand it. FYSA: GBX updates will overwrite this file.

Graphics menu options are not hardcoded. They populate from the shader code. For example the shadow options:

Shaders have a concept of time now - I’m not entirely clear on this one. HWR can also use geometry shaders (tesselation).

Bitvenom recommends sticking to a custom namespace when creating custom shaders (ie sob_brick_ship).

Edit 3/12: Realized I forgot to put up the comparison photos BV requested.

More stuff here, I think I played a whole MP game with the modified shaders as the ships didn’t seem as shiny as usual. Much to Bitvenom’s consternation I am sure, I am not as good at discerning visible alterations and details as I need to be. :slight_smile:

Edit: I’ve thought of a possible use case for the new shader flexibility we have*, and I’ve thought of a few shaders that would make good candidates for early experiments. What can y’all think of?

Babylon 5 - Shadow ship skins
Star Trek - Romulan/Klingon cloaking
Starcraft - Protoss cloaking
cel-shaded look

What other ones can y’all think of?

*possible use case: the ships in my mod have a variety of default color schemes. However, many people would no doubt prefer a uniform set of team colors. Instead of two separate mods, it sounds like it should be possible to set which texture channels or shader is being used via the Graphic Options menu, and doing a behind the scenes switch of shaders to use a different set of textures (from predefined colors to textures compatible with team colors).

Additionally, it should be possible, if I understood correctly, to swap out whether ships would be plastic and glossy looking, or metallic and painted, again, by setting it up so you can access it via the Graphic Options menu.



Almost correct! In your case that’s the one to edit (as nearly all ship-related shaders use it as a central logic point) - for most shaders you just add the debugReload command to their .prog:

debugReload X

where X is the # of seconds between reloads. On NVidia hardware it is very, very fast - ATI is pretty good, Intel (my dev laptop) - not so much. It works great (and so far Intel wins for best error messages/most informative) - but can chug the game a bit.

Again, almost - the idea is that the settings declared in dev_config.manifest can be set in UI (OT_Video.lua, etc) VERY easily - or at the command-line. Any shader or other graphics script (surfs, manifests, etc) can use those list symbols to change features, enable chunks of code, etc. It is very, very flexible and designed to make expanding the systems and giving user control over new features easy and without any code-level edits.

Any time you see a graphics engine file - there’s probably a ‘mod’ version meant for override by Mod authors. However, don’t edit the base ones, any patch we do will break it, they may even end up protected from edits at some point.


I’ve been making some Star Trek TOS starships, for my own fun really, and I needed animated bussards on my ships. So I used the advice in this thread and got this:

(five meg gif warning)

I wrote a shader that can take a texture flipbook then animate it in HWR. The shader’s not done yet, though, as everything’s hardcoded (4x4 sheet, 20fps or thereabouts), but setting up the shader was mostly painless. Just need to work out how to add new variables to my shader that I can use the HOLD_PARAMS block to allow you to set framerate and texture sheet sizes. Maybe get rid a lot of the unused extra things. Got to say, that inTime variable really helped, as it gave me a way to do this!

(Sorry bout the bump, though. Didn’t think this needed a new topic, really…)


Well, I think that’s that! Got the shader parameter working in a float4. Shove in the x tiles, y tiles and framerate into a material node on the model, and the shader does the rest. I’m considering also making a texture scrolling shader, if anyone would find that shader handy?

DOUBLE EDIT: Huh, turns out the Max part of the config doesn’t work. This is the node holding the params: MAT[FedTOS2]_Param[animParams]_Type[Float4]_Data[4.0,1.0,0.5,0] and in the code, the variable is SOB_animParams (I will probably rename that to my own namespace…)

I think I just have the datatype wrong in 3ds Max. I’ll keep trying things.


Look at the Planet/Backgrounds Example - The example Planet has some params in it that are defined in Max for the shader, you are very, very close! :wink:

Ahhh, the PARAM bit needed to be capitalised and float4 needed to be RGBA. It works perfectly now!

1 Like

That looks all kinds of wickedly awesome!! Can’t wait to see it first hand!

I’ve worked on an extra feature for this, as I had an extra float free in my data: Scrolling and Rotating!

It scrolls along horizontally and vertically, it rotates around, and it uses the same shader as the flipbook animation! This could be useful for a fair few effects, potentially.

I’ve uploaded the shader to a github repo, located here:

Feel free to use it, and let me know if you spot anything that could be improved or added.


@CMDBob… you’re a hero among men :smiley:
Could something like this also be used for the TNG flat triangle style bussards? They only have a very subtle animation on them

@Major_Stress did you see this?

I hope I can wrap my head around this!

I can’t go into any sort of details right now (trying not to work all weekend) - but I have some minor critique of the shader, and also ideas on how I’d do the same effect a bit differently. I’ll explain soon. BUT - that isn’t meant to take away from what CMDBob did, which is amazing and really, really needed!


Yeah, I did shove it together in about 4-5 hours! I have an idea how I could probably integrate it into the ship supershader with a series of #ifs in the right places, but that’d mean overriding the main ship shader and I didn’t want to do that in case a newer shader was ever added in an update. (plus, using an if statement in a shader is costly, and I perhaps should have had scrolling/rotating as a seperate shader…)

@Nathanius - That was one of the ideas I had for the scrolling/rotating feature, as I thought it could be handy for TNG triangle bussards myself.

EDIT: Oh, I’ve made one little update since the original release. Forgot to remove debugReload from the shader’s prog. Whoops! :flushed:


I hadn’t thought too much about the issue of trying to do a variant ship shader with our group still editing (probably a few more versions before we’re done). I may tackle that with some sort of ‘injected functions’ approach - so your own shader can override/replace parts without having to directly edit it… Hrm. I’ll have to think on that more. That one single .frag file draws very nearly everything ship-related in the entire game!

I did indeed… This is exactly the animated effect i am looking for. Outstanding work CMDbob! However i want to “One Up” it by making the bussards semi transparant (minus the blades of course), and have actual flashing lights (using nav lights) behind the semi clear surface. However if we can’t pull off the transparancy’s ill gladly take animated textures! :slight_smile:

I dont know any of this code monkey stuff. I am an Artist. Not a programmer, but document, and save what you are doing. Even if we cant use it i am sure someone can. Nathan Im not sure if I can wrap my head around this, but im gonna check it out, and see what if anything i can do.

1 Like

Demo of my test for the animated bussards :sunglasses:

(whoops, don’t know how that was the mobile link before >_< )

1 Like

If that kind of feat does not bring back the B5 modders, nothing will :smile:

Could a shader perhaps be created to do shields that can turn a diff color based on hp. Lights that flicker (randomly as in diff places so its never the same flicker sequence, when badly damaged. B5 jumping gate effects is a must i think.

Hmm could it also be the time for animated phasers galaxy style that the st mod teams have wanted to do for so long?

Why it’s called a bussard anyway?

It’s named for Robert W. Bussard, who first proposed the engine concept it’s based on.


Had an idea based on something @herbyguitar tried in STC for HW2C, was wondering about feasibility

There’s an animation used on a couple of ships where it’s activated using CodeRed_OnSet, we were wondering if we could have a shader based on the thruster shader that had a transition triggered when CodeRed came up? And would go back to “normal” with CodeGreen_OnSet? We would use this for things like the glowing torpedo ports on Klingon ships :smile:


It would also be interesting to be able to trigger shutting on and off nav lights and GLOW on death or disabled from EMP


I have some features I want to add that would allow this - and a long-delayed idea which I’ll probably get into the next update (after the one we’re finalizing now).

A ‘stateful’ shader parameter control is on my list for later - which would give you this, and much, much more.