Search Unity

Surface Shaders - addShadows directive, is it efficient?

Discussion in 'Shaders' started by Noisecrime, Jul 22, 2014.

  1. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Hi,

    Been working on some surface shaders that modify the input vertices (unity 4.3.4) and figured I'd try the addShadow directive to see if it would work and thus save me time writing custom shadow passes.

    It works great, but while looking through the compiled code it seems, in opengl at least, that the shader simply re-uses your vertex function. That's understandable, but of course if you modify the normals and tangents then that code gets dumped in as well which is obviously in-efficient.

    I guess there might be the possibility that the code is further optimised and strips out stuff since the normals and tangents aren't actually used in the fragment/pixel shader, but that sounds like a bit of a stretch. Its also a bit odd as you'd think Unity is in a far better position to strip out the code since when generating 'addShadow' passes it should know that only the vertex data is of use.

    Just wondering before I dig any deeper into this if anyone else has come across it or done any research into it.

    Cheers