B Info Shader Shader Stuff- HLSL instruction limits

Users who are viewing this thread

Jarvisimo said:
Okay, thanks.

Is there any chance you could PM me the code for your new standart shader for me to look over and study?
I dont think it would help to be honest, it is a complete mess and you would find it very hard to understand what is going/ what is being used where. I am releasing my shader pack in the next few days though, so will have access to it then if you really want to have a look at it but it will not make things more clear, it was one of the first shaders I coded and I literally had very little idea what was going on :smile:

Some native warband shaders do feature a nice clearly coded fresnel function though, just have a search through the shader file for "fresnel"
 
La Grandmaster said:
Jarvisimo said:
Okay, thanks.

Is there any chance you could PM me the code for your new standart shader for me to look over and study?
I dont think it would help to be honest, it is a complete mess and you would find it very hard to understand what is going/ what is being used where. I am releasing my shader pack in the next few days though, so will have access to it then if you really want to have a look at it but it will not make things more clear, it was one of the first shaders I coded and I literally had very little idea what was going on :smile:

Some native warband shaders do feature a nice clearly coded fresnel function though, just have a search through the shader file for "fresnel"

Everybody is adding fresnel terms to everything lately. Reminds me to the bumpy and plastic-y look that games got when starting to use normal maps back in 2004. They are all overused and overdone, without any stylistic need, put there to show off and say "hey guyz , look awsom gfx 4 u, nexgen ftw owned omg real lyf rolfcopter pwnz hax~ 2edgy4me we kn do it 2 ^_^".

Take a look. Moderation and barebones approach! Less is more, specially in real time shaders where performance is key and what you see is just a fraction of what you feel of an enjoyable interactive experience!

If you want references take a look to The Old Republic and Dishonored games, for extra halo-y or spectral-backlight-which-comes-from-nowhere effects around characters and sundry things.
 
Yes, I don't actually want a fresnel effect for my mod, I just want to be able to do it for the understanding/practice.

I don't want a desaturate either. :smile:

Though I do want a pretty flag wavy shader. The Deluge ones look amazing. :smile:

Thanks for the advice though, Swy.
 
Swyter said:
Everybody is adding fresnel terms to everything lately. Reminds me to the bumpy and plastic-y look that games got when starting to use normal maps back in 2004. They are all overused and overdone, without any stylistic need, put there to show off and say "hey guyz , look awsom gfx 4 u, nexgen ftw owned omg real lyf rolfcopter pwnz hax~ 2edgy4me we kn do it 2 ^_^".
I agree to some extent, but "everybody" and "overused and overdone"? Apart from Docms shader pack (and mines which is unreleased and very poor in comparison) I couldnt name one other which adds new fresnel effects to M&B

 
La Grandmaster said:
Swyter said:
Everybody is adding fresnel terms to everything lately. Reminds me to the bumpy and plastic-y look that games got when starting to use normal maps back in 2004. They are all overused and overdone, without any stylistic need, put there to show off and say "hey guyz , look awsom gfx 4 u, nexgen ftw owned omg real lyf rolfcopter pwnz hax~ 2edgy4me we kn do it 2 ^_^".
I agree to some extent, but "everybody" and "overused and overdone"? Apart from Docms shader pack (and mines which is unreleased and very poor in comparison) I couldnt name one other which adds new fresnel effects to M&B

I was talking more about real standalone AAAaaaAAA+ games popping out for current consoles and PC.
It wasn't a critic to fellow modders. Take it more like a in-situ rant for the whole industry on fashionable trends.


Jarvisimo said:
Yes, I don't actually want a fresnel effect for my mod, I just want to be able to do it for the understanding/practice.

I don't want a desaturate either. :smile:

Though I do want a pretty flag wavy shader. The Deluge ones look amazing. :smile:

Wavy things are probably the easiest effects you can accomplish with shaders, I made a bunch of these for the latest version of The Last Days (both 1.011 and Warband) and recorded some preview videos for kicks.

These kind of vertex shaders are really simple and cheap if you know what to modulate with to get a nice falloff from the pole to the bottom edge of the cloth. Requires quite a bit of tweaking until you get a somehow realistic look, though.

