Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using setReplacementShader in Shadow Mapping

Discussion in 'Shaders' started by levelappstudios, Mar 4, 2019.

  1. levelappstudios

    levelappstudios

    Joined:
    Nov 7, 2017
    Posts:
    104
    I'm using a directional light with hard shadows in my game. Problems come with DepthPass.Job and Shadows.RenderJobDir: they are using a lot of batches. I would like to use the same shader for all opaque objects in these two jobs, so Unity could batch a lot of objects in a same draw.

    Is there anyway to use a custom shader for all objects in the depth job of camera and light?

    Thanks in advance.
     
  2. Sh-Shahrabi

    Sh-Shahrabi

    Joined:
    Sep 28, 2018
    Posts:
    56
    As far as I know Unity uses the LightMode Tag on the shader to determine which pass to use for the depth pre pass (it uses the ShadowCaster). Would be nice if there was a RenderWithReplacementShader function on the camera but with LightMode. You could try giving your ShadowCaster pass a custom RenderType, then use Rendering with Replaced Shaders to set a replace shader. Then I would assume that Unity would use the same sahder for all objects which have that RenderType tag in their shadow caster pass. However I still have a hard time believing that would lead them to batch. Seems way too easy. Let us know if you figure out how, I am quite interested to know too.