Completely custom shadow pass with standard material

For various reasons I’m exploring my own solution for shadow rendering. There’s quite a bit of information around on doing your own screen-space shadows using the cascades that Unity renders out for you, or putting standard Unity shadows onto your own shaders, but I haven’t been able to find much information on doing a complete overhaul.

As far as I can see there are these options:

1. Write your own shaders.
Obviously gives you the most flexibility.

2. Cut-and-paste then modify the Unity Standard Shader sources
Works fine but it’s a bunch of work to maintain and doesn’t “feel” nice.

3. ???
I guess you could do something weird like trick Unity into doing a shadow pass but not render anything then hijack the SSS texture with your own shaders? Or do something weird like do shadows entirely as a post-effect?

What I would like to do is

  1. render out my own shadow cascades, at the rate of my choosing (e.g. to render distant cascades less frequently)
  2. render my own screen space shadows using a replacement shader (basically like Unity does itself)
  3. press the necessary buttons so that Unity picks up on my screen-space shadow texture–which ought to look identical to the actual forward rendering pass–and use it with the rest of the Standard Material, or any other materials that are set up to query the screen-space shadow texture.

But after quite a bit of research I haven’t figured out how to proceed with step 3.

What am I missing?

(And as a bonus, here are some not terrible looking soft shadows)

Not a pleasant solution, but third step could be achieved if you would just simply change shadow sampling function to sample your own shadow textures (This way u could have complete control on it). This can be done by changing our built-in shaders.

Any way, the best way this could be achieved with our new feature called “Scriptable render loops” (Some info https://docs.unity3d.com/Manual/ScriptableRenderPipeline.html), this way you could simply take our froward render loop implementation and modify the shadow calculation step. However the catch is that this feature is currently experimental.

Thanks for the reply. I didn’t realize Scriptable Render Loops were available to experiment with. I had a chance to read through the documentation early on and have been greatly anticipating it. I’ll have to check it out! What’s the earliest version of Unity that’s available with?

Are there plans to make the Standard Shader more modular alongside this effort?

There’s early functionality with 5.6 beta 1, but don’t expect anything in the manual to line up as I think it changed a bunch between that and 2017.1.

1 Like