Texture/Material Questions

Hello,

I have a couple of questions regarding Textures/Materials.

1- More textures, or more nodes? On most of my materials i’m using the diffuse as roughness map, sometimes multiplying it with a constant or adding a oneminus… which add to the instructions. Is this better than adding another texture?

2- Instructions guidelines? I have no idea what the recommended limit of the maximum instructions is for each type of material. I did not find much info regarding this.

3- Drawcalls? Is there such thing in Unreal Engine 4? how do i know if i’m pushing the limit in a material?

4- Does it matter how many material “slots” an object has? I remember in CRYENGINE each material in the object adds an extra drawcall. Is this the deal in UE4?

5- Best texture format to use? Right now i’m using JPEG for all of my textures. Is it a good idea?

These are all good questions and I ask myself them a lot. The one answer that covers all of them is there are no guidelines, it ultimately depends on what you are making. Blending materials is more expensive than doing a lerp of two samples- but maybe you need to do that. An iOS game is going to have different requirements than a PC title. One step further, a car racing game you’ll probably want super detailed cars and crazy shaders. But say my game is a mech game and I’m shooting up cities, the car props don’t have to look great just blow up nice.

That’s how I look at it…maybe someone does have metrics. So far the material editor will let you make the most abusive shaders you can think of if you really want to.

As for formats, I use TGA’s for ease of editing in PS with alphas.

Like TimeSpirit said, there are generally no solid rules. Over time you’ll find the best practices and you’ll find out about certain things to avoid, but I’ll try to answer your questions.

1 - Using a lot of math and simple functions may not cost as much as you think (just think of how many calculations your CPU does every second). Go through the Content Examples and the Starter Content and you’ll see that Epic uses insanely complex graphs for things that seem fairly simple on the surface. For texture maps, you’re adding to the storage space and memory usage of your project. For instructions, you’re adding more load to the CPU. Both options aren’t a big deal on PC or modern consoles, so you just have to tailor those factors to your individual needs.

2 - Like above, you just do what you can. Use the least amount possible for the best possible result. It’s usually not a big deal. To see how complex your shaders are, go to View Mode > Shader Complexity. Green is good, red is heavy, white is “too complex” You can see what Unreal is considering too complex, but it’s a spectrum because you can choose when you want complex materials.

3 - As I understand it, each material is one draw in the world. A material doesn’t have more than one draw in it (unless someone corrects me). However, if you build Material Instances, they all tag along on the draw of the parent material. So you could have one big master material for your project, and your total number of material draw calls for your game could be just one or so. I suggest using material instances and parameters, but it’s necessary to have some normal custom materials for different things.

4- Like I said, each material is a draw , but I’m actually not sure if having two of the same material on an object would be one or two calls. But if you’ve got 4 materials on an object, that’s 4 material draw calls.

5 - I would say JPG is the worst. Every time a JPG gets saved, it loses information due to its lossy compression type. Even with the highest settings, a JPG can’t have lossless compression like a PNG or TGA can. I would stick with those two. PNG is easier to open and preview in a simple photo program and is lightweight. TGA is very reliable with its channels and is great if you want a customizable alpha channel. I think TIFF does the same thing, but I don’t use it.

Since those two have given great answers, I’d just like to add that since UE4 became a thing, the instruction count ‘limit’ has increased in a huge way from UDK (based on what I’ve heard and read). UE4 is extremely capable in terms of what it can do with it’s materials (instructions/texture limits), so don’t worry about breaking it too much at the beginning. Do worry about resource management (huge texture memory sizes, things like that), though.

1 - Both will use resources. Graphics cards have a limited amount of memory and bandwidth, so referencing too many gigantic textures will use up those resources (but memory, the capacity for large textures, is typically less of an issue than bandwidth, the speed of transferring those large textures). Shader calculations on the other hand will eat up your pixel shading performance, and typically that’s going to be your bottleneck. Everyone wants more complex shaders and higher quality lighting, post-process, high resolution, faster framerates, etc, and with the advent of shared texture samplers, draw calls typically associated with textures are no longer an issue. Ideally, you’d use all the resources you have available, so a combination of methods will give you the best results.

