Search Unity

"Expensive" shaders

Discussion in 'General Discussion' started by StarvingIndieDeveloper, Jan 23, 2019.

  1. StarvingIndieDeveloper

    StarvingIndieDeveloper

    Joined:
    Aug 21, 2015
    Posts:
    274
    Yesterday, the guy who made "Welcome to the Game" was trying to manually paint an entire wall for his next game, and I suggested he simply use a procedural shader, but he replied that procedural shaders are too expensive. Many people on this forum take the same view and some even say the Unity standard shader is too expensive, but I've been using procedural shaders and custom enhanced versions of the standard shader in many of my objects, and the normal standard shader in most of the others, without much reduction in framerate. I've tested it pretty thoroughly: the framerate doesn't seem to be effected much. So why do people think the opposite?

    Obviously it would become an issue for mobile, or VR, but the developer I mentioned above is probably developing his new game only for PC and Mac (as far as I know) and his last game had far more expensive effects such as realtime reflections. What am I missing? The reason I ask is because maybe I need to scale back my heavy use of such shaders if I'm missing something here.
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,156
    If they're deploying to MacOS, shader cost is absolutely a factor as most Apple computers have tiny baby GPUs.
     
  3. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    "Too expensive" doesn't always mean that you can't afford something, it can mean that you can't justify the expense.

    Reflections can really help sell a scene and improve the realism of surfaces. Procedural wall texture vs hand painted probably doesn't do that, and the hand painted texture may even look better.

    But perhaps it just feels wasteful or unprofessional to them to procedurally calculate every pixel of a wall texture every frame when painting a texture will do. Perhaps the artistic control is a factor, or they find the task of hand painting mediative and helps them think. Perhaps they feel the coding for the procedural approach, and handling edge cases, wouldn't save them alot of time in the long run...
     
  4. Cost is relative. Using a crude example, if you're targeting 60FPS and you already use 16.5ms. everything slower than 0.1ms is too expensive. While if you're at 12ms, even 2ms isn't that expensive.
     
    Kiwasi likes this.
  5. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    Exactly. I thinks it's more likely that he meant "Too expensive when you consider my particular over-all rendering workload" rather then trying to propose some rule of thumb.
     
  6. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    The standard shader is pretty over-bloated to be honest, because it's a one-size-fits-all solution. You could write your own shader to look exactly same as the Standard shader and it would be quite a bit cheaper.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Perhaps the people you're talking to aren't very experienced or you lack the experience to find the nuance in the information you're given.

    Mobile Phones are faster than the first xbox one these days, and that game had Sunset Overdrive which had procedural shaders. Games have had complex shaders for years now.

    You should also note that most shaders aren't slow because they're complex, but because you're consuming too much bandwidth. Bandwidth is the main bottleneck in modern rendering.

    Use profiler to narrow down what is slow. If you use a lot of lights -> consider HDRP. If you use maybe a fixed amount like 4-5 use LWRP.

    HDRP might seem slower at first, but it pays off cos its an initial cost, an up front entrance fee. After that you can throw 100+ lights at it and it will be faster than anything else around here.

    If that's not an option, you should be much more interested in the following:
    • what pipeline are you using? builtin/hdrp/lwrp
    • what post effects?
    • what is your culling?
    • what does profiler say?
    • what resolution are your textures?
    • do you use mipmaps?
    • what casts a shadow?
    Use the unity profiler too.
     
    angrypenguin and Zarconis like this.
  8. Zarconis

    Zarconis

    Joined:
    Jun 5, 2018
    Posts:
    234
    Exactly what @hippocoder says, a lot of issues will stem from cascade maps and translucent material shaders (especially with deferred rendering). There's a shader visualisation tool in UE, look at the foliage with SSS and translucency, it was causing so much overdraw w/ metal rendering time was 35ms+ (in comparison BOTD ran with 25msec and more foliage due their renderer)..

    This is a small example but there's others like self shadow POM, tessellation etc. complexity / performance cost can be pretty high dependant on what you use but again as hippo said bandwidth is the real kicker. You need to have a thorough understanding of rendering technology even if you couldn't create it yourself when it comes to performance optimisation, also level design skills go a long way.

    It's knowing what to use when for a specific situation that's key.

    ShaderComplex.png
     
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    I mean they are, but they drive screens of much higher resolutions than of what an XBox One does. So having high pixel shader cost is not really that great, especially if it's something that can look just as good with a texture.

    Also if you limit your game to only the latest and greatest phones, you are probably doing it wrong.
     
  10. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    They also thermal throttle, so you may not always be able to sustain such high levels of performance. This would vary from phone to phone.