Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to have this in my shader:

#if SHADER_API_MOBILE
#pragma surface surf Lambert noforwardadd
#else
#pragma surface surf Lambert
#endif

But this tries to compile both #pragma surface and ignores the second one instead of respecting the #if condition.

Anyone know how to add "noforwardadd" to a shader, but only when it's compiled for mobile platforms?

Thanks!

Allen

share|improve this question
up vote 2 down vote accepted

Preprocessor macros don't work on pragmas, because they are parsed before any preprocessing happens. What you can do instead is to make two identical subshaders, the top one without noforwardadd and the bottom one with. If you assign different LOD thresholds to those subshaders, you can then choose between them by making mobile builds use a lower LOD value:

SubShader {
    // Desktop shader
    LOD 300

    CGPROGRAM
    #pragma surface surf Lambert
    ...
    ENDCG
} 
SubShader {
    // Mobile shader
    LOD 100

    CGPROGRAM
    #pragma surface surf Lambert noforwardadd
    ...
    ENDCG
}

With LOD set as:

#if (UNITY_IOS || UNITY_ANDROID)
    Shader.globalMaximumLOD = 200; // Only subshaders with LOD <= 200 will run
#else
    Shader.globalMaximumLOD = Int32.MaxValue;
share|improve this answer
    
Hmm, that looks like something that might get some of the benefits that I'm looking for, thanks! With this method, I suspect it will increase shader size (instead of decreasing as noforwardadd would do normally)... – Allen Pestaluky Jun 10 at 21:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.