PointLight & PBRMaterial, large area of light vs intensity at origin

Hey team, any light experts around? :slight_smile:

I’m trying to increase the area of good intensity light from a PointLight on PBRMaterials
while not creating a burning bright sun in the center…

the light is attached to a mesh in my project, and must be emitted from the mesh, so it can’t be moved upwards.
(PG 1, Bright center spot)

I can clamp it in the shader, but i’d rather not overwrite it and also better performance if this can be avoided.
(PG 2, Roughly how it should look)

Not sure if I’m a light expert :grin: but I can give you a trick I sometimes use.
But for a start the light should be set higher so it can cover more surface and diffuse better.
I’m not sure I understand the part that says:

Can’t you just parent it?
Next on a PBR material that does not take much of the specular, I tend to use directIntensity.

Then another thing I often do is clone the env texture and change the env level. But here you don’t use an env.

Edit: Oops, just realized you said “more light” :face_with_hand_over_mouth:. So, yes to get more light, increase the directIntensity in the PG to a level of 2 or above. It will give more light without the burning effect (that comes from where the light directly hits the surface).

Hiya @mawa Thanks for taking a look!

Can’t you just parent it?

No, the light is already parented to a mesh within my project, and must be emitted from that mesh position :smiley:

If i move the light upwards on the Y axis compared to the mesh, if anything comes between the mesh and the light, it would be lit up from above rather than below.

The light (or rather the mesh it’s attached to) can also be mounted on a wall, so there would be a bright spot of sun on the wall too, and the light origin would not match the mesh position on the wall.

i’m not sure about directIntensity, it seems more like a per-material-intensity option, but i need to keep the size of the light area (range & radius), aswell as the falloff area, while only removing the super bright center spot.

Updated original post to be clearer :slight_smile:

Looks more tricky than I thought it was. If you cannot act neither on the material nor on the position or range of the light :thinking: May be with the angle but it wouldn’t work with a point light. Fact is where the light hits directly it will create a bright spot. I don’t see how this could work through the light. May be through the shader? ask a real expert :wink: @Evgeni_Popov @PatrickRyan

It’s a tough one!
i would be totally fine with the center spot still being there if i can just get it smaller and less bright (maybe down to 25% of what it is now), but i need to keep the light area and falloff roughly the size they are in the PG, all the other settings i’ve tried just doesn’t give the proper area & falloff i’m looking for.

I editted the shader in the 2’nd pg, but this is what i’m trying to avoid :smiley:

1 Like

I guess you would need area lights for that, but it is not supported (yet) in Babylon.js…

You could try to simulate it by using multiple light sources with reduced intensity, but performance will suffer quickly… Maybe @PatrickRyan will have a magic solution to this problem!


@aWeirdo, there are potentially a couple of solves to your problem depending on what your constraints are.

The first would be useful if your point light isn’t illuminating meshes to the sides or above it. Your sample shows the point light over a ground plane only. If this is indeed your use case, I would change your point light to a directional light pointed at the ground mesh. This will even out the light and create no hot spot. But the trick to making it look like a point light with falloff would be using a projection texture with the directional light to simulate the falloff. This would be a simple radial gradient from white to black. This allows you to control the shape of the falloff with what is in essence a Gobo added to your light. This is the best way to simulate an area light under our current lighting system as an area light is a light shape that emits parallel light rays. Using this projection method allows you to simulate the shape and parallel rays. The only limitation is falloff, but there may be a few tricks for that as well.

If you do need to light both a ground plane and meshes to the sides and above the point light, you can also fake the lighting by controlling the illumination with multiple lights. You can use the directional with projection texture to illuminate the ground plane and the point light to illuminate other meshes around it with intensities that don’t blow out any of the materials. You would then take advantage of light culling in the engine to control which meshes are illuminated by each light. This can help you simulate the light quality you want with maximum flexibility.

The second solution would be to address your concerns about a custom shader and optimizing performance. If you use custom shader code like in your sample PG, you will indeed be responsible for the optimization of the shader yourself. However, if you use a node material, you are simply putting together blocks to suggest the format of the shader. The node material class itself was created to replace those blocks with optimized shader code. The engineers who wrote our base shaders also created the node material class, so the optimization of that system should be on par with any of our base shaders. Now, you could end up with some heavy shaders if you wire together heavy blocks or do extra operations that aren’t needed. But for what you are suggesting - taking our standard PBRMaterial and creating a clamp for the diffuse and specular contributions - you are going to be mainly using our standard PBR blocks and a couple of post lighting calculations, so it should be really optimized anyway.

I hope this helps give you some ideas for a solution, but feel free to ping back with more questions.


Thanks for the pointers!
I do indeed need it to emit light in all directions.

Learning node materials, creating & updating every material in my project would be quite a large undertaking.
Using multiple lights for every PointLight source/placement, would be too demanding when it comes to performance i believe.

I suppose it leads back to using a custom light shader as the best option in this scenario.

@PatrickRyan Do you know if it’s possible to set/change which shader a specific light class use?
I looked through some of the code a few weeks back, but i found it very convoluted, assumably for caching/optimization reasons.

I think having a custom light shader specificly for this would give the best result and i won’t need to duplicate the shaders all the other lights use, i could also skip some checks (light type, intensity type, falloff type etc) and just run the light calculations directly.
All PointLights will need this same behavior and it’s the only use of PointLights in my entire project.

The shader code used to compute lighting depending on the type of the light is in:

Babylon.js/lightsFragmentFunctions.fx at master · BabylonJS/Babylon.js · GitHub.

The function that handles point and directional lights is computeLighting, and the point light case is when lightData.w == 0.

If you change this code and want it to be used by Babylon, you should update BABYLON.ShaderStore.IncludesShadersStore["lightsFragmentFunctions"].


I was hoping there was an option to say pointLight use customLightShaderFile.fx etc and i would be able to leave default shaders completely alone, but i suppose not

Unfortunately no, the light code is in the file I pointed above.


Thanks all for the help :slight_smile:

1 Like

There is more than just point light. I did one with a spot. I also added a hemi for the wider area, but I assume you could use an environment on low intensity, since you are using PBR.

I believe he knows that. In fact, tried my luck already :shushing_face: but it looks like the constaints here are just very specific.
I’m actually wondering what it is just exactly? Hopefully @aWeirdo you will share it with us once it’s done. You really teased me on this one and I wonder what this is (will be) :thinking:

It’s literally just a PointLight for my Torch mesh :smiley:
I needed more range on the light, while still having a steep cutoff to black and without a huge shine area at the origin, i was hoping there existed some kind of solution / combination of light settings where i didn’t have to overwrite the default light shaders

I just have to get better at describing the conditions in the original post when it’s a rather complex scenario with very specific conditions :sweat_smile:

Here’s the results so far, i kinda liked the slight shine idea, and the original diffuse clamp PG was a bit darker in the clamped center.
From left to right:

not super visible in a small picture, but notisable in a full sized render, but it’s nothing fancy :slight_smile:


Funny because if the light is emitted from a torch, I actually would have done it with a spotlight. Unless of course, the torch is the kind of torch that casts light in all directions, is it?
But then, the result still looks good from this screenshot above.