Search Unity

Fallback

Discussion in 'Shaders' started by Harry Tuttle, Sep 5, 2007.

  1. Harry Tuttle

    Harry Tuttle

    Joined:
    Jan 3, 2006
    Posts:
    122
    How can I force a shader to fallback?

    Ideally I would like to cycle through a shader fallback chain at run time so I can see what my game might look like on progressively less functional graphics cards.
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Right now you have to comment out the subshaders you dont want to load.
    Or wait for 2.0's incredibly handy Graphics Card Simulation feature.
     
  3. Harry Tuttle

    Harry Tuttle

    Joined:
    Jan 3, 2006
    Posts:
    122
    Nice plug!
    Where! when! how much!
     
  4. RockHound

    RockHound

    Joined:
    Apr 14, 2006
    Posts:
    132
    I'd like to see subshader selection under script control.

    If I recall correctly, Unity selects the highest subshader that will run on a given graphics card. However, some subshaders may run significantly more slowly than simpler subshaders. In our game we try to reach the long hardware tail, so to speak, and we would like to automatically adjust subshaders based on frame rate.
     
  5. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Isn't it more effective to do that with quality settings?

    E.g. changing the number of pixel lights gets more performance than changing a Bumped shader to Diffuse one (in an example where one subshader would do bump-mapping, and a lower one would not).
     
  6. RockHound

    RockHound

    Joined:
    Apr 14, 2006
    Posts:
    132
    In most games it's nice to give the user control over quality settings. In our game it's important that we instead do this automatically. Perhaps I'm mistaken, but I don't think quality settings can be set in script during game time.

    Regarding shaders, in reading the forums over the past year I'm sure I've read that there are times when the wrong subshader can signicantly increase render times, especially on older cards. For instance, if a card doesn't have enough texture units, is not the subshader rendered multiple times to accomodate?

    If it's true that there will never be a time when one subshader is much slower than another subshader in the same shader (assuming, of course, intelligently written subshaders), then I don't need to worry about this at all.
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    We have really put a lot of effort into making Quality settings be changable at runtime. You can even change resolution of all textures using the quality settings without reloading anything else. Using Quality Settings is extremely powerful and very easily lets you implement automatic performance adjustments. Big Bang Brain Games used this. They simply switched to lower Quality Settings based when the frame rate dropped below 20 fps.

    http://unity3d.com/Documentation/ScriptReference/QualitySettings.html

    Seriously check out the Quality settings, they are a great solution for exactly this problem. You could even select a quality settings based on the graphics card, so the user doesn't need to do it.
     
  8. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    This is only true if you have your shaders written this way. E.g. first subshader for capable hardware in one pass; second subshader for less capable hardware in three passes. But in this case your suggestion of switching subshaders from script makes less sense :)
     
  9. RockHound

    RockHound

    Joined:
    Apr 14, 2006
    Posts:
    132
    Thanks Joe for that clarification!

    Sorry, Aras, but I didn't really understand your reply.

    It appears that there are no Quality Settings that would force using a different subshader; though I think it's true that the 'pixel light count' setting would affect the number of pixel light passes in the same subshader.

    Therefore, it seems safe to conclude that the Unity developers (Aras I guess) don't consider switching subshaders a very effective way of improving frame rate. If that's true, then that's good enough for me. I'll simply rely on the Quality Settings and other mechanisms.

    Thanks for all the info.
     
  10. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    My point was that whether switching subshaders will bring any performance gains totally depends on how your subshaders are written. Switching to further than the first supported subshader can gain performance, or it can lower performance, depending on the shaders.

    The easiest way to control performance at runtime is switching Quality Setting levels, turning off things like reflective water, Projectors and so on.

    A more involved way would be switching shaders in the materials. If each shader has one subshader, and falls back to "lower" shader; then this approach is functionality equivalent to "switching subshaders from scripts". And this can be done now :) But again, whether this would bring any performance benefits depends on the shaders in question.