Belendor 说:
Well, thanks for the explanation. It answered the OP pretty much.
It doesn't hurt contributing a basic shader tutorial though, there are so little information around. At least, that is what I would do if I could trust my knowledge like you do.
If you want a
really basic shader tutorial then look down. But you are going to have to drag around learning the syntax of HLSL if you want to do something meaningful anyway.
Shaders need to be as lightweight, small, clever, nuanced and optimized as possible too. Don't forget that they are mini-programs that run in parallel for every pixel and vertex of every object of the scene.
--
How to setup Warband shaders and make them work with your mod.
0. Enable
Edit mode and
Windowed mode using the launcher's options. To skip the intro videos rename
to something else in the game root, if you haven't already.
1. Download the shader sources provided by Taleworlds.
<insert link here>
2. Extract the compiler (fxc.exe), its batch script (compile_fx.bat), engine header (fx_configuration.h) and the main effects source (mb.fx). You can skip the rest.
3. Rename
to
, open the batch script with your favourite text editor, replace
by
and
by
.
Or even better replace the script by this one, which I made for the The Last Days of the Third Age Warband port:
插入代码块:
:start
@echo off && title compiling the tld hlsl shaders thing-- && echo ^[working hard...^] ^[started at %time%^] && echo.
start /b /wait /i /high /realtime fxc /D /nologo /D PS_2_X=ps_2_b /Tfx_2_0 /Fomb.fx mb_src.fx
echo. && echo Shader processing has ended at %time%.
echo Press any key to recompile. . .
echo ___________________________________
pause>nul
goto :start
4. Compile the sources double-clicking the batch script, it will take a while, a
file will be created in the root of your module folder, it's a binary file. You should know that the game also accepts the sources as input (using the same filename), but they will be recompiled every time they are needed and if you reload it (by using Ctrl+F in the game window) while having syntactic mistakes the game will crash due to failed compilation.
If we compile offline, by using the provided script, we can see possible errors and warnings and correct them without having to restart the game.
5. Run the game, select your module. Now you are running your own shaders file, even if they are identical to the ones coming from the game. Press Ctrl + F and see if reloads fine. Nice!
6. Edit the shader file. Open
with a decent editor like Notepad++, change the syntax highlighting to C/C++, so you can fold braces and conditionals. Take a look to the structure, a shader file is composed by various parts, constants, vertex and pixel shader functions, and techniques, which bind them into a single element.
The general pipeline of shaders is like this, the game displays a mesh by using the DirectX 9 framework, binding it to a technique, a technique is composed by two parts, a vertex program (or function) and pixel program (or function).
In particular, Mount&Blade uses the
插入代码块:
<mb-root>\CommonRes\core_shaders.brf
file (you should make a copy of it in your
插入代码块:
<mb-root>\Modules\<mod>\Resources
folder to override the original one) to wire different techniques from your shader file with materials used in other resources.
--
If anybody tries it I will expand this further into a full-fledged thing.