Modulative Lights?

Hi,

do I have to write custom shaders if I want to have modulative lights instead of additive ones? If so, how would you guys do it?

Greetings
BrightBit

What do you mean by modulative lights? Ones that would darken objects instead of making them lighter? I think that would be negative light.

I think simplest way to fake this would be projector with material that has multiply blend mode. It does not behave exactly like spotlight, but it’s close.

I guess writing your own shader could also work, but I’m not sure you can selectively choose which light will be treated as normal and which one as negative light via shader.

As far as I’m aware off, you would need to make your own custom shaders (vertex/fragment) in which you specify how you want to blend the results for each light. But like passe mentioned, this will be for every light that uses the shader and you can’t really say that it should only affect this or that light, this is due to how the different passes work (you have one for the main light, and another pass for every other). Perhaps that there is a way to distinguish different lights or light types, but I don’t know about that.

So if you also want to have “normal” behaving lights, you will probably end up writing a good couple of shaders (or variants) and use them where needed.

For the Deferred Lighting path, you could place a modified ‘Internal-PrePassLighting’ shader in the Resources folder (and restart Unity). Of course, this would apply the same to all lights.
It looks like you can simply adjust the blend modes of the lights, for LDR, HDR and HDR on the Xbox 360.

Doing the same thing with Forward Rendering, like Rld_ mentioned, is a bit more complex, because lighting is combined in several places. You would have to re-implement all lighting work that surface shaders do for you, in a custom multi-pass vertex/fragment shader.

You would have to change the blending mode for ForwardAdd passes.
You would need to rewrite Shade4PointLights(…)
You would need to change how that vertex light data is combined with the light computed by your Lighting model
You might want to change the behavior of Emissive light too (stuff like reflections/refractions)

And you wouldn’t be able to use the standard SH9 function for the lights applied as Spherical Harmonics.

What do you want to use it for?

Yes, you need to write custom shaders to change the lighting model.

How really depends on what you mean by modulative lights. Modulation is almost always multiplication, which is what all lights do: surface colour (albedo) is multiplied by incoming light (irradiance) to get the colour of the reflected light. This is done for each light, and the results are summed.

What would you want to happen instead?