More than one light in shaders

I wanted to write a toon shader and for that I would need the light data. I read here JME3 and Shaders :: jMonkeyEngine Docs and couldn’t find how JME handles if there is more than just a directional (seems special thread due the reading) or a point light but like many point light, how do I handle that with in a shader? Is there somewhere an example or more documentation how JME is handling lights in shaders?

Maybe this helps

1 Like

JME has single pass and multipass lighting.

Multipass lighting (which I’m 99% sure is still the default) renders the scene once per active light and mixes the results.

Singlepass lighting packs some number of active lights into an array so the shader can iterate over them as needed. It has a max number beyond which it will render the scene again with another batch of lights like multipass does. (So if you set the max to 6 lights but have 10 lights it would render the scene twice, once with 6 and again with 4).

That is my understanding.

Each approach has tradeoffs.

Still, if you are of the mindset “I’m going to put point lights all over the place” then you will either want to bake them into your geometry instead or write your own deferred renderer to replace JME’s forward renderer.

2 Likes

Well all over the place means I use it for gun muzzles. And directional light for the scenery. This one pass and multipass is some how configured? Is this valid for post filters? Just to understand and to follow the right approach. Like toon filter looks on normal and ligth direction for caculating the intensity. I did that as a post filter but somehow only the „first“ light had an impact. the point light not.

I think it is configured by setting

 renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass); // Use SinglePassAndImageBased for PBR
 renderManager.setSinglePassLightBatchSize(10);
1 Like

Lighting is done before post filters. You probably had something else wrong.

It’s not clear from what you are saying whether the light worked without the filter.

1 Like

Oh. So I probably did it all wrong then. I thought I can do this toon filter as a post filter but if the lighting is done I’m too late. So hmmm do I maybe need a special material definition for that or? I didn’t found a lot of documentation so I fish pretty much in muddy water tho.
My current toon post filter does just reduche the number of possible colors, it looks not too bad but is not really a toon filter I think…

And I know now why the first one had an effect, I put the light direction static inside the shader… stupid me :wink:

Ah true I remember that. Ok that helps.