[SOLVED] Light only affects front side of Geometry?

Hello dear community,

I randomly noticed that my flashlight (a Spotlight) only affects the front sides of geometries. The back sides are basically just ignored. Of course this only can be noticed with geometries whose face cull mode is set to off.

Here is an example of a simple bush geometry (common Lighting material).

The front side with enabled flashlight (works as it should)

The front side with disabled flashlight (works as it should)

The back side with enabled flashlight (does not work as it should)

The back side with disabled flashlight (works as it should ^^)

So you actually can not see a difference between the last two pictures. I would like the back side to be affected by my flashlight as the front side does.

Does anybody know how to solve this problem?

Best regards
Domenic

Are the leaves made from planes?

Edit: just in case they are maybe this will help.

https://www.katsbits.com/tutorials/blender/double-sided-faces-different-materials.php

Double-sided lighting is only supported in single-pass mode. It is not possible to implement double-sided lighting in the multi-pass so its not supported there.

1 Like

If the leaf has two sides, as in the second link I posted where they duplicate and flip the object, would that work?

@mitm yes it is just one plane. I am not sure if that would work. And in the case it does, I would have to modify almost every model I have in blender which means a lot of work too… Maybe there is another solution…

@Momoko_Fan is it possible to implement this in multi-pass? Or what else should I do in this case?

Okay, I got the issue solved by using Single-pass mode as @Momoko_Fan suggested.
Is there anything that I need to know / consider when using single pass mode?

Here is the code to enable single pass

app.getRenderManager().setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
app.getRenderManager().setSinglePassLightBatchSize(3); // 3 is a good value for my scene

Thanks again for any help :slightly_smiling_face:

1 Like

Just a detail: the light batch size is the number of light handled by each light pass.

  • The number of lights is actually the number of lights affecting the geom being rendered (not the number of light in the scene). This number is computed for each geom. That’s our light culling system.
  • If the batch size is 3, 3 lights will be handled in the shader, even if there is only one light affecting the geom (to avoid dynamic loops in shader that kills the perf, it’s often better to make a fixed number of iterations even if some of them are for naught)
  • If the batch size is 3 but 4 lights affects a geometry, the geometry will be rendered twice (once for the 3 first lights once for the last one).
3 Likes

Alright, thanks for explaining this :+1: :slightly_smiling_face:

Hi there, I hope you can help me. I have just started using JME to convert our CAD engine from Java3D. I am also having trouble using double sided lighting. I’ve tried setting the lightmode to singlepass but the back of my triangle faces are still black. Is there any other setting that needs to be specified (maybe on the material) to activate the double sided lighting as I expect it won’t enable by default?

Hmm… I don’t know to be honest. Did you set FaceCullMode to off? Maybe try it with another batch light size.

99% sure that standard JME lighting is single-sided… so you’d have to fork the shader and reverse the normals for the back sides (that’s why those sides are dark because the normals are facing away).

Or you could duplicate your mesh and flip the normals that way. It’s not really that much more processing since both of those meshes would be single sided. The benefit to this approach is that it’s all Java programming if you don’t know shader programming well already. (Though shader programming is tons of fun… it’s fun in the ‘when I stop banging my head against the wall, it feels great’ sort of way. :slight_smile: )

1 Like

So is there any downside to setting single pass mode with just one light per batch?

well… yes there is, you’ll have more probability to hit the case where it needs to perform an additional render pass for the geometry.
But that can never happen depending on your scene.

@Domenic - Yes FaceCullMode is set to off. I had a look at SPLighting.frag and it appears normals should be flipped when in SinglePass mode.

@pspeed - I understand I can duplicate the mesh and flip the normals. However, I would like to avoid that if possible. Our software is used in the mining industry to visualise mine layouts and earthquakes (each earthquake is a sphere). So our 3D scene can become very populated, especially if a user has 10000 spheres as well as showing his entire mine layout.

In my case I have a single light source (DirectionalLight) that is always behind the camera. This works well for lighting up spheres as with our experience in Java3D. I have read other posts where the double-sided face issue was solved by enabling SinglePass mode, but I cannot seem to get it working. Any help would be appreciated.

This is the part where I say: “Your code looks fine from here.” wink-wink, nudge-nudge.

:slight_smile: I ended up resolving the issue by copying Lighting.j3md and SPLighting.vert files and adding the following entry to SPLighting.vert:

wvNormal = -faceforward(wvNormal, viewDir, wvNormal);

This solved the problem for me. Thanks guys for your help.

2 Likes