Home Technical Talk

UDK: X materials on a mesh mean mesh renders X times?

polycounter lvl 9
Offline / Send Message
CarlCraft polycounter lvl 9
Mentioned here:

http://www.youtube.com/watch?v=PXQTw...tu.be&t=31m56s

"Whenever you have 2 materials applied to an object, the GPU has to render that mesh twice..."

How true is this? I'm currently working on modular buildings, and plan to reuse 3-4 materials on many different buildings (as I've seen others do). Will this mean that a building using 4 textures will have 4x tris?

Thanks

Replies

  • Farfarer
    I imagine - internally - it's broken down into submeshes - one for each material.

    So it'll have to render each submesh as if it were a separate object.
  • CarlCraft
    Offline / Send Message
    CarlCraft polycounter lvl 9
    Submesh?

    So if a building got walls and windows, each with separate materials, it will render out the walls and then the windows? Which is worse than just rendering them both at once?
  • blankslatejoe
    Offline / Send Message
    blankslatejoe polycounter lvl 19
    it's actually MORE than that too...if i recall correctly.

    It has to render the mesh once per material per dynamic light that touches it, which is why UE3 has its lightenvironment stuff for dynamic actors and why its dynamic lights can be so expensive. If you place an object with three materials and put two dynamic lights touching it, it's at LEAST 6 draw calls. I think it might actually be 12+, since the normals might be separated into their own pass (I can't remember if that was stockUE3 or something we did to the engine ourselves in the last project I worked on). And then if any of that is casting dynamic shadows, those are drawcalls too.

    So yeah, it adds up quick.
  • Farfarer
    callebo wrote: »
    Submesh?

    So if a building got walls and windows, each with separate materials, it will render out the walls and then the windows? Which is worse than just rendering them both at once?
    It can only render them both at once if they share the same material and are part of the same mesh.

    And blankslatejoe is also correct. It'll likely be one pass (drawcall) for base + ambient then one pass for each dynamic light that affects the model. For each material in the object. Plus 3 drawcalls for every light it casts shadows from.

    Although UE4 is deferred, I think, which will change things a little.
  • CarlCraft
    Offline / Send Message
    CarlCraft polycounter lvl 9
    So having a single material for all the building pieces would be preferred for optimization? I'm thinking of run time performance mostly.

    By the way; I'm not a programmer in any way, so please excuse my ignorance
  • SHEPEIRO
    Offline / Send Message
    SHEPEIRO polycounter lvl 17
    deferred doesnt necessarily change things much you still have the same drawcalls but they are rendered into different buffers... BUT batching drawcalls may have a massive effect in the future, where its will be possible to batch render shaders using different textures as long as they are the same shader (same values and effects) so heres looking forward to more textures and NO values...
  • Farfarer
    Well, deferred means that dynamic, non-shadowed lights don't cost multiple drawcalls as they happen once (to the GBuffer) rather than per mesh.

    If you have shadows, then you're adding a drawcall per mesh into the light's shadow buffer, but that's still the same cost as forward rendering.

    But yeah, there's still the same amount of drawcalls being used to put those meshes into the GBuffers.
  • blankslatejoe
    Offline / Send Message
    blankslatejoe polycounter lvl 19
    callebo--this is why so many people use a texture atlas image composited of lots of subtextures for things like buildings...but costwise, it may not be as huge an issue. If you have a large building with lots of materials, but it's only placed once or twice in the scene then having a few materials is fine--especially if the gains in smaller texture sizes or in visual quality are worth it.

    Where you have to pay attention is on stuff you place a hundred times--rocks, trees, buildings-if-you're-building-a-city, etc. Even then, the visual gains may be worth the drawcall costs for --some-- objects. I was working on a an MMO in the UE3 engine and we tried to limit most buildings to 2, but let 'hero' buildings creep up to 4 or 5. Our trees were usually 2. Almost everything else was 1. Our scene total drawcall limit was something like 1100-1400? (can't remember...but we weren't aiming for consoles)

    Also, Farfarer, I think that,yeah, deferred will make the lights be a nonissue, since things are lit after being drawn to the buffer..but I think materials will still add draws. We'll have to wait and see, I suppose.
  • blankslatejoe
    Offline / Send Message
    blankslatejoe polycounter lvl 19
    SHEPEIRO wrote: »
    deferred doesnt necessarily change things much you still have the same drawcalls but they are rendered into different buffers... BUT batching drawcalls may have a massive effect in the future, where its will be possible to batch render shaders using different textures as long as they are the same shader (same values and effects) so heres looking forward to more textures and NO values...
    .
    wait!! they're adding batch rendering of meshes?!?? Woah!
  • CarlCraft
    Offline / Send Message
    CarlCraft polycounter lvl 9
    Very helpful, thanks!
    The buildings are actually for an entire city, so atlasing them would be recommended?

    Another thing I've wondered which is kind of relevant is; when making buildings further away they will obviously need a lower polycount, but is it possible to just reuse the same texture for the LOD0 buildings, instead of using the same but smaller textures?
    I'm guessing memory vs performance comes into play here.
  • blankslatejoe
    Offline / Send Message
    blankslatejoe polycounter lvl 19
    Yeah its possible. Most building LODS use the same textures actually. it'll mip down to a smaller size anyway. For stuff that's ALWAYS going to be in the distance though, like epic distance stuff, you might find that you can get better/sharper results by handmaking something smaller for it. Mipping does introduce blurriness.

    As for atlasing--yeah, sounds like you should then. It helps to make tall and skinny atlases --like 512x2048 and then working in 'bands' of textures. That will let you take advantage of tiling across at least the horizontal easily, which is crucial for big buildings.
  • CarlCraft
    Offline / Send Message
    CarlCraft polycounter lvl 9
    Thanks a lot for the help guys, really helpful.
    When you say bands of textures, you mean bands horizontally then? Not quite sure I follow.
  • blankslatejoe
    Offline / Send Message
    blankslatejoe polycounter lvl 19
    Yep, like this http://imageshack.us/scaled/landing/227/exampleofwallswk0.jpg

    It certainly isnt the only way to do things, but it helps with modular env construction
Sign In or Register to comment.