I’m currently porting over a project from Unreal 3 to Unity 5, for most as a learning exercise. I’ve come to the point where I’m playing with baking light, until now I’ve only been using dynamic light, but it gives very harsh and dark shadows on static objects, so I should really use some GI magic.
That said, a few issues raised and I’m unsure how to solve them.
One is that glass materials cast shadows and I’m wondering if I can somehow tell Unity to not do this. I’m aware I could work around this by extracting the glass-part from a mesh, only leaving the frame to be lightmapped. But I’m mostly wondering if there is some nifty shader trick to let the lightmapper know I don’t want to cast shadows. Mind you my current setup already works like this with dynamic light, just not when baked
Second is how I would go about making shadows not as black (either a lightmap setting or shader trick). In Unreal I can tell the engine a minimum blackness for shadows.This is not the same as ambient light which affects all surfaces! It really only affects shadows.
Third, I’m currently abusing the Ambient color as a Skylight, meaning it lights all surfaces equally, is this a correct thought? I’ve also tried using the Gradient, but I can’t seem to figure out how it works?
I actually figured this one out, and it smells like a bug. When I replaced my glass shader with an Unlit/Transparent and assigned a texture with alpha, baking actually went fine. Played around some more by literally taking a copy of the Unlit/Transparent shader and stripping it until it stopped working. Funnily enough, the lightmapper does not actually take the fragment-shader into consideration when baking a shadow. Because it had no effect when I literally returned just a “fixed4(0,0,0,0)” in there, nothing more. I did notice that as long as I kept a _MainTex in the properties, it would still bake my previously assigned texture.
So, the workaround is both silly and simple: When you have a shader, that does not have a _MainTex property, but you still want it to not cast a shadow, simply add a _MainTex property and assign it a 1x1 white pixel texture (in my case, the A set to 0).
For the dynamic light, make sure the fallback is either Off or using a shader that’s transparent.
I’m considering reporting this issue, because it seems weird its only looking for a texture and not the fragment-shader itself.
I’m on 5.3 beta, so it may be something that changed recently, but it seems to work fine for me? Transparent thing DO produce a little shadow, but it’s proportional to how transparent they are, which is how it should be I think. That’s for direct lighting though. Were you talking about indirect light?
In any case, you could bug report it. In general, the lightmapping doesn’t care about your shaders all that much. It just reads certain properties and makes assumptions for the rest.
From the top of my head, there is no equivalent setting in Unity 5. There are a couple of ways to create colored shadows, but I don’t think any of them also work for baked shadows.
Ambient Light is really environment light (backdrop light?) and is properly cast as GI for static objects. It’s not the traditional “magic” ambient light that would make everything brighter everywhere, at least when you are using lightmapping.
So the only way to make “real” ambient light work is embedding it as part of a shader?
I do have a question about your note in the quote: Does your shader actually have a MainTex property? Because that seems to be the key thing. If you make a transparent shader without it, in the current 5.2 it will cast a full-on shadow.