# Light from a disco ball?

**URL:** <https://forum.babylonjs.com/t/light-from-a-disco-ball/24615>\
**Category:** Questions\
**Created:** [October 15, 2021, 11:50pm UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615 "2021-10-15T23:50:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 15, 2021, 11:50pm UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/1 "2021-10-15T23:50:10Z")

</div>

What would be the best way to simulate the light from a disco ball?

In Unity you would use a point light and then give it a “cookie” which I believe is a cubemap that works as a texture filter for the light.

How hard do you think that would be to implement?

**UPDATE**

Eeeek looking at how we bind the stuff for the pointLight, It might be better to extend the materials I need and bind the data for the single light and cubemap.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 16, 2021, 12:29am UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/2 "2021-10-16T00:29:00Z")

</div>

[https://playground.babylonjs.com/#V6JU3U](https://playground.babylonjs.com/#V6JU3U)

think I got it.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 16, 2021, 1:28am UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/3 "2021-10-16T01:28:14Z")

</div>

[https://playground.babylonjs.com/#V6JU3U#2](https://playground.babylonjs.com/#V6JU3U#2)

Now the question is how do I get a shadowMap to contribute to this and obfuscate the “light” from the projected cubemap on the correct meshes.

I have a 0.0 intensity light in the scene at the same position as my shader light so that the normal attributes get bound to the shader for the meshes.

My guess is I need to capture a cubeDepthPass from the lights perspective, then sample that on the fragment check my depth at that position and if its farther then what the sample for the depth Pass says then don’t add any color from the projection?

Sooo the next question (that ill prolly end up self answering anyways) is how do you generate a cubeDepthMap? Time to google ^\_^.

**UPDATE**  
It looks like you can have the shadowMap from the pointlight Generate even if the intensity is 0!  
[https://playground.babylonjs.com/#XDNVAY#9](https://playground.babylonjs.com/#XDNVAY#9)  
Happy days.

[https://playground.babylonjs.com/#V6JU3U#4](https://playground.babylonjs.com/#V6JU3U#4)  
So I got all the way to sampling the light maps texture, but I’m sure this is not correct. How do I get the right mask data?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 18, 2021, 12:56pm UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/4 "2021-10-18T12:56:46Z")

</div>

Adding @nasimiasl who might be able to help with the custom material

---

<div class="post-metadata">

**Author:** ![nasimiasl](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nasimiasl/32/34_2.png) [@nasimiasl](https://forum.babylonjs.com/u/nasimiasl)\
**Post date:** [October 18, 2021, 1:01pm UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/5 "2021-10-18T13:01:18Z")

</div>

hey i will back soon for this thanks @sebavan

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 18, 2021, 4:16pm UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/6 "2021-10-18T16:16:49Z")

</div>

Thank you, yeah I’m just not sure why I can get the shadow stuff to work the way I was expecting. Gonna try to take a look today agian.

I’ve done it before so not sure where my disconnect is this time.

---

<div class="post-metadata">

**Author:** ![nasimiasl](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nasimiasl/32/34_2.png) [@nasimiasl](https://forum.babylonjs.com/u/nasimiasl)\
**Post date:** [October 18, 2021, 8:38pm UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/7 "2021-10-18T20:38:46Z")

</div>

i will start that on shaderbuilder for do it faster then we can convert that 🙂

that is heavy request for FPS i will try make simply as i can

i start with define line calculate  
float Line(vec3 p1,vec3 p2,vec3 p){

```
            vec3 norm = normalize(p2-p1);

            vec3 p3 = p1 + norm*length(p-p1); 

            return pow(1.-max(0., length( (p3-p))) ,1.);               

        }

```

[https://www.babylonjs-playground.com/#I5NJSE#10](https://www.babylonjs-playground.com/#I5NJSE#10)

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 19, 2021, 12:46am UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/8 "2021-10-19T00:46:37Z")

</div>

This is cool, but not really what I am looking for.

I just need to figure out how to get the shadows appearing on the meshes in my example pg and I can take it from there. Definitely appreciate your attempt to help though!

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 19, 2021, 3:47am UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/9 "2021-10-19T03:47:56Z")

</div>

[https://playground.babylonjs.com/#V6JU3U#8](https://playground.babylonjs.com/#V6JU3U#8)

This is what it would look like, but this only works with one shadow system. I essentially need to highjack this so the regular shadow systems can work over the top.

---

<div class="post-metadata">

**Author:** ![nasimiasl](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nasimiasl/32/34_2.png) [@nasimiasl](https://forum.babylonjs.com/u/nasimiasl)\
**Post date:** [October 19, 2021, 6:33am UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/10 "2021-10-19T06:33:35Z")

</div>

i know that need you calculate 3 lines per each face and can detect space behind the face by math but we need very optimized line code

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/0/c09a9e2ecf7c0194ebf95fa27d16ae664cb9d865.png)

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 19, 2021, 2:27pm UTC](https://forum.babylonjs.com/t/light-from-a-disco-ball/24615/11 "2021-10-19T14:27:30Z")

</div>

Naw, I just need to test the position vs the depth of the probe texture and match that up. I think I figured out what I’m doing wrong and will see about fixing it here soon.

I’ll toss the real texture on there and show an example here today if I get a chance. I appreciate your help but think we got it 😉.
