Search Unity

Shader keywords and #pragma

Discussion in 'Shaders' started by hausmaus, Jan 28, 2017.

  1. hausmaus

    hausmaus

    Joined:
    Dec 9, 2011
    Posts:
    105
    Is there a way to get preprocessor lines to control which #pragma lines are used? I'm trying to use #pragma_multi_compile keywords and it seems that the associated #if blocks are ignored where #pragma statements are concerned.

    I'm trying to collapse some blend and tessellation shaders for easier updates, but it seems like neither the properties block nor the #pragma lines respect the keyword preprocessor tests. This makes sense, but I wondered if there was a magical way of achieving this or a similar effect some other way. The main issue right now is that the tessellation feature requires a single-parameter vertex shader, while the normal surface shader workflow requires two, so the signature conflict prevents using a single line like "#pragma surface surf Standard vertex:vert tessellate:tessEdge nolightmap addshadow" and the preprocessor doesn't help.

    Any insight would be appreciated!
    Adrian
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Unfortunately no. Your best bet is to use cginc files to put common code, or even all of the code, and have separate shader files to define the #pragma lines.
     
  3. hausmaus

    hausmaus

    Joined:
    Dec 9, 2011
    Posts:
    105
    Ah ok, that seemed likely. Thanks, bgolus!