PrismaticFlower / shaderpatch

Improved shaders (and fun stuff for modders) for Star Wars Battlefront II (2005) - Incompatible with Classic Collection
MIT License
39 stars 2 forks source link

More normal_ext.specular inquiries #59

Closed DoctorAnsem closed 5 years ago

DoctorAnsem commented 5 years ago

I noticed just now that if normal_ext.specular is slapped onto a model with -vertexlighting true, it doesn't receive specular highlights from directional lights. The stock material does.

Now, here's the catch - this is actually very good in terms of how it can be used for interiors, as it never really made sense to have the sun cast a specular highlight where sunlight should be completely obstructed. However, for vertex lit exteriors this is not that good obviously. It does, of course, raise the question as to why an exterior would be statically lit in the first place but it is what it is, a design choice that worked with the stock shaders as well as it could.

Here's the question: would it be reasonable to implement a material flag that dictates whether or not the material should receive specular lighting from directional lights?

And additionally, I hate to bring this up as #57 is already fixed and it's not exactly the same problem, but the specular materials still seem to be a tiny bit brighter than the regular normal_ext materials. It's definitely not an eyesore like #57 was, but as the perfectionist that I am I can't un-see it either. Notably enough, as the specular effect vanished with me adding the -vertexlighting flag, the color mismatch vanished too. I don't think it's the specular highlight itself, as it happened consistently all across, and the area of the texture that made it noticeable is blacked out on the gloss map anyway so I guess I'd blame the diffuse again. As I said though, it's a very minor difference in shade but it's there so here we go.

PrismaticFlower commented 5 years ago

Here's the question: would it be reasonable to implement a material flag that dictates whether or not the material should receive specular lighting from directional lights?

That feature itself would be fair simple to do. (Although I'm not particularly keen on the idea of having another if check in the normal_ext shader if it isn't adding something significant.) But I don't think it would solve the problem in the way you expect. You see each shader in the game has a set of variations for different combinations of lights. (No lights, Dir Lights + Point Light, etc) The game then picks which one to use for a given frame; this really is key here.

So while a shader could ignore lights the game wants it to use, it couldn't use lights the game didn't tell it about. It's the latter situation we find ourselves in here. The model is marked as having static lighting baked into it so when deciding what lights to use when drawing it the game skips any marked as static. Nothing Shader Patch can do in this regard.

And additionally, I hate to bring this up as #57 is already fixed and it's not exactly the same problem, but the specular materials still seem to be a tiny bit brighter than the regular normal_ext materials. It's definitely not an eyesore like #57 was, but as the perfectionist that I am I can't un-see it either. Notably enough, as the specular effect vanished with me adding the -vertexlighting flag, the color mismatch vanished too. I don't think it's the specular highlight itself, as it happened consistently all across, and the area of the texture that made it noticeable is blacked out on the gloss map anyway so I guess I'd blame the diffuse again. As I said though, it's a very minor difference in shade but it's there so here we go.

Oh crap, this is actually a lot worse than you think. I rechecked the lighting code in normal_ext.fx and I've made two (one character) typos and instead of using the direction and color for the second directional light when calculating the second directional light I've been using the direction and color for the first directional light, resulting in models being lit using the first light twice.

This might have been screwing majorly with the look of your map and I consider this so bad that I'm going to delay going to bed and post a new release to fix it asap, should be up in a couple minutes.

DoctorAnsem commented 5 years ago

So while a shader could ignore lights the game wants it to use, it couldn't use lights the game didn't tell it about. It's the latter situation we find ourselves in here. The model is marked as having static lighting baked into it so when deciding what lights to use when drawing it the game skips any marked as static. Nothing Shader Patch can do in this regard.

Ahm, well. That's odd then, because the stock shader is in fact casting specular on the statically lit surface as explained. If you look at space maps, the capital ships do receive specular highlights despite being vertex lit so there's something Shader Patch is doing differently.

Still, I'm not sure it's a bad thing... Interiors really shouldn't receive the specular shine from outside lights. Unless... maybe shadow regions filter the color of the specular accordingly and that's why I've never fussed about that before. I'm honestly drawing a blank on this lol.

PrismaticFlower commented 5 years ago

Ah, yeah I forgot to mention some stuff last night. So stock models with specular enabled actually get drawn twice. Once for diffuse lighting and once for specular lighting. Each of these uses a different shader, for whatever reason (artistic or simply oversight) when the game setups the specular shader it doesn't bother considering if a light is static or not, it only seems to care about if the light is marked as casting specular.

SP custom materials override the shader used for diffuse lighting, so they get all the input it does. And the game does (obviously) take into account whether or not a light is marked as static when setting it up.

DoctorAnsem commented 5 years ago

Well that clears it up, I suppose. So really the feasible way to work with this is to use -vertexlighting strictly for interiors only, and if need be add a region-restricted dynamic directional light inside to cast specular on whatever surface wanted. It makes perfect sense this way.

Since all the points I had have been discussed and put to rest, I suppose this can be closed.