If you have no idea what shaders can be used for, click one of the images below and see for yourself.
I have a whole lot of other videos featuring hlsl shaders so go check them out if you are interested.
Back in 2015, a guy called Bear released his shader-linker that made it possible to add new hashed shader names to a shader-names-table the game uses to lookup shaders when linking fastfiles.
The problem was that he did not specify how to setup the material so that the game could use these new shaders and with that, no one used it as no one knew how to use it.
We are going to create a scrolling 2D material, that can be used for eg. HUD-Elements, to be able to somewhat explain the setup thats needed.
This is obv. very basic but starting with something different would be way to much for this scope.
1. Material Template > root\deffiles\materials
Create a copy of the closest template related to our use-case. Would be mtl_2d.template in our case.
Name it z_scrolling_hud.template
This template fits perfectly, so all we need to change is the techset
We are going to use this template only for this specific shader so we’ll give the techset the same name as our template
2. Asset Manager
Create a new material with the following settings:
3. Techset > root\raw\techsets
Search for 2d (the techset that was in the stock mtl_2d.template) and find 2d.techset
Create a copy, name it z_scrolling_hud.techset and change it as follows:
Techsets in root\raw\techsets will be used by GPUs running ShaderModel 3, but CoD4 also supports ShaderModel 2 so we have to
create a copy of the new techset and place it in » root\raw\techsets\sm2 (a sm2 techset is needed or you’ll get errors on linking your fastfile)
4. Technique > root\raw\techniques
Search for the technique vertcol_simple2d.tech ( the original 2d one from the techset we used in step 3 )
Create a copy and name it z_scrolling_hud.tech
Bear’s shader-linker only works with ShaderModel 3 shaders, so change the version to 3.0 (VertexShader and PixelShader)
Rename both shaders to z_scrolling_hud and cut the .hlsl extension
Comment out vertex.color = code.color; because we are not going to use it in our shader (all defined inputs have to be used within the shader)
5. VertexShader > root\raw\shader_bin\shader_src
The VertexShader only needs to transform our vertices into worldViewProjectionSpace (cameraSpace)
Create a new txt-file and call it: vs_3_0_z_scrolling_hud.hlsl (every custom VertexShader needs the “vs_3_0” suffix)
Paste the following:
6. PixelShader > root\raw\shader_bin\shader_src
The PixelShader will, as the name suggest, shade our pixels; 1 pixel at a time
Create a new txt-file and call it: ps_3_0_z_scrolling_hud.hlsl (every custom PixelShader needs the “ps_3_0” suffix)
Paste the following:
7. Compiling the shader so that cod-linker can access it
Download the following package: v1.1_hlsl_xoxor4d.zip (includes all the files needed to compile your shaders)
Copy the files within 2d_tutorial\additional_files into your cod4 root directory if you did all the above mentioned steps yourself
Otherwise use the files within 2d_tutorial\whole_source (You still have to setup your material in Asset Manager as mentioned in Step 2)
Go into root\raw\shader_bin
Create a folder called backups (the compiler will make a backup of your shader_names file every time you compile a shader)
Type cmd into the address-bar of your file-explorer window and hit enter to open a commandprompt that points to this directory
Use the following to compile your shader: shader_tool z_scrolling_hud
This will compile the Vertex- & Pixelshader using microsoft’s fxc shader compiler
Shader_tool will also add the hashed shader names to the shader_names file and copy the compiled binary shaders over into » root\raw\shader_bin
8. Adding your custom material to your mod/map
Now just do what you normally do when adding custom materials to your mod/map
(This is not different in any way. You don’t need to include any files that we’ve created besides the material from Asset Manager.)
1. Zone File
Build your mod/map fastfile and put your .iwi into your .iwd
Run the game and test :)
Quick links for the individual files within the material chain with more in-depth information