Particles and lighting

Hey guys,

I have some particles flying about my screen and wish to color them according the to the scene’s lighting.

For instance, a blue point light in one corner would light all the particles over there blue, while particles elsewhere would be white or something.

Is there anyway to do this? I didn’t see the functionality in the Common/MatDefs/Misc/Particle.j3md

The issue with particles, is that lighting does not look good with them.

Particles are essentially billboarded quads, so they just have one normal pointing outwards toward the camera, if they were to be shaded, they would probably look ugly.

You could try this yourself, apply the “Lighting.j3md” material to a particle emitter that has a ParticleType of “Triangles”.

Thanks for the reply Momoko.

I’ve been testing particles and lighting lately and I’ve found an issue. The normals for the lighting calculation always seem to point along the unit Z axis. Even if I use particleEmitter.setFaceNormal()

In the screen shots below, the particles all have their normals pointing along the unit Y axis and we are looking at them from the sky above them. We can see two lights, a red light and a green light. However, we notice that the particles only seem to be lit by one light at a time, by the light that is located to the left of the particles (I believe that’s the positive z-axis…)

This looks odd… I am investigating why the normals are set this way

The screenshots look weird … Perhaps you might want to fix that issue first :slight_smile:

About the normals, they are not set on the particle because it is additional data that has to be updated.

For the lighting calculations to work correctly, the normal has to be set to the inverse view vector

haha yea the screen shots look weird because the of the way the particles are set up. I just made them all extremely huge and stacked for the test… so they don’t look so pretty :slight_smile:

So for lighting should I add a normal buffer to the ParticleTriMesh and update that every tick in the updateParticleData() method? Will the buffer be picked up automatically by the engine and lighting shaders if I set it using setBuffer()?

Yeah that should work

Great thanks! I’ll give a shot and post back new screens if all goes according to plan

Just an update on this.

I did end up implementing normals on all of my particles and the lighting worked as expected. Unfortunately, I didn’t actually want the lighting to work as expected :slight_smile: By having normals, only lights from certain directions lit the particle. This meant if I had a single particle with lights on either side of it, one side would look black and the other colored. Or, if I always pointed the normal towards the camera, a group of particles would all be the same color, even if some were right beside the red light, but the green light was behind the camera. Since the particles are always changing their orientation I ended up with really odd cases.

Anyhow, the solution for me was to write my own particle shader that didn’t take into account normals and I could apply custom lighting to. It turned out nice for me since I also needed to do add spotlights.

Thanks again for your help Momoko