Light position in HDR

If you want to create a directional light, finding the sun position won’t help you as what you need is a direction. So you would need an additional point to create a direction, and I don’t really see what point you could choose based only on the environment picture, except maybe (0,0,0)…

Anyway, what you would need is a transformation from a 2D coordinate of the equirectangular HDRI texture to a 3D coordinate in the cube in which the texture is mapped to.

Must be doable, but pretending the HDRI texture is projected onto a sphere instead of a cube is easier:

I think you can reuse the computation from this PG to convert a 2D coordinate from your HDRI picture to a 3D coordinate. The radius (rho) value is not relevant here as it will produce the same direction whatever the value you choose (if second point for direction is (0,0,0)), so using 1 is ok. The final 3D coordinate you get in the end is your direction (after normalizing) if you choose (0,0,0) as the second point to construct your vector.

1 Like