Light from picture

Hi, i’ve got the cubemap of my ambient constructed thanks to a sphere of photos (i can use the sphere or the cube with 6 faces too).
I’ve set a treshold so i’ve got white pixels over a certain value and black pixels under that.

Is there a way to set a directional light in the area where most of the white pixels are?
I can’t figure out how to chose the area with more white pixels because in the picture there are more than one white pixels zones!

Thanks!

No ideas?

If you’re using it as the ambient source then it should be doing what you want already?

Like and ambient light it’s fine because i can use it as an HDRI, but if i want to see shadows this is not the way. I need to identify where the light source is from the picture and create there the directional ight with the right angle that generate real shadows.

You want an automated way? Can you just set it manually?

For something automated you probably need to do some type of sampling pattern.
Sample the environment map from a bunch of angles. Look for the brightest value from the environment map.
and then make that your light direction.
But if there are more than one region of white you will just have to pick one.

While you probably could do this on gpu. Depending on how often you have to do it, you should just calculate uv and do the pixel lookup on the CPU.

Easiest way: place a camera in the scene. Rotate the camera until it’s looking at the bright area, then use its rotation values on a directional light.