2 - I like to stay as close to default levels as possible, but that’s dodging the question. Obviously more complex shaders like ocean water with translucency, displacement, reflections, depth-based opacity, wave breaks, and panning normals will require a lot of instructions. Again, it depends on a number of factors (resolution/framerate goal of project, whether you’re targeting mobile or high-end GTX 980 setups, the style of the project, and the type of material in question). For PC projects it’s generally good practice for your necessary code to stay below 130 instructions for most base pass+static lighting rendering shaders, but that number’s just for me personally. If you choose to use absolutely no stationary or dynamic lighting, just static lighting for the entire game, you can double your shader complexity and get the same performance. Personally I’m a shader nut (Mario Kart 8), but I also have to admit that a simpler, cleaner style in 1080p also looks amazing (Rayman Legends).

3 - Materials themselves don’t usually waste more than one draw , but if a static mesh references more than one material, then each instance of that mesh will create two draw calls. If you use the shared samplers from UE 4.6 and beyond, you can basically group multiple textures together into one draw . Multiple static meshes and multiple materials will result in more draw calls, but like the texture/shader issue, you have to use discretion to tell whether or not it’s smarter to use more materials and draw calls or group together more often (hint: if it’s going in your level a hundred times, please don’t give it 3 materials. If it’s your player character, 7 materials is not insane). A well-optimized project takes advantage of both to keep draw calls and material complexity balanced low. Foliage instancing used to be one draw per group, but UE 4.7 seems to dissolve this issue in the same way it dissolved texture samplers by using arrays, and I’m guessing now all foliage actors of the same static mesh are considered as one draw .

4 - Yes.

5 - I typically prefer to use uncompressed .tga with UE4’s default DXT1 compression for most cases, or no compression for special cases. Typically I find compression artifacts are what drive people to keep using progressively larger textures, and it’s better to make good use of a quality, less compressed texture at 1/4 the size than to quadruple the texture space, compress it, and allow the quality (especially the color depth/contrast) to suffer. If you’re rendering a sharp noise map, it needs to retain that contrast and it must be uncompressed. Normal Maps also benefit from less compression. Alpha channels using hard-edge masks need to be smooth and well defined, otherwise they appear with jagged edges. Other than that, .tga with default compression settings is good for most purposes. Memory and texel rendering is not as much of an issue now as it used to be in the past, so as long as you’re not filling a giant library full of 4k textures, you should be fine. Remember, textures don’t have to be square: colored gradients look great at 1128, and that size is half as large as a 1616 pixel texture. If your material is going to tile along a short wall, the texture needs more variation in width than height, so you can cut its height down and use a texture with 1:4 or 1:8 aspect ratio and save a ton of pixels. Not to mention detail maps: tiling detail maps over larger general ones to break up repetition. I’m making a shader right now that takes advantage of this, and you can render a hundred square meters of tiling bricks extremely easily with extremely small textures.

Thank you all for the answers. Really appreciate it!

So it’s between the CPU and the GPU memory. I think taxing the CPU would be better as according to Steam the majority of people have 1GB graphics memory, and I want my project to be very flexible.

Most of my materials range from 30-70 instructions so I should be good here.

I made sure most of the models that are going to be mass placed only contain one material while rare stuff like rooms or buildings contain about 5.

I find the loss of quality in JPG negligible as my textures do not have as much fine detail to make a difference, furthermore I do appreciate the small file sizes.
My textures are mostly 1024 x 1024 but I make sure to use lower resolutions as much as I can.

Again really appreciate the help guys!
I’m loving my stay on UE4.

Glad to see that you’re enjoying your time with the community and also with the engine. Hope you stick around!

Depends. Sampling full sized texture may cost as high as hundred of simple math instructions. As a general rule, if you can replace a texture with math with reasonable number of instructions, go for it without hesitations.

There is no guidelines. It is all situational and relative. Besides instruction count, cost of your material rendering scales with screen space it occupies and overdraw, thus something, that occupies all the screen or gets overdrawn alot (eg. foliage, grass), needs much tighter fit than a small prop lets say. There is a shader complexity debug view in UE4. It should be your very rough guideline.

Same as in the other engine you are well familiar with, but minding that UE4 typically is not using multi pass shaders, so your material will commonly generate one draw per pass.

Same as in the engine you’ve just mentioned.

Consider looking at lossless formats instead.

Why are you replying to a thread that’s more than a year old?

/facepalm

The thread was mysteriously displayed at first page of recent threads, that is why. I did not look at the actual last post date.

And that is reply of epic dev? OMG. So many old posts are in the first google search page (including this one) and most of them are still relevant and useful.

I don’t work for Epic, also, almost 3 years ago?

I always wondered: why does it bother some people to revive old threads?

It clutters the active threads and it’s a waste of people’s time to read a thread where someone bumped it without adding anything