Matching Light to HDR

I am using a HDR for the scene background and environment. I also have a directional light in my scene to create shadows.

Assuming the directional light always points towards 0,0,0 and is an arbitrary distance away, is there an easy way to get the location of the light such that it matches the HDR? This way the shadows will match.

Do people just do this by eye? It doesn’t have to be very accurate, but I potentially have a few scenes to do each using different HDRs, so if there is a neat way of doing it it could save me a lot of time.

Do you have to use real-time shadows, because of the animations or other reasons?
If not, you could use the lightMap

Thanks for the response, but I don’t think I can use them as the model viewed may change, and may animate.

Thanks for the information though.

If offline calculation is allowed, you could try with this (python) or even implement any of both SPA or IBS methods.

If it should be done on init, you can grab your head around and look for rgb peaks, just like Devedec’s median cut.

Jaume Sanchez did exactly this around 2013 (feeling old just by writing this down), you should found a live example on his twitter account (or timeback machine?)

Good look!

I used my lazy eye, and the 3d space within my brain to make sense of what x,y,z might mean, and in fact, I didn’t even try.
I never even thought about how badly I got it wrong until this question was raised.

ibstaclecourse

If you think it’s going to make all the difference, then you can fork it and make it better : GitHub - Sean-Bradley/React-Three-Fiber-Boilerplate at obstacleCourse

Thanks for all the info @Antonio & @seanwasere ! There’s certainly a lot to take in.

I was just going to create a sphere that is super shiny, put the hdr as the reflection then raycast to it where the light is to get the position on the sphere. I could then just extrapolate that to to bounding sphere of my scene to get the lights position. Sound like I am completely underthinking it though!

Perhaps I misunderstood your original question. Are you wanting a dynamic HDRI that changes when you move your sun object around?

See this thread about LightFormers