Home Technical Talk

Questions about Materials/Shaders and Textures

polycounter lvl 3
Offline / Send Message
NoRank polycounter lvl 3
So, my polycount fellows, I'm pretty sure that this is a noob question but I still can't figure out and can't find the exact answers so I will just ask here. 

I'm using unreal in this example but the question applies to any other engine too (well, at least that is what I think lul)

So, first question is:
If I use one texture (or like in this example 2) in different materials/shaders/instances, will the engine normally recognize that they are the same textures and thus saving memory?

I mean, I used the same plastic normal and plastic roughness for every asset here, the only difference is that in each instance I changed the color with a color node and on the trash bags I loaded one unique normal map that I have combined with the plastic normal.

This is the master material (which is pretty simple for now, just for the sake of knowing i'm not doing stupid stuff lol):
So, on the trash bags I have the plastic normal, plastic roughness and one unique normal map that I baked just for this example from a HP mesh.

It goes like this, on the trash can, I used the plastic white and on the trash bags I used the instance named with the _trash because in this instance I have a detail normal map but it still uses the same plastic roughness and plastic normals. 

For the second question, It's about using multiple materials and drawcalls. As far as I read about it, each material will add up one drawcall. But is that really bad? I mean, using the decals technique you normally will have at least 2 materials for each asset (if i'm not mistaken ofc). 
I'm not saying I will stack materials just like a retarded, I'm just trying to understand how bad is using multiple materials for a good amount of assets on a large scene.

tl; dr
Does the engines normally recognizes that I'm using the same texture on different materials/instances?

Using 2 or 3 materials per asset can become a problem?

