SWBFII HLSL Shader Toolkit

Started by SleepKiller, November 29, 2017, 02:16:51 AM

Previous topic - Next topic
As some of you likely know I've been working on this toolkit for a few weeks now and I feel it is now reasonably complete. It allows you to write shaders for the SWBFII in HLSL and have those shaders target either Shader Model 2.0 or Shader Model 3.0. See the readme for more information.

To install and use this you'll need to download or clone the repository from GitHub. Put it into the root of your BF2_Modtools folder. The folder structure should go BF2_ModTools -> shader_toolkit -> src.  Not BF2_ModTools -> shader_toolkit   -> shader_toolkit -> src. After that you can bootstrap the toolkit or you can download this which is a shader_toolkit folder containing a build folder for you to copy into the shader_toolkit you got from GitHub.

After that simply see the Getting Started in the readme for how to use the tool!

GitHub Repository
Prebuilt Compiler and Pre-extracted Premunged Files
Prebuilt core.lvl containing the New Shaders

I'm probably going to get this just to see how much fun I can have and to learn... Thanks for the great work!
The BOBclan:  A Rich History


Quote from: Unit 33 on November 29, 2014, 03:44:44 AM
'Please, tell me more about the logistics of the design of laser swords being wielded by space wizards' - Some guy on the internet.

Now if only there is someone to create the relef terrain thing for pixel shader 3.0 that will be awesome!!!!Im telling you people even if its not perfect its a big thing for this game.When i heard that such thing is possible here i totally forgot about other shaders,not because i dont need them.For example if its easyer i would absolutely love to get the full reflection water shader moved to....lets say some of the non working shaders like  the "sky" shader.If im not mistaken it was 11

I'm wondering if we can modify shaders to have pixel point/spot lights emit from nulls/primitives (particularly in vehicles and weapons) that are based accordingly. You'd probably need a reference to the game objects in the scene..

This could make things like a Halloween map that requires the use of a flashlight that actually lights up the buildings that use the shader.

Headlights on vehicles would be so cool!

Quote from: Dark_Phantom on November 29, 2017, 04:51:34 AM
I'm probably going to get this just to see how much fun I can have and to learn... Thanks for the great work!
Messing with things is a lot of fun. I hope you get some enjoyment and knowledge out of it!

Quote from: Ginev on November 30, 2017, 01:34:30 AM
Now if only there is someone to create the relef terrain thing for pixel shader 3.0 that will be awesome!!!!Im telling you people even if its not perfect its a big thing for this game.When i heard that such thing is possible here i totally forgot about other shaders,not because i dont need them.For example if its easyer i would absolutely love to get the full reflection water shader moved to....lets say some of the non working shaders like  the "sky" shader.If im not mistaken it was 11
I assume you're referring to the .msh file render types? They're actually a poor representation of SWBFII's material system;  I suspect a lot of them are just layovers from SWBF1. And in SWBF1 I suspect a lot of them are just layovers from it's early development days or from other games.

From a typical game object's perspective (after the munger runs) SWBFII effectively only has two render types. Normal and Refraction. in SWBF1 there were more, but that was because it's rendering system was a lot less unified and actually less powerful.

In regards to a dynamic reflection render type, shaders sadly don't have any say over what they're passed, they simply take input data and output a result. So setting up a custom reflection shader is not possible using just the shaders.

However Refraction (surprisingly) might be able to give you something similar to what you want. To perform it's refraction it get's passed a copy of the game scene rendered at a lower resolution. It then projects this texture onto the model with an offset specified by the bump/normal map. If you use a completely grey value for the bump map (RGB{128, 128, 128}) it should turn off the distortion and create an almost reflection effect.

Quote from: RepComm on November 30, 2017, 09:50:13 AM
I'm wondering if we can modify shaders to have pixel point/spot lights emit from nulls/primitives (particularly in vehicles and weapons) that are based accordingly. You'd probably need a reference to the game objects in the scene..

This could make things like a Halloween map that requires the use of a flashlight that actually lights up the buildings that use the shader.

Headlights on vehicles would be so cool!
I've never tested it but if you're using SWBFII you can use -attachlight in a model's option file (Or AttachODF with AttachDynamic in the odf, see the modtools documentation.) and use a spotlight with a projected texture.

As far as doing anything else as you say you would need to control/edit the game's scene in some way, which shaders obviously have no concept of.

Quote from: RepComm on November 30, 2017, 09:50:13 AM
I'm wondering if we can modify shaders to have pixel point/spot lights emit from nulls/primitives (particularly in vehicles and weapons) that are based accordingly. You'd probably need a reference to the game objects in the scene..

This could make things like a Halloween map that requires the use of a flashlight that actually lights up the buildings that use the shader.

Headlights on vehicles would be so cool!


Maybe you mean something like this?Watch to the end.

https://www.youtube.com/watch?v=pm-B493ucM4&index=14&list=UU4dhQo9u8auzSvj0AzadFKQ

Im using the BF2 Naboo lamp for this.If you want to test it by yourself make sure your map is completely night/dark.

Quote from: Ginev on November 30, 2017, 10:44:36 PM

Maybe you mean something like this?Watch to the end.

https://www.youtube.com/watch?v=pm-B493ucM4&index=14&list=UU4dhQo9u8auzSvj0AzadFKQ

Im using the BF2 Naboo lamp for this.If you want to test it by yourself make sure your map is completely night/dark.
Yes, that is one of the things I meant. That is VERY cool.
I wish we had these same features in BFI..

I remember in debugger exe, there was a function called "Normalshader.Minimal", it seemed to disable all or most of the shaders. Would it be possible to replicate this with your toolkit?

Yup. Although I don't know why you would want to do that. I'm guessing it would be for performance reasons?

It is probably simpler to force the game to use it's fixed-function rendering path by passing it `/fixedfunction` as a startup argument. It'll accomplish most of the same with a fraction of the work.

December 01, 2017, 04:27:03 PM #9 Last Edit: December 01, 2017, 04:36:52 PM by xMichael
Thanks. Out of curiosity, how hard would it be to replicate normalshader.minimal thing without understanding hlsl? Btw, great work on this. You always come up with some unexpected cool thing, like the splitscreen mod.

Not too hard actually. In the case of the Normal shader you'll just need to edit it's definition file so it only uses the basic shaders. You'll have to follow the instructions for installing the toolkit and getting it to produce a core.lvl.

After that for each state definiton in normal.json you'll be interested in these lines. They control which shader function is used for that state.

Quote
    {
      "name": "unlit opaque hardedged",
      "id": 1,

      "passes": [
        {
          "skinned": true,
          "lighting": false,
          "vertex_color": true,
          "texture_coords": true,
          "transform": "position",

These lines here.
          "vertex_shader": "unlit_opaque_vs",
          "pixel_shader": "unlit_opaque_hardedged_ps",


          "vs_target": "vs_2_0",
          "ps_target": "ps_2_0"
        }
      ]
    },

If you play around with swapping those values from different states around you should learn how to replicate what you want.

December 02, 2017, 11:54:43 PM #11 Last Edit: December 02, 2017, 11:57:14 PM by Ginev
Sleepkiller for now can you make me a simple core.lvl with just edited shadow shader?I just need my shadows darker.The rest of the shaders can stay unedited.If someone have time to do this that will be cool.My First assault Tat map need darker shadows.I just cannot reach the desire effect with the light section in the Zero editor.

I don't have the time personally sorry! Even then I'm not sure you want people to have to install a core.lvl that gives custom shadows designed only for your map. What if they play more than your map in one session? Seems like it may be better to focus on other aesthetic parts of your map.