There can be more than two keywords on a multi_compile line, for example this will produce four shader variants: #pragma multi_compile SIMPLE_SHADING BETTER_SHADING GOOD_SHADING BEST_SHADING If neither of these two keywords are enabled then the first one (“off”) will be used. At runtime, one of them will be activated based on the Material or global shader keywords. Will produce two shader variants, one with FANCY_STUFF_OFF defined, and another with FANCY_STUFF_ON. How multi_compile worksĪ directive like: #pragma multi_compile FANCY_STUFF_OFF FANCY_STUFF_ON This works in surface shaders too.Īt runtime, the appropriate shader variant is picked up from the Material keywords (Material.EnableKeyword and DisableKeyword) or global shader keywords (Shader.EnableKeyword and DisableKeyword). In Unity this can be achieved by adding a #pragma multi_compile or #pragma shader_feature directive to a shader snippet. This is commonly called “mega shaders” or “uber shaders”, and is achieved by compiling the shader code multiple times with different preprocessor directives for each case. Often it is convenient to keep most of a piece of shader code fixed but also allow slightly different shader “variants” to be produced.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |