# Fake directional light from environment.dds?

**URL:** <https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550>\
**Category:** Questions\
**Tags:** lighting\
**Created:** [May 4, 2021, 11:10am UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550 "2021-05-04T11:10:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSa](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@JSa](https://forum.babylonjs.com/u/JSa)\
**Post date:** [May 4, 2021, 11:10am UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550/1 "2021-05-04T11:10:30Z")

</div>

Hi! I am wondering how would one create a fake sunlight directional light from the most luminous highlight of .dds envinment texture used in IBL lighting? I am happy with the IBL results but would need the “fake” sunlight with shadows as well to the scene.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [May 4, 2021, 12:00pm UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550/2 "2021-05-04T12:00:54Z")

</div>

Here is the example - [https://playground.babylonjs.com/#SYQW69#832](https://playground.babylonjs.com/#SYQW69#832)  
You may need to tune the position and direction of your light to correspond with the most luminous area (and/or tune dds texture rotationY value).

---

<div class="post-metadata">

**Author:** ![JSa](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@JSa](https://forum.babylonjs.com/u/JSa)\
**Post date:** [May 4, 2021, 12:17pm UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550/3 "2021-05-04T12:17:07Z")

</div>

Thanks! This gives a good direction for the solution… Btw. now when testing the animating light I started getting interested in calculating the light position based on time and gps-location…

---

<div class="post-metadata">

**Author:** ![JSa](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@JSa](https://forum.babylonjs.com/u/JSa)\
**Post date:** [May 4, 2021, 12:17pm UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550/4 "2021-05-04T12:17:49Z")

</div>

Still what I am also kind of missing, is if there is a way to read the env map somehow to get the most luminous spot automatically?

---

<div class="post-metadata">

**Author:** ![JSa](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@JSa](https://forum.babylonjs.com/u/JSa)\
**Post date:** [May 4, 2021, 12:20pm UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550/5 "2021-05-04T12:20:32Z")

</div>

Have to try this at some point 😉

> **[mourner/suncalc](https://github.com/mourner/suncalc)**
>
> A tiny JavaScript library for calculating sun/moon positions and phases.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [May 4, 2021, 12:34pm UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550/6 "2021-05-04T12:34:24Z")

</div>

In order to find most the luminous spot of the texture you may try to use `readPixels` [Texture | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/babylon.texture#readpixels)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 4, 2021, 1:34pm UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550/7 "2021-05-04T13:34:14Z")

</div>

There’s currently no tool that would compute the direction of max light in an environment map. That’s something that you will have to write yourself.

---

<div class="post-metadata">

**Author:** ![JSa](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@JSa](https://forum.babylonjs.com/u/JSa)\
**Post date:** [May 5, 2021, 6:32am UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550/8 "2021-05-05T06:32:02Z")

</div>

This post was finally very helpfull here, its what I ended up doing for now:

> **[Any tips on how to align lens flare with sun from skybox texture ?](https://www.html5gamedevs.com/topic/41727-any-tips-on-how-to-align-lens-flare-with-sun-from-skybox-texture/)**
>
> Hi, I am struggling to properly align a lens flare with the sun from the skybox texture so I was wondering if anyone would have any tips on doing it properly as in the lens flare demo? -\> https://playground.babylonjs.com/#QP32DP#1

Boils down to something very simple:

> scene.onPointerDown = function(evt, pickInfo) {  
> console.log(pickInfo.pickedPoint)  
> }

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [May 31, 2021, 4:55pm UTC](https://forum.babylonjs.com/t/fake-directional-light-from-environment-dds/20550/9 "2021-05-31T16:55:49Z")

</div>

> [@JSa](#):
>
> Still what I am also kind of missing, is if there is a way to read the env map somehow to get the most luminous spot automatically?

There is a lot of extremely interesting reading about this here - [Path-tracing in BabylonJS - #100 by erichlof](https://forum.babylonjs.com/t/path-tracing-in-babylonjs/11475/100)