--

Let's see if I can get you inspired, quotes coming right from the TLD thread:

Swyter said:
Swyter said:
Youtube is getting ****tier and ****tier as the time passes.
Here you have some quick videos, anyway.

Another one, Janus is limiting to two embedded videos per post.

Swyter said:
I took a break from fixing the boring formations thingie and started to do some shader magic:
Code:
https://trello.com/c/NCDdDIT2/60-wavy-scene-prop-banners

Not exactly poetry, but I think they look good enough:


http://youtu.be/tbPdxdK_txI



Edit: They consist of a
Code:
sin()
or
Code:
cos()
operation fed with a periodic or linearly incrementing value, in our case, time, using M&B's provided
Code:
time_var
uniform. Basically you add the result of
Code:
sin(time_var)
to the current vertex position in whatever coordinate space you want (before or after the world transform). With that you normally get a wobbly effect for the entire object, if you modulate by the vertical position or the vertex color you can change the periodicity, strength and phase of the wobbly effect, ending into a more natural waving effect depending on other factors, like rotation. You can stack complexity as much as you want, but generally simpler but grounded effects are all what you need. Looks cool and you aren't losing FPS budget.

More here, a bit outdated, still valid:
Code:
http://mbmodwiki.ollclan.eu/Swyter%27s_Simple_Waving
 
Woah, nice job, those are really convincing... stop making me jealous, Swy! :grin:

Seriously though, those are exactly what I'm going for.

These kind of vertex shaders are really simple and cheap if you know what to modulate with to get a nice falloff from the pole to the bottom edge of the cloth. Requires quite a bit of tweaking until you get a somehow realistic look, though.
Hold it, hold it. What do you mean "modulate"? How would I go about doing this? I am totally clueless, remember. Grandmaster's tutorial was perfect for my pathetic level of intelligence.

I am guessing here that I need to do some sort of for/next loop for the length of the texture, displacing it somehow?

EDIT: Just saw your edit above. You babe. I'll have a crack. :smile:
 
Jarvisimo said:
Woah, nice job, those are really convincing... stop making me jealous, Swy! :grin:

Seriously though, those are exactly what I'm going for.

These kind of vertex shaders are really simple and cheap if you know what to modulate with to get a nice falloff from the pole to the bottom edge of the cloth. Requires quite a bit of tweaking until you get a somehow realistic look, though.
Hold it, hold it. What do you mean "modulate"? How would I go about doing this? I am totally clueless, remember. Grandmaster's tutorial was perfect for my pathetic level of intelligence.

I am guessing here that I need to do some sort of for/next loop for the length of the texture, displacing it somehow?

EDIT: Just saw your edit above. You babe. I'll have a crack. :smile:

With modulating I'm just talking about multiplying some value by another.

Let's go deep! *turns off lights and powers on the projector*

Take a look to the image below. Imagine that the wave at the bottom is the waving made by our sin() function.
The middle graph is what you get when you multiply the regular back-and-forth of the wave (which in our case represents just an addition to to horizontal position [in the current view model] of every vertex where this little program or shader is run) by some random value (which is the curve at the top) making it more or less stronger. Normally you would want an stronger movement on the loose parts of the cloth which aren't sewed to the pole, or to simplify, as you go down, the movement gets stronger and the number bigger. This is a linear gradient from top to bottom. Imagine it in a visual way in your head, like a grayscale gradient, going from pitch black at the top to pure white at the bottom, passing over every single shade of gray in the middle. That's your modulator.

How can you go from that concept to reality? Well, you can approach this in various ways, like if the texture coordinates from your model are vertical, and your banner images in your texture are perfectly aligned, you could just modulate by using
Code:
tc.y
. If you don't want to depend on pesky UV coordinates or a perfect texture layout you can use the absolute vertical position of the vertex itself,
Code:
vPosition.y
. There are many ways of sourcing your information, transforming it in the most simple and "performant" way to make it do what you want out of it and show the right thing at the screen. That's the essence of shaders, one has to balance a lot of factors.

