B Info Shader Shader Stuff- HLSL instruction limits

Users who are viewing this thread

xenoargh

Grandmaster Knight
Well, I'm playing with the shaders.  Serdar wants feedback on the Forums; this seems like the place  :cool:

I have almost finished my first major task; using specular values as a cap to specular values, so that we don't have OMG BRIGHT on all our shiny things.

I just watched the code compile on a very simple brute-force clamp I wrote, after hours of futile struggle... until I looked up the HLSL spec and found something important enough I thought I'd share.

The code for all the shaders is compiling using Pixel Shader 2.0.  Not 2.0a (which is practically any card that can run this game in DirectX 9.0, let alone anything higher).  This is a severe and rather arbitrary cut-off; it means you can only use 64 instructions in your code!

Why the bar was set that low, I don't  know, but it's a fairly easy fix.  I thought I'd let my fellow hackers know about this silly issue right away; it saves a lot of time (and cursing) if you can write up to 512 instructions, and there's no point in worrying about whether players can use it, because if they can run the game with decent framerates in DX9, they have a card that is already PS2.X compliant.

Hope that was useful to a few folks.
 
Aye I noticed that too, but how do you compile it with 2.0a?
It's not an arbitrary cut-off though, and probably very sensible back when 2.0 was new and shiney. Now it's old and out-of-date :p

What might also help for shinyness is using higher coefficient values, like 100 and such, instead of the puny 10-30 range.
And I'm guessing you already figured out how to make use of colored specular maps?
 
I'm still working on it, as I'm still a bit confused about where I need to multiply it to get a good result, but once I got around the 2.0 limit, it got a lot easier, lemme tell you- I spent a couple of hours just trying to free up a couple of instructions this morning  :lol:

As for the how... go look at the lines that say, "compile PS_2_0".  You just change them to PS_2_X, that's it. 

Same with the PS_2_a; it's pointless to specify that when you can just go straight to _b, and again, there practically aren't any cards with those specs that can even play the game with DX9 anyhow.

It also makes the FXOs compile faster  :lol:
 
Thanks :smile:

While you're at it, modify your compile_fx.bat to only compile the a version, not the b if you didn't already.

As for colored spec maps... change this:
Code:
float spec_tex_factor = dot(tex2D(SpecularTextureSampler, In.Tex0).rgb,0.33);	//get more precision from specularmap
to
Code:
float spec_tex_factor = tex2D(SpecularTextureSampler, In.Tex0);	//get more color from specularmap

Unless you really need the extra precision.... (guess not eh? ^^)
 
Oh, rats.  Unfortunately, that does not work, like the last 10 things I've tried :lol:

Everything shiny gets washed out and white. 

What I want is for everything to hit the top of the specular color and get clamped to that, and no brighter, unless it's zero, in which case I want it to behave normally.  Nothing should hit white unless the specular is also white.


[EDIT]I think I just left a bug in elsewhere  :lol:  Testing now...[/EDIT]
 
OK, maybe I have a theory about what's wrong.  I think it's the specular coefficient that needs to be shifted, not the final RGB.  Trying that out; at worst, that means I need to boost coef a bunch on things.
 
You can just clamp stuff right?
However I don't know exactly what the problem is you want to solve this way. It will probably look unnatural, wouldn't it be better to just use lower spec values if you think it's too bright? Or higher coefficients, making the bright specular area smaller.
 
What I want is for things to not give a *white* feedback, where they aren't pure white, but a *colored* one, anywhere they don't hit the pure white point.

I do this with coef values, and it works really well, giving metals a more realistic look; but it's severely limited, because you have to use one value everywhere, instead of using gold values for gold, blue-grays for irons and steels, browns for leathers, and so forth.  IRL, objects don't just reflect back white light, it's colored where the light isn't so powerful that you can't see anything else.

In OpenBRF, it works just fine; a colored specmap gives you a color-shifted specular result.  It has never worked that way in Warband, and it really makes things look a lot more plastic and fake than they should.
 
Here, this will explain a lot better than words.

This is how the object should look, in the game:
colored_spec01.jpg


Due to whatever is wrong with the shader, it looks like this, instead:
colored_spec02.jpg


The difference is really huge; getting this working is kind've a big deal.
 
So you want a colored specular spots instead of white?
It should be enough to just change that one line where it reads the spec map, like I posted before.
Oh it seems like you managed to do it :smile:
 
Well, like I said, I tried that and it didn't work.  It's working now though  :smile:

That last shot is how it's supposed to work; now I can have different specular values for every sub-material of a given skin.  I should probably use something cooler than my silly Viking Opera helms to show it, but whatever.

I got going down the right path by looking at the coef values and how they interact with the lighting system- look down a few lines :smile:
 
OK, done testing it; the principle Idea works; now I just, uh, need to adjust about... every single specular  :lol:  The problem is that all the existing speculars lack color shifts, which makes them look a little flat and lifeless now.  Oh well, that's a trade I can live with.

Maybe not today; gotta go do IRL in about 15 minutes.  Oh well, at least it's possible now; been wanting to do this since I looked at Narf's stuff in OpenBRF.
 
xenoargh said:
Well, like I said, I tried that and it didn't work.

That's weird...

Cause thats all I did there, for as far as I can remember.

And I get this:
mb19d.jpg

with a spec map like this:
saxonshorthauberkspec.jpg


We are talking about the ps_main_standart right?

From what I understand you use the spec coefficients in open brf to define the color right? Its much easier imo to use the specular texture.
 
Hmm.  I really didn't get that result over here, but I didn't try anything that saturated, either.  I'll have to play around with Rainbow Brite tomorrow night, see what's possible  :lol:
 
Alright, well it is supposed to work :p
Everything multiplies there anyway, so.

If you have any other cool ideas for ways of using textures or anything. I'm all ears. I can't really think of anything  :shock:
 
Barabas said:
Alright, well it is supposed to work :p
Everything multiplies there anyway, so.

If you have any other cool ideas for ways of using textures or anything. I'm all ears. I can't really think of anything  :shock:
I've been trying to figure out how to make the plant/tree shaders wobble. Does anyone know how to that in HLSL?
 
Back
Top Bottom