Hello,
I have a scene with thousands of surfaces (photovoltaic modules) and I need to calculate how much (%) of the area of each module has a shadow casted from the other modules that are close or from another object from the scene.
It does not need to be rendered, I just need to know if the module is shaded or not.
Anyone know if there is a way for accessing such information or how to calculate it?
Thanks in advance
Welcome aboard!
I’d put a material that doesn’t write to the color/depth buffer for all objects other than the one for which we want to calculate shadow coverage (let’s call it A), so that they don’t render and occlude A (this is important because of the way we calculate shadow coverage, see below). Note that their shadows would still be rendered!
Next, I’d render the whole scene in an RTT with a top-down view of A, so there’s no distortion from perspective rendering (using an orthographic camera would probably help too, even more so if A isn’t planar).
Finally, I read the texture and count the pixels in/out of shadow.
Here’s a quick proof of concept:
The RTT looks like this:
This is a top-down rendering of the scene. As you can see, the sphere is not rendered, allowing us to see its entire shadow. With the color and light intensity I’ve used, a point not in shadow has the color (147,255,147) and a point in shadow has the color (0,255,0). This makes it easy to calculate shadow coverage (look at the console).
3 Likes
@Evgeni_Popov,
If I change the ground mesh for a plane mesh the calculation stop working and the RTT does not capture the shadow over the plane mesh. Do you know if there is a limitation to that approach only for ground meshes?
It looks like that is not an issue with the plane or ground, but with the angle of the plane. ie. when I rotate the plane to be with pi/4 it goes to 100% and with it on vertical I get NAN
it was the color thresholds. I changed and it is working now. Thanks a lot!
Don’t forget to update the camera position so that the RTT camera is always a top-down view!
I’ve also noticed that, because of the lighting, the non-shadowed pixels aren’t all exactly the same color. So it’s better to count the background colors instead, and do rttSize * rttSize - countBackground
to get the total shadowed + non-shadowed
pixels:
The difference is notable: 13.7% versus 16.7%.
2 Likes