How does Lights radius work?

Hello,

I’m trying to implement a day/night cycle on the game i’m working on, and i’m a little confuse about point lights radius.
How does they work ?

Because when i’m adding a point and i set its radius to 150, on screen the light circle has a diameter of 230px. And when i set it to 75, it disappears.
If it is not a pixel parameter, it is not proportional, what it is bind to ?
Is it bind to the intensity (In my case set to 10) ? The coordinates ? The screen size ?

Thank you by advance.

1 Like

You’re right, it’s hard to tell exactly what the radius is. It’s always a bit bigger than the visible radius.

I think you need to use a minimum radius 80.

Hi,
It seems there is an attenuation after the radius, if we look at the shader file:

float attenuation = clamp(1.0 - distToSurf * distToSurf / (radius * radius), 0.0, 1.0);

But i’m not a shader expert, and i have to admit i don’t understand this light shader…

After many try, I think that it depends of the canvas size, the more it’s big, the more the minimal size increase.

@BlunT76 What do you think “distToSurf” is? I think it is the key to understand how it works.

uniform vec4 uCamera; // x, y, rotation, zoom
float distToSurf = length(lightDir) * uCamera.w;

It seems to be the length between the light and the camera view, but i don’t know what uCamera.w is…
Too much complicated for me xD
I use a lot the Lights in my games, but i just find the good values by try and errors.
And you need to know that the Lights will be deprecated on next Phaser version…sadly :frowning:

Camera.w is certainly the camera width, so as I said the radius is certainly directly bind to the canvas size. It would be better if everything worked the same way, maybe it is the reason why it will be deprecated.
I hope it is for a rework :sweat_smile:

Anyway I will search for an alternative, mask is a good one I think

But for a given game size, light radius will be consistent throughout. Won’t that work?

The game canvas always fill the page, so to keep the same scale i apply a ratio to every objects (Position and size).

When i resize the page, every objects change their width and height to have the good size, except lights which have weird changements.
I made an example:
https://jsfiddle.net/ZauChoco/7uxoag48

Try to resize the result page on the width, the light radius scale change oddly compared to the base image. (With this edit layout if possible: edlay )

I hope that what I say is understandable :smile:

Perhaps your problem comes from handling the ratio manually, phaser has scale features and take care of all game objects size automatically.

1 Like

Thank you, it works :smile:
Yet I had already tried, maybe with an error i didn’t see.