I’m working on a planet renderer and have a problem where objects occluded by a planet are still being lit by the sun (directional light). This is due to the bright side of the planet being manually frustum-culled, thus allowing all objects in the dark side receive light from below.
I’m not sure how to go about this.
I could just skip the frustum cull step and draw everything being culled with a reduced geometry and simplified shader, but that will eat some precious FPS anyway.
Any ideas or help would be much appreaciated.
Assuming this is using shadowmapping, the easy solution would be to alter your culling solution to switch the renderer’s draw mode to shadows only rather than just disabling the renderer. If for some reason you need to cull the renderers entirely, then your other alternative would be to account for planetary occlusion manually;
One way would be to use command buffers and inject a sphere directly into the shadowmap itself, however with the combination of cascades and Unity’s auto shadowmap rescaling this is actually a lot harder than it needs to be. The other way would be to have spherical occlusion in the object shader on top of regular shadowmapping, however this will make your shaders more complex which isn’t necessarily ideal in a forward renderer, especially if you are already tight on performance.
However, knowing what we do about Unity (afaik Unity will always use deferred shadows for directional lights) we can actually combine the two; use a command buffer to inject into the screenspace-shadow pass of the directional light and sample the planet’s occlusion using re-constructed positions from the depth texture. This would automatically work for any object without shader modifications and only requires the dimensions of that draw (in most cases, the screen’s resolution).