[SOLVED] I need some help with lighting in my project

I’m really really bad when it comes to lighting. Im trying to get a good even lighting setup using directional lights. It doesn’t need to be even all around. I’m trying to make it a little bright on one side like the sun is in that direction.

https://playcanvas.com/editor/scene/975396

Your directional light added to scene looks fine. Not sure what your question is.

I want all round even lighting. Is there something like world wide ambient lighting?

So no shadows, no shaded faces, everything as an even colour etc? Do you have a reference image to show the effect you are looking for?

Maybe you are looking for ambient lighting?

Yes how do you do that?

There is an ambient setting in the Rendering options of the project settings:
image
image

But using only ambient light will remove all shadows. You probably want to use directional lights. Just place them opposite to each other to cancel out the fade ins/outs.

If you want to remove shadows, you can also disable ‘cast shadows’ on the light(s) too.

This is what happens when I place to directional lights opposite to each other.


I made one brighter than the other to make it look like the sun is in that direction. But the problem is the dark shadow in the middle on both sides. If I add more light sources then it won’t look like it’s coming from the sun, it’ll look uneven. I was asking for ambient lighting because I thought that would fix this. Is there a way to enable ambient lighting programmatically?

Hi @Gamer_Wael,

What @yaustar asked for may help everybody here understand what kind of lighting you are after.

I’m afraid I couldn’t find such a image. But with reference to the screenshot I posted above. Is there a way to get rid of the black shadowy spot in the middle and make the transition more smooth? I’m sorry if I’m not making sense.
I think ambient lighting would fix it. Is there a way to do it programmatically?
To make the cylinder look evenly lit without any sharp dark spots but also without making it so bright that it looks 2d.

What is your current ambient light color?

I don’t have ambient lighting. I’m not using the editor right now. Can you please tell me how to programmatically add ambient lighting? I’m writing the html file on my phone

The GitHub engine examples are pretty good for things like this: http://playcanvas.github.io/#graphics/mesh-decals.html

Specifically: https://github.com/playcanvas/playcanvas.github.io/blob/master/graphics/mesh-decals.html#L39

        app.scene.ambientLight = new pc.Color(0.2, 0.2, 0.2);

https://developer.playcanvas.com/en/api/pc.Scene.html#ambientLight

2 Likes

Thanks. Just what I was looking for. Sorry it took so long.

Hey guys I’m having the same problem.

https://playcanvas.com/editor/scene/1317721

Here is my code:

var Lighting = pc.createScript('lighting');

// initialize code called once per entity
Lighting.prototype.initialize = function() {
    app.scene.ambientLight = new pc.Color(1, 1, 1, 1);
};

// update code called every frame
Lighting.prototype.update = function(dt) {
    app.scene.ambientLight = new pc.Color(1, 1, 1, 1);
};

Hi @Gamer_Wael,

What are you trying to do with that code?

It won’t execute most likely since there is no variable named app, you need to replace that with this:

this.app.scene.ambientLight = new pc.Color(1, 1, 1, 1);

This will set the ambient light of the scene to full white.

You can do the same in your project settings, here, change the ambient color of the scene to white:

image

* @CharlieGeorge

1 Like

Thanks for the advice, @Leonidas but I still can’t get it working with code. It works in the editor with the method you explained but I’m not sure where I’m going wrong with my code.

I read the docs on how to add code and write scripts but there isn’t much detail on it.

I have also added the script to the root of the project under the script component. But now I am not sure how it’s supposed to work alongside the editor settings for ambient lighting in the render section as there is no ‘enable’ or ‘disable’ option.

var Lighting = pc.createScript('lighting');

// update code called every frame
Lighting.prototype.update = function(dt) {
    this.app.scene.ambientLight = new pc.Color(1, 1, 1, 1);
};

Hi @CharlieGeorge,

I’ve added your lighting.js script to the Root entity and it seems to work: