Search Unity

pragma multi_compile in cginc

Discussion in 'Shaders' started by trad_emark, Jun 4, 2018.

  1. trad_emark

    trad_emark

    Joined:
    Oct 9, 2015
    Posts:
    7
    Is it possible to define shader keywords in cginc shaders?
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    Hi!
    No, only the shader source itself is scanned.
     
  3. trad_emark

    trad_emark

    Joined:
    Oct 9, 2015
    Posts:
    7
    Thanks for the answer. May I suggest to put this information into documentation?
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    Sure, I'll add it.
     
    trad_emark likes this.
  5. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    @aleksandrk
    Does the unity standard shader dynamically add all of the multi compiles then, or how does that work? it is a bit tedious to add multi compiles to lots of shaders when we could just include the cginc.
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    Surface shaders add those when generating code, yes.
    As of Unity 2020.2 it's possible to put #pragma directives in includes, but those have to be included using #include_with_pragmas directive. This also requires turning Caching preprocessor on in Editor project settings.
     
  7. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    Wonderful! I'll keep that in mind for when we upgrade. Thanks Aleks!
     
    aleksandrk likes this.