(Shaderlab) Are shadowcaster passes with shadow map depth write and semi-transparency possible ?

As title says : is it possible to do in single transparency subshader in shaderlab with two shadowcaster passes :

  • one for writing depth and discarding pass outside shadow area (i already have a working example)
  • one for writing semitransparency via _DitherMaskLOD with discard/clamp

NOTES:

  • i know using discard/clamp precludes writing to depth when inside area covered by a mesh. that’s why i suggested use of two shadow caster passes
  • i’m aware that trying to use two potentially opposing approaches to casting shadows may be a paradox
  • i’m trying to implement this with raymarcher

I still haven’t made a working example of semi-transparent shadow casting.

One more for @bgolus when you can spare the time :slight_smile:

You cannot have two shadowcaster passes.

Well, you can, but the second one will be ignored and only the first pass will ever be used.

If you want different behaviors for different use use cases (camera depth vs. shadow map depth) then you have to detect which is currently being rendered and change the output.

This method is still the only one I’ve found to work consistently, and it only works if you don’t set your shadow bias to zero.

if (unity_LightShadowBias.z)
{
  // do shadow caster specific code
}
else
{
  // do camera depth specific code
}

This is actually what Unity’s own shader code does.

The minor modification to that mentioned here is also good if you want to support point light shadows as those disable normal bias (what’s stored in the unity_LightShadowBias.z) and exclusively use unity_LightShadowBias.x (which is depth bias).

if (any(unity_LightShadowBias) == false)
{
  // do shadow caster specific code
}
else
{
  // do camera depth specific code
}

But both will break if you set the biases to zero. There were other methods that were 100% consistent, but Unity has broken those all (as mentioned in the first post I linked).

1 Like

Thank you for exhaustive reply.
When i think some more, shadow dithering looks very much what opaque cutout shader does - both do discard/clip. Its just dithered shadows do it at the level of single texels. Sigh … Again, thanks !