# Odd behavior from directional lights with webgl

**URL:** <https://discourse.processing.org/t/odd-behavior-from-directional-lights-with-webgl/41791>\
**Category:** Coding Questions\
**Created:** [April 22, 2023, 12:08pm UTC](https://discourse.processing.org/t/odd-behavior-from-directional-lights-with-webgl/41791 "2023-04-22T12:08:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluemoon](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@bluemoon](https://discourse.processing.org/u/bluemoon)\
**Post date:** [April 22, 2023, 12:08pm UTC](https://discourse.processing.org/t/odd-behavior-from-directional-lights-with-webgl/41791/1 "2023-04-22T12:08:16Z")

</div>

Hi Folks,

I’m getting what I think is some really weird behavior from directional lights when using webgl. [Here’s the example sketch](https://editor.p5js.org/mbmosher/sketches/63Qs2huvd). What I can’t figure out is:

- Quads appear to reflect light opposite to boxes and other primitive shapes
- Shapes made with beginShape() do not reflect light at all
- No shapes show color when set with ambientMaterial()

What am I missing here? Would appreciate anyone who can set me straight on directional lighting in webgl.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [April 22, 2023, 2:35pm UTC](https://discourse.processing.org/t/odd-behavior-from-directional-lights-with-webgl/41791/2 "2023-04-22T14:35:31Z")

</div>

Hi @bluemoon,

Just a few issues to note

- ambient material only affected by ambient light
- For vertex you need to set the normal vector
- quad needs to have the correct vertex orientation

I would recommend to study the reference for each functions you are using … 🙂

Cheers  
— mnse

https://editor.p5js.org/mnse_forum/full/DewVpWEb-

---

<div class="post-metadata">

**Author:** ![bluemoon](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@bluemoon](https://discourse.processing.org/u/bluemoon)\
**Post date:** [April 22, 2023, 3:23pm UTC](https://discourse.processing.org/t/odd-behavior-from-directional-lights-with-webgl/41791/3 "2023-04-22T15:23:26Z")

</div>

Thank you so much for the response! I thought it might have something to do with normals.

I’ll submit a github issue to update the [reference fro ambientMaterial](https://p5js.org/reference/#/p5/ambientMaterial), which currently states:

> The ambientMaterial() color is the color the object will reflect under **any** lighting.

edit: I double checked the reference for beginShape() as well, and there is no mention of normals, a pity.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [April 22, 2023, 3:51pm UTC](https://discourse.processing.org/t/odd-behavior-from-directional-lights-with-webgl/41791/4 "2023-04-22T15:51:40Z")

</div>

> [@bluemoon](#):
>
> I’ll submit a github issue to update the [reference fro ambientMaterial](https://p5js.org/reference/#/p5/ambientMaterial), which currently states:

Let’s see the outcome. Read the same but the current behavior seems to be different.  
Maybe someone else has ideas regarding …

Cheers  
— mnse