Replies

  • musashidan
    Options
    Offline / Send Message
    musashidan high dynamic range
    Quoted from UE forums:

    "On meshes and material IDs, let me present a hypothetical situation to try to explain the situation more clearly. Let's say you have a mesh that has three materials: wood, chrome, and leather. Now let's say you place 100 of these meshes in your level. Ignoring other passes (shadow, depth only), this will result in 300 draw calls: one per-ID, per-instance. You can see this by looking at the section counts in the primitive stats window.

    First thing to keep in mind: some draw calls are more expensive than others. The renderer sorts by material. So in this hypothetical scene we will draw the 100 wood elements first, the 100 chrome elements next, and the 100 leather elements last. Once we draw a wood element, the cost of drawing another wood element is not so high because we are rendering using the same shader and with mostly the same textures. But once we switch materials to draw the chrome we incur a high cost. That's why the renderer sorts by material.

    Compare that situation to another scene where you have the same mesh instanced 100 times but each mesh has its own unique material. The scene is still 300 draw calls but the renderer incurs the material switch cost for every draw call. Instancing a mesh provides performance benefits even if the total number of draw calls does not reflect that"

    To really see the performance boost in using Instances bring up the Stat UNIT and watch the DRAW versus GPU (CPU vGPU) and notice when you instance a mesh the CPU time remains fairly consistent depending on the additional information you are wanting to pass to each instance, while the GPU will increase. All of these numbers are still dependent on the size of your mesh and the type of material setup and the ultimate limitations of your CPU and GPU.

    Thank You

    Eric Ketchum



  • Eric Chadwick
    Options
    Offline / Send Message
    Yes reusing textures does save memory.
  • NoRank
    Options
    Offline / Send Message
    NoRank polycounter lvl 3
    Thanks for the answers guys.

    @musashidan Idk if I got it right on this text, but this means that having the same texture is kind of a gain because it will be faster to render the same material but this also means that the models instead of rendering entirely, they will be gradually be rendering sorted by materials.
    My whole question was, even if it has some impact on performance, would it really be a problem? I saw some graphs that people did and there was no real big difference. I was wondering if in a big production, like a AAA game would this difference be even relevant over the benefits this have?

    Idk, the more you read about, the more you get confused lol. That's probably because I'm not a technical artist at all and I'm probably worrying too much with things I shouldn't be.
  • radiancef0rge
    Options
    Offline / Send Message
    radiancef0rge ngon master
    Performance and memory are two different issues. 
    Sharing textures reduces memory as only one texture asset needs to be stored on disk. 
    Instanced draws increase performance as those meshes can be dispatched at the same time. 

    Instanced draws require the same mesh data, meaning the tri order and count cannot change. Therefore a trashbag and trashcan using the same material and texture are not instanced regardless of the same material. Having multiple material draws on a mesh is fine within reason. 

    Determining what method for texturing and creating materials depends on your game. Streaming games tend to rely on less textures as memory is the bottleneck, so reuse is key.
  • Obscura
    Options
    Offline / Send Message
    Obscura grand marshal polycounter
    My 2 cents:

    In my experience, the texture part really depends on the texture size, and the budget, and its really easy to track with the profiler. In modern/AAA games you can aim a pretty high buget nowadays, around 2-3-4 gb of video memory overall, with quality settings in mind - Even some games will tell you that it uses that much, when you hit ultra settings. Still , the spent resources should be wisely used. Most of your video memory will go for the textures though. So resolution should be considered based on some factors. However, shader complexity can make things much worse even if its just one texture used. Avoid complex math, complex blending, many textures inside one material, looping materials.

    Now back to the textures...There is a thing called mip mapping and it exists in pretty much all of the  game engines because its a really useful thing , it kinda cooperates with your screen resolution and adjusts the texture size based on screen size/distance, to avoid graphical artifacts such as more patterns and subpixels. In Unreal, there is also a thing called texture streaming, which should in theory load/unload necessary/unnecessary mip levels of the textures based on importance, distance, so basically if you have a 2k by 2k texture, you'll see it on that size in a small percent of cases.

    ...

    Now I'm looking at your material and I see you did not pack the roughness into anything, and it has its own texture. You could reduce the number of used textures by packing it into the alpha channel of something - but usage of the alpha channel also depends on some settings... If packing into the alpha of a different color space texture  would give you color space issues, you could put it back to where it should be. 

    Here is something about the "normalmap" compression:

    - when you set a normalmap to use normalmap compression, you will see some resource size increase due to the wider  (1,-1) color rangeand better compression ( compression is dxt 5 bc 5).
    - when you set a normalmap to use default compression, you see that the file size decreased a lot if you don't have and alpha channel (dtx 1/5 bc 1/3). In this case, you can put back the normal map into 1,-1 range by multiplying it by 2 and then adding -1. If you do have an alpha channel, you will get the same resource size as if you would use normal map compression. So to be honest, the normalmap compression seems to be really wasteful to me -  I see its differently compressed but we all know that on not so smooth surfaces, this should not be an issue.


    Sooo... normalmaps with default compression can be something to consider especially if it doesn't have an alpha channel...
  • NoRank
    Options
    Offline / Send Message
    NoRank polycounter lvl 3
    Thanks a lot for the info guys!

    @radiancef0rge Yeah I read on some places that memory usage doesn't exactly affect performance (even thought that when it exceeds a certain limit it actually does).
    The main reason of reusing the textures would be just to make things faster and easier to change. So, if it's not really a concern if used with caution, then I'm ok, just don't want to test a workflow that sucks on performance and is bad optimized.

    @Obscura I normally pack my textures with metallic, roughness and AO, just for this one I actually didn't. Thanks a lot for the info about the normal maps too, didn't know about that.

    Actually I have one other question about channel packing, idk where I saw someone saying that the blue channel (?) has more information so it would be better to pack the roughness there. Is that true?


  • radiancef0rge
    Options
    Offline / Send Message
    radiancef0rge ngon master
    NoRank said:

    Actually I have one other question about channel packing, idk where I saw someone saying that the blue channel (?) has more information so it would be better to pack the roughness there. Is that true?
    This depends entirely on your compression method. A DXT1 texture is compressed at R5G6B5 so the green channel actually contains more information than that of the red and blue. DXT5 is R5G6B5A8 so it makes the alpha channel an ideal place for roughness or gloss. BC compression is more intelligent about its choices to crunch information (http://www.reedbeta.com/blog/understanding-bcn-texture-compression-formats/)
  • musashidan
    Options
    Offline / Send Message
    musashidan high dynamic range
    @radiancef0rge Although isn't this a trade-off as RGBA DXT5 Vs RGB DXT1 uses near twice the memory?

    So, for instance, if you were building non-metal materials with a solid colour Albedo, you could pack 2Xsets of rough/AO into a DXT5, and you'd be halving your draw calls on textures but doubling your memory footprint.



  • radiancef0rge
    Options
    Offline / Send Message
    radiancef0rge ngon master
    @radiancef0rge Although isn't this a trade-off as RGBA DXT5 Vs RGB DXT1 uses near twice the memory?

    So, for instance, if you were building non-metal materials with a solid colour Albedo, you could pack 2Xsets of rough/AO into a DXT5, and you'd be halving your draw calls on textures but doubling your memory footprint.

    Correct, whether you can take the memory trade off depends on your situation.
    Less fetches to disk and sampler limits can be a issues where alpha packed textures are necessary. 
Sign In or Register to comment.