Jump to content
Sign in to follow this  
spooky

Sky Portals in Unity?

Recommended Posts

Hello, this is something I've posted around a few places, and I finally decided to bring it to ProCore, since the relevant tool here is ProBuilder.

 

I'm building Quake-like interior maps using ProBuilder, and for efficiency and ease of editing I'm using using one-sided geometry. Previously back-faces would cast shadows, but this seems to have changed in Unity 5. Shadows can be 'fixed' by setting Cast Shadows on the mesh renderer to 'Double Sided', but I'm not happy with that solution. It's inconvenient, since the default setting on ProBuilder objects is 'On' and there would be a lot of effort to fix the settings. I also suspect that rendering double-sided shadows may not be very efficient - perhaps why it's no longer the default mode in Unity? The other solution would be to build an elaborate shadow-casting shell, but while it's probably a little more efficient, it's still incredibly inconvenient.

 

 

Ideally we would have more control over directional lights. For being a supposedly general purpose engine, Unity seems to be moving toward rendering exterior scenes as the default mode with the default skybox in Unity 5. In the Source Engine and the Mental Ray render there is a feature called a "Sky Portal" which masks light from the directional light to a polygon or quad. If it were possible to recreate this in Unity it would probably be a much better solution. With sky portals the light could be masked to windows and other apertures into the 'outside'; you would choose what light you do want rather than what light you don't want.

 

I didn't post this in feature request, because although it's relevant to ProBuilder's claim to enabling BSP style construction (sky portal is a feature of many BSP engines) lighting seems a little orthogonal to existing ProBuilder features, but I'd like to know if anyone has any idea how you'd implement this.

 

I had an idea of how a sky portal might work but I don't know enough about shaders or how rendering to implement it. Basically you would mask the light down to the sky portal. If the shadow map of the directional light could be 'flipped' so that by default the entire directional light is shadowed rather than revealed, then a sky portal object would then have a special shader (or something?) which causes it to cast an 'anti-shadow' which would then be shadowed normally by the objects in the scene, and this would create the same effect of getting directional light only where you want it. It might incidentally give you a hack solution for real-time area lights, since if the directional light was perpendicular to the portal you'd get a nice quad of light.

Share this post


Link to post
Share on other sites

 

I'm building Quake-like interior maps using ProBuilder, and for efficiency and ease of editing I'm using using one-sided geometry. Previously back-faces would cast shadows, but this seems to have changed in Unity 5. Shadows can be 'fixed' by setting Cast Shadows on the mesh renderer to 'Double Sided', but I'm not happy with that solution. It's inconvenient, since the default setting on ProBuilder objects is 'On' and there would be a lot of effort to fix the settings. I also suspect that rendering double-sided shadows may not be very efficient - perhaps why it's no longer the default mode in Unity? The other solution would be to build an elaborate shadow-casting shell, but while it's probably a little more efficient, it's still incredibly inconvenient.
 
It would be pretty easy to write an editor script to toggle on backface shadows in batch mode.  You could always do that and save some time manually changing all those values.  As far as efficiency goes, I can't imagine it would be that much more intensive than culling back faces in the shadow calculations.  I'd suggest testing that theory before looking for alternate methods.
 

 

Ideally we would have more control over directional lights. For being a supposedly general purpose engine, Unity seems to be moving toward rendering exterior scenes as the default mode with the default skybox in Unity 5. In the Source Engine and the Mental Ray render there is a feature called a "Sky Portal" which masks light from the directional light to a polygon or quad. If it were possible to recreate this in Unity it would probably be a much better solution. With sky portals the light could be masked to windows and other apertures into the 'outside'; you would choose what light you do want rather than what light you don't want.
 
Assuming your intention is to create an indoor scene with god-rays providing lighting through skylights and windows, I think the best course of action would be to model a lightblocking volume around the shell of your interior geometry.  On the sky portal thought, I think you're describing Area lights?
 

 

I didn't post this in feature request, because although it's relevant to ProBuilder's claim to enabling BSP style construction (sky portal is a feature of many BSP engines) lighting seems a little orthogonal to existing ProBuilder features, but I'd like to know if anyone has any idea how you'd implement this.
 
Lighting is a bit out of our scope, yes :)  On the thought of implementation, I'd suggest looking into area lights, and following that you'd probably be looking at writing your own lighting pipeline.
 

 

I had an idea of how a sky portal might work but I don't know enough about shaders or how rendering to implement it. Basically you would mask the light down to the sky portal. If the shadow map of the directional light could be 'flipped' so that by default the entire directional light is shadowed rather than revealed, then a sky portal object would then have a special shader (or something?) which causes it to cast an 'anti-shadow' which would then be shadowed normally by the objects in the scene, and this would create the same effect of getting directional light only where you want it. It might incidentally give you a hack solution for real-time area lights, since if the directional light was perpendicular to the portal you'd get a nice quad of light.
 
That's an interesting thought - it would be pretty easy to invert the directional light in a fragment shader, and Unity does provide the source code to the built-in shaders.  You could also do what you suggested and invert the lightmap textures (by first baking only directional lights set to 'Baked'), then baking other light sources and blending the latter over the inverted directional atlas.  This would require a lot of legwork, or a custom baking script to automate that process.  I think just inverting directional lighting in the fragment shader would probably be easier though (at the cost of mucking around in Unity's shaders).

Share this post


Link to post
Share on other sites

Thanks for the suggestions! I'll probably just stick with building shells. It's tedious but it's probably the most efficient. I'll just have to do a test of shells vs. double-sided shadows when I'm done with the construction.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×