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

Blending Emissive map with vertex colors in normal_ext #128

Closed DoctorAnsem closed 3 years ago

DoctorAnsem commented 3 years ago

Since the stock materials do factor in vertex colors to glowing polygons, it could be useful for normal_ext to replicate this behaviour. There are a couple of scenarios where it would be applicable.

  1. Vertex alpha being used to smoothly fade out emissive surfaces
  2. Geometry particles. These can't use the particle_ext rendertype, but what they can use is a normal_ext material. However since the emissive texture no longer obeys color transforms, everything will be drawn according to the coloring of the base texture which in most cases is desaturated for the purpose of being able to use one texture in multiple unique ways.

Just a little improvement to consider, I guess.

PrismaticFlower commented 3 years ago

Those sound like compelling use cases, I'll try find time to work on it.

Vertex alpha being used to smoothly fade out emissive surfaces

Is vertex alpha controlling it necessary or could it just be the vertex color? In that case when fading was needed one would have to fade to black but the vertex alpha would still be available for other uses.

DoctorAnsem commented 3 years ago

Hmm, that is a good question. The case I was actually using vertex alpha for is just a scrolling, transparent emissive material, a sort of energy beam that fades out into the sky. So there is some flexibility, I guess? Would it break things if a transparent material used the overall brightness value of a vertex color to multiply the final transparency of the vertex, textures included? Or something along those lines, whatever works and is the easiest to implement lol. I don't mind the details, I'd just prefer to have any kind of method to fade that beam out without peppering the world with particles.

PrismaticFlower commented 3 years ago

Coming in the release that will be posted as soon as it finishes building is support for MultiplyEmissiveByVertexColor. For now multiplying by vertex color was simplest to implement.

As it is in a preview release details about how it works can be changed so let me know if it is unsuitable in someway.

DoctorAnsem commented 3 years ago

I'm not sure if it's working correctly, it doesn't actually seem affect the emissive texture in any way - it does change the diffuse blending as intended though.

PrismaticFlower commented 3 years ago

Oh, I see what I've done wrong. Sorry about that, I'll aim to get a new version out with it actually working by tomorrow. Thanks for testing it so quickly as well!

DoctorAnsem commented 3 years ago

Hmmm, so I grabbed the latest version just now but it unfortunately still didn't quite do the trick - now the switch doesn't actually do anything at all to either the diffuse or the emissive textures. :/ It's just treated as if it's always "false".

PrismaticFlower commented 3 years ago

I'll investigate further! One quick thing is that the .msh.option file doesn't have -vertexlighting in it does it? As that would interfere with the setting.

DoctorAnsem commented 3 years ago

Nope, no vertex lighting on this one. And I don't think the particle meshes are treated as having it either, iirc some of them might be explicitly tagged -additiveemissive in the option file but I'm guessing that just overrides the material flags. As far as vertex lighting goes I don't think the particle meshes usually have a CAV property at all.

PrismaticFlower commented 3 years ago

Found the problem I did a typo and made it conditional on the env map being active rather than the emissive map. Expect a new release later today fixing it.

https://github.com/SleepKiller/shaderpatch/blob/dacf925998a24619f457daa9333b1bb8da6eb5d4/assets/scripts/material/normal_ext.lua#L77-L79