Search Unity

shader_feature / multi_compile resource usage

Discussion in 'Shaders' started by tessellation, Mar 24, 2017.

  1. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    I've written an uber shader that has enough combinations of keywords that together there could be as many as 100 variations. I've seen forum threads with developers complaining about shader variants taking up tons of memory. Most of the combinations I know will never be used (I only use 11 combinations). Because I enable and disable the keywords at runtime from script, I can't use shader_feature, I have to use multi_compile.

    My question is, does multi_compile in fact consume a lot of resources or are the shader variants only created when they are used by the renderer? I assume it must consume resources because otherwise the "shader_feature" command wouldn't have been necessary.

    I have all 11 shader variants in a .shadervariants asset, but if I switch the shader to use shader_feature instead of multi_compile, the variants I need do not make it into the final build. I assume this is because there have to be material assets with those keyword variations set in order for the build process to include those shaders.

    Right now it seems like I'm going to have to write an editor script to create my 11 shader variants as material assets in order to fix this. Is there a better way?

    Thanks for the advise...
     
  2. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    just going to bump this since it was posted late on Friday...