modulation.PNG



This the actual vertex shader program used in the videos above, take a look. Credit me if you use/scavenge it, all or parts.
Code:
VS_OUTPUT vs_main(uniform const int PcfMode, uniform const bool UseSecondLight, float4 vPosition : POSITION, float3 vNormal : NORMAL, float2 tc : TEXCOORD0, float4 vColor : COLOR0, float4 vLightColor : COLOR1, uniform const bool swy_rohan_banners = false, uniform const bool swy_spr_banners = false)
{
	INITIALIZE_OUTPUT(VS_OUTPUT, Out);
	
	//swy-- constants, tailored constants everywhere! :)
	if(swy_rohan_banners)
	{
	 //swy-- if not metal thingy
	 if(tc.x < 0.944f)
	 {
		float seed = time_var + (vPosition.x/vPosition.y/vPosition.z);
		float v_modulator;
		
		//swy-- special codepath for sideways banner, modulating the waving vertically/horizontally by UVs. sigh :(
		if(tc.x < 0.547f && tc.y > 0.789f)
		{
			v_modulator = tc.x * 0.5f;
		}
		
		else
		{
			v_modulator = tc.y;
		}
		
		vPosition.y += ((sin(seed+cos(vPosition.x))*0.4f)* v_modulator*vPosition.x)/vPosition.z;
	 }
	}
	
   //swy-- per-pixel sampling for per-vertex shaders, now that's performant! :)
   if(swy_spr_banners)
   {
	 //swy-- if not metal thingy
	 if(tc.x <= (244.f/256.f))
	 {
		float seed = time_var + (vPosition.x + vPosition.y + tc.x + tc.y) + matWorld._m03;
		float thingie  = sin(seed + cos(vPosition.x)) * frac(tc.y*3.f) /* * abs(vPosition.x) */;
		      thingie *= 0.2f;
		
		vPosition.y += -(abs(thingie)*abs(thingie));
		vPosition.x += thingie*0.3f;
	 }
   }
   

	Out.Pos = mul(matWorldViewProj, vPosition);

	float4 vWorldPos = (float4)mul(matWorld,vPosition);
	float3 vWorldN = normalize(mul((float3x3)matWorld, vNormal)); //normal in world space


	Out.Tex0 = tc;

/* rest of the shader here, mostly standard stuff, all unrelated to the wavy thing */
 
That was a great explanation, thanks!

And the code is really really generous of you. Do you mind if I just stick it in game, then slowly tweak bits to work out what it does?

P.S What shader should I put it within? Or do I need to create a new "flag_shader" or something?
 
Jarvisimo said:
P.S What shader should I put it within? Or do I need to create a new "flag_shader" or something?
Depends entirely on what models you want to wave. I am guessing you want it to occur on banners, so i would suggest you create a new shader for banners - to do this copy an existing shader which has the features your are after and then add in swyters wave code.

Then you will have to create a new shader in a brf and defining the technique ect, then apply the new shader to your banner materials.
 
I have been looking into this post (http://forums.taleworlds.com/index.php/topic,255572.msg6128576.html#msg6128576) on animated normal maps and I dont actually think it would be too hard to code a shader which performed this. However the main problem I see is in passing values to the shader, to say when to "animate the normal map" and when to not.

You see currently the module system only allows us to pass values to shaders "globally", through these commands
Code:
set_shader_param_int			= 2400 # (set_shader_param_int, <parameter_name>, <value>),	#Sets the int shader parameter <parameter_name> to <value>
set_shader_param_float			= 2401 # (set_shader_param_float, <parameter_name>, <value>),	#Sets the float shader parameter <parameter_name> to <value>
set_shader_param_float4			= 2402 # (set_shader_param_float4, <parameter_name>, <valuex>, <valuey>, <valuez>, <valuew>),	#Sets the float4 shader parameter <parameter_name> to <valuex/y/z/w>
set_shader_param_float4x4		= 2403 # (set_shader_param_float4x4, <parameter_name>, [0][0], [0][1], [0][2], [1][0], [1][1], [1][2], [2][0], [2][1], [2][2], [3][0], [3][1], [3][2]),	#Sets the float4x4 shader parameter <parameter_name> to the given values .w components are 0001 by default

These all function on a "global scale" in that they can not be unit specific (or vertex specific, what we actually want). To give you an example, if I wanted an "animate" a horses normal map when it was moving I could use one of these commands to pass a value to the shader, however this would "animate" all horses normal maps, not just the horse which is moving - it would affect every model using the shader. There must surely be a way to pass values to the shader which I am missing, or is this stuff all hard coded. I was thinking that it could be done via vertex painting, but there is no way to paint vertex colours via the module system (well no way I can see).

I believe animated normal maps are how TW do their animated faces in bannerlord (https://www.taleworlds.com/en/Games/Bannerlord/Blog/7), and these must be specific to each unit, this is similar to what I am trying to do in WB.
 
La Grandmaster said:
I believe animated normal maps are how TW do their animated faces in bannerlord (https://www.taleworlds.com/en/Games/Bannerlord/Blog/7), and these must be specific to each unit, this is similar to what I am trying to do in WB.

They clearly do it using classic per-vertex skinning. With standard bones, painted rigging and poses.
Nothing of this fanciness is going to be included in M&B II. I'm pretty sure of that.

Nothing revolutionary on that front.

--

The thing is, the vertex weights and quaternions are passed by uniform to the shader, but the uniforms are changed every time the engine batches a character and sends the geometry to DirectX 9, and that's amid the rendering phase, part of an engine frame.

You can "only" change uniforms one time per frame using the module system. Which is more than I could even think five years ago, when even making skeletal animations was something difficult, out of hand or outright impossible.


So, to sum up, no, you can't go nuts with this. Unless you find a incredibly smart/unlikely way to sandwich various uniforms in between the render loop on a per agent basis and blablabla.
 
Hmm it would be possible to accomplish something similar if we were able to colour vertices (even just vertex paint an entire model) through a module system command. However I have not found any which would allow it to be done inside a scene, the only operations I found allowed vertex painting of tableau meshes, which where done on item initiation only - not dynamicaly in a scene, cannot change it mid scene
 
Docm30 said:
Swyter said:
They clearly do it using classic per-vertex skinning. With standard bones, painted rigging and poses.
Nothing of this fanciness is going to be included in M&B II. I'm pretty sure of that.

It's more likely done with blend shapes.

Which are normally setup as poses. And rigged to a skeleton just like any other skinned character so that one can have mesh-independent movement. You don't really want to manually tweak face vertices with all the range of expressions for more than two meshes, take a look at how painful is editing faces by pulling polygons in the current incarnation of the engine.

You create an array of loose bones depending on the neck, stuff like eyelids, mouth, and what not... Then you assign them to certain vertices by painting weights and move them into blend shapes or poses. Then you play them at runtime interpolating depending on gameplay or amount of blood for maximum duck face.

eYaA3pm.png

Oh, Frodogorn, color me green, green with envy!
 
Swyter said:
You don't really want to manually tweak face vertices with all the range of expressions for more than two meshes

Why would you? Why would you even do two? As long as all the heads use the same topology, they can use the same blend shapes. The shape of the head doesn't matter.
 
Docm30 said:
Swyter said:
You don't really want to manually tweak face vertices with all the range of expressions for more than two meshes

Why would you? Why would you even do two? As long as all the heads use the same topology, they can use the same blend shapes. The shape of the head doesn't matter.

I don't think they would be using the same topology/mesh.

Anyway, I know that blend shapes are common in computer animation, but in a game with lots of people on the battlefield that doesn't seem cheap, bone skinning makes much more sense to me. Apart from how the hell are implemented in shader, I can't think of how can be done in DirectX 9, I think that you are overestimating videogames, their complexity and performance budget.

I'm pretty sure that the current vertex morphing is done in the CPU, and that's just going from A to B for every vertex in the mesh, imagine sending ten versions of the same mesh to mix them on shader. Bandwidth, think of the bandwidth!
 
Back
Top Bottom