3
\$\begingroup\$

I'm currently learning how to use OpenGl, and I'm following a tutorial on learnOpenGL. I'm at the lightning chapter, and it has introduced basic lightning, ambient and diffuse with specular highlight. Phong shading essentially.

I'm confused about the ambient term. I understand that the ambient light is basically a light that comes from nowhere in particular, and it just fills the scene you're in with a soft light. And it's used to fake Global Illumination in renderers that do not compute it, so that the stuff that's not in the direct view of a light source is not completely black but it has some generic lightning on it.

So going by the definition, before actually trying to implement a renderer myself, and by using other engines like UE4, I always just assumed that ambient light would be a separate thing from say a point light or a directional light. I thought it would be a parameter independent of other stuff that would basically just light the scene.

But in the tutorial, at least for the basic lightning part, the ambient is actually part of the light "object" itself. Essentially every light source has its own ambient light.

This seems counterintuitive to me. Why does every light need an ambient part too? Wouldn't make more sense to have a "separate" ambient light object that provides the ambient light itself?

Also, if my light has a radius of say 100 units, then outside of that radius nothing will receive any direct light, obviously, but also no ambient and will be completely dark. Isn't the point of ambient light exactly not to have scenes without direct light go completely dark?

Most importantly I'm wondering if this implementation approach is the standard used in modern game engines, or if it's maybe a simplification in the tutorial. (For example I don't remember seeing a parameter for ambient light in the light objects themselves in UE4)

Links for context: https://learnopengl.com/Lighting/Basic-Lighting https://learnopengl.com/Lighting/Light-casters

\$\endgroup\$
1
  • \$\begingroup\$ Ambient term is not physically accurate: it's a hack to crudely simulate indirect illumination \$\endgroup\$
    – Ocelot
    Commented Oct 29, 2020 at 0:10

1 Answer 1

2
\$\begingroup\$

But in the tutorial, at least for the basic lightning part, the ambient is actually part of the light "object" itself. Essentially every light source has its own ambient light

If you consider ambient lighting to be global, then this is not the case. The global ambient term is essentially an extra light source that's independent of direction, that's added to the lighting calculation for every object (not for every light).

E.g., if you had multiple lights, it would be (pseudocode):

vec3 result = (ambient + diffuse1 + diffuse2 + ... + diffuseN) * objectColor;

Now, since ambient lighting can be colored, you need to specify a color for it too, not just a multiplier (e.g., in daylight, you might want it to have a sky-blue color, in a night scene that cinematic night-blue, in a lava-filled chamber you may want it to be orange-red, etc.)

I didn't read the tutorial very carefully, but I think they are using a single light source, and the color of that light is reused as the ambient color.

Now, you don't have to have only the global ambient illumination. Suppose you are in a room that's lit by two differently colored lights - in reality the light bounces off of the walls, so you'll have some global illumination coming from the surroundings that smoothly changes color depending on the direction. Or imagine a scene where you start outside, at night on the slope of a volcano (blue ambient color), and the enter a lava-filled cave (orange-red ambient color).

You can simulate this by adding a per-light ambient term that's attenuated with distance (and placing the light sources at appropriate locations). If you add an independent per-light multiplier for it, then you can have lights that only produce direct lighting, only ambient lighting, or both.

But that's not necessarily always done. You can do other things, e.g., you can change the global ambient color as you transition areas (but then, if you can still see the objects outside, they'll have wrong ambient lighting). You can have regions (boxes) that define ambient lighting within them, and somehow send location-specific ambient color to the shader. But then you'll have sharp jumps when object transition from one area to the next, unless you find a way to smooth that out over a couple of frames, or based on distance, or something like that. So, you know, tradeoffs.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .