[ASK] How to create shaders ?

正在查看此主题的用户

ElPadrino

Sergeant Knight at Arms
Hi everyone, I'm looking for creating new shaders for my mod. Something like accentue bump or create blue shadow around meshes.
I have any idea about how I can do that and I found any tutoria. Someone have an idea ?

Thanks
 
creating new shaders can be pretty complicated, I have never managed to do more than make a couple of waving flag shaders and a shader which flows like a river. You will have to download the mount and blade shader files which can be found from the taleworlds website, have a look at them to get a bit of an idea, but honestly to create anything decent you would have to read up on hlsl language, which is beyond my head. Although Ive said this Im sure a alot of people would disagree that shaders are complicated

 
Shaders are using either of the two languages; HLSL and GLSL. I assume for more complex shader tecnhiques, you will want to use HLSL but for more basic stuff, go on with GLSL. It is not any harder than learning any coding language, go visit my sticktied thread to find xenoargh's good ol' shader thread which covers pretty much everything with long discussions.
 
Oh okay, I cant learn something new for the moment  :neutral:

SO do you knwo some customizable shaders engine ? (I know Sweet FX)
 
Belendor 说:
Shaders are using either of the two languages; HLSL and GLSL. I assume for more complex shader tecnhiques, you will want to use HLSL but for more basic stuff, go on with GLSL. It is not any harder than learning any coding language, go visit my sticktied thread to find xenoargh's good ol' shader thread which covers pretty much everything with long discussions.
HLSL is used by Direct3D, GLSL is used by OpenGL. If you want to write Warband shaders, HLSL is your only option.
 
Belendor 说:
Oh, sorry for the wrong information.

GLSL, HLSL and Nvidia Cg are pretty much the same thing, a C-like language for doing arithmetic with vectors and outputting colors. Some intrinsic functions and data structures vary. But the gist is the same, maybe GLSL is a bit weirder but don't be sorry for that.

I used GLSL for my sprite shader in that thread because WebGL (the 3D toolkit for web browsers) uses it, and I wanted to show a quick preview for everybody instead of having to compile your own (HLSL) sample in-game.
 
ElPadrino 说:
Hi everyone, I'm looking for creating new shaders for my mod. Something like accentue bump or create blue shadow around meshes.
I have any idea about how I can do that and I found any tutoria. Someone have an idea ?

Thanks

3479838-1362693386.jpg
rim5b.jpg


If you are talking something like Skyrim's freeze effect. It's just a "cheap" fresnel rim lightning addition.
There's a lot of information on the Internet if you know what to search:

插入代码块:
[url=http://lmgtfy.com/?q=fresnel+rim+light]http://lmgtfy.com/?q=fresnel+rim+light[/url]


fresnelrimlighting.JPG
150px-Alyxfresnel.jpg
raman_0009_Layer%204.jpg


It looks something like this. You won't find any M&B specific info,
as shaders are the same for all DirectX 9-based engines.
 
Belendor 说:
You definitely need to write a tutorial covering all the basics, at least how to add one.

How to add one... what? One shader BRF entry? One DX technique? One pixel shader? It's a lot of stuff, the best thing is to try to do the steps separately.

When I started working with shaders I was pretty lost. But once I got them compiling and loaded by the engine everything started to make sense. Normally one starts by fiddling with the existing techniques, find the shader of a model and start changing the pixel shader slightly seeing how it reacts.

Maybe the first time you try to make it all red or something. Copy and paste small snippets that you find in the interwebs.
Make the texture coordinates twice the size, something like that, so that you don't go from zero to hero.

If you don't even attempt to try don't expect me to do a huge ass tutorial covering all the bases.

--

One just has to know that when the game detects custom shaders (while having the Edit more enabled, of course, what kind of modder are you?), when it detects a
插入代码块:
mb.fx
inside your module folder, you can reload them instantly using Ctrl+F.

That makes fiddling with shaders a lot more fun and forgiving that working with the module system, for instance.
 
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.
 
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
插入代码块:
binkplay.exe
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
插入代码块:
mb.fx
to
插入代码块:
mb_src.fx
, open the batch script with your favourite text editor, replace
插入代码块:
mb.fx
by
插入代码块:
mb_src.fx
and
插入代码块:
mb.fxo
by
插入代码块:
mb.fx
.

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
插入代码块:
mb.fx
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
插入代码块:
mb_src.fx
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.
 
That is simply great, thanks. Already added into sticky. Oh, and don't feel like I asked it for myself in first place.
 
Belendor 说:
That is simply great, thanks. Already added into sticky. Oh, and don't feel like I asked it for myself in first place.

Alright. So that's what I was saying, there aren't any shader-related tutorials because there's close to zero shader development in this game. Most of the questions are the ones I receive directly, I guess. Even if my knowledge is just enough to dabble into it.

Hope the tutorial up there helps to solve this catch-22 paradox thing and we get mods with more interesting visuals. Or at least lower the entry level.
 
jacobhinds 说:
A great tutorial. I tried looking into shaders myself, but the sheer amount of maths involved in online tutorials led me to assume it was solely for people with graphics degrees. Thanks for this.

That is mostly true, but one can also do all kinds of nifty things at an entry level with all the information out there. Let others do the research. The technical artist community is really open and one can find sample code and easy-to-follow reference materials on the Internet.

You probably all remember the fuzz with minor tweaks like colored specular and glow shader from xenoargh when they were posted in the forum some years ago. Small things like that give a small boost in quality and uniqueness to the mod in a crowded landscape of cookie cutter creations (marketing blurb).
 
后退
顶部 底部