Keyword Defines around include guards

Just a quick question if there is a way to use keywords to define different shader programms.
Currently messing around with Tessellation and i would like to keep the amount of shaders i use as low as possible.
This is an example of what i’m talking about:

            #ifdef _TESSELLATION
                #pragma hull MyHullProgram
                #pragma domain MyDomainProgram
                #pragma vertex TessCellVertexProgram
                #pragma fragment TessCellFragmentProgramm
            #else
                #pragma vertex CellVertexProgram
                #pragma fragment CellFragmentProgramm
            #endif

It could also be that the defines work and the problem is, that i’m defining the hull and domain passes in one of the if’s, so it get’s called anyway, if so please let me know.

Thanks in advance!

1 Like

I don’t believe you can put those kinds of #pragma lines in shader variant conditions, as the keywords are also defined by #pragma lines at the same time.

More specifically, #pragma lines are processed first before any of the #if lines. You can’t toggle shader stages on and off like that. You need to have completely separate shaders, or at least separate shader passes. Technically you could have a single shader with tessellation and non-tessellation passes in it, and control toggling them either with SubShader LOD levels, or disabling specific passes with a custom material inspector.

1 Like