Materials Blending a'la UDK

Started by
7 comments, last by InvalidPointer 11 years, 11 months ago
Hey,

I've just stumbled upon an interesting video showing off materials blending in UDK (http://www.3dmotive.com/training/udk/advanced-mesh-paint-with-udk/) and I was wondering how such an effect could be implemented.

There are two ways that this could be accomplished I can think of.
First is to render the mesh twice and use alpha blending. One mesh would be rendered on top of the other one with alpha blending turned on.
The second way would be to render mesh once, with both materials computed in a single shader and lerped at the end. That would however require some materials generation system.

Which solution do you think UDK uses? Does it render mesh twice, or does it use its internal material system to combine component materials?
Advertisement
Neither, it's all the same material. You're really just dinking with opacity values and shader constants to create variety.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Are you completely sure of that? An artist told me that he could blend separate materials in UDK and asked me if I could do the same in Unity. Of course, "material" is quite a high-level concept which differs in UDK and Unity, so I was wondering how this could actually be done technically in UDK.
I'm not sure how Unreal implements it, but in our engine we do all of the material layer blending in a single pass. To make it nicer for the artists the tool supports having a layer derive its properties from a separate material, and then we build a shader with all of the seperate material properties specified for each layer. This obviously requires some pretty complex tools and build pipeline support.

IMO this is really the only way to do it, because rendering in multiple passes is expensive. It also prevents you from blending together the material properties from multiple layers...for instance a lot of times you want to blend the normals from multiple layers and then apply lighting to the surface (imagine a layer of water running over some bricks). With deferred rendering you can blend G-Buffer properties, but of course only if your G-Buffer uses blending-friendly texture formats and packing. And of course you have to blend multiple render targets, which may not be very cheap.

I'm not sure how Unreal implements it, but in our engine we do all of the material layer blending in a single pass. To make it nicer for the artists the tool supports having a layer derive its properties from a separate material, and then we build a shader with all of the seperate material properties specified for each layer. This obviously requires some pretty complex tools and build pipeline support.

IMO this is really the only way to do it, because rendering in multiple passes is expensive. It also prevents you from blending together the material properties from multiple layers...for instance a lot of times you want to blend the normals from multiple layers and then apply lighting to the surface (imagine a layer of water running over some bricks). With deferred rendering you can blend G-Buffer properties, but of course only if your G-Buffer uses blending-friendly texture formats and packing. And of course you have to blend multiple render targets, which may not be very cheap.

What about shader instructions or textures limits? For instance, in our engine we right now have quite a simple shader that blends 4 diffuse maps. If we added normal maps that is as much as 8 textures (not counting others, like shadow map[s?]). I don't remember exactly the limits for this in Shader Model 3.0 for instance, but that is quite a lot of texture data to sample in a single shader. A good thing about that is that we could afford many ALUs without sacrificing much or any performance :).
To get around blending 8+ textures (or at least get around the increasing performance hit for such) more people are going for baked blending using Megatextures. All your blending baked into one texture, a good trade off between performance and disc space if you've got the latter to spare.

Of course I wouldn't consider this a silver bullet. Odds are digital distribution will become momentously more popular for the next generation of consoles, and the less disc space you use the easier it is for people to get.

What about shader instructions or textures limits? For instance, in our engine we right now have quite a simple shader that blends 4 diffuse maps. If we added normal maps that is as much as 8 textures (not counting others, like shadow map[s?]). I don't remember exactly the limits for this in Shader Model 3.0 for instance, but that is quite a lot of texture data to sample in a single shader. A good thing about that is that we could afford many ALUs without sacrificing much or any performance smile.png.


SM3.0 is limited to 16 textures. I don't remember the instruction count limit, but I think it's in the thousands and you could possibly get around it using loop instructions. Either way I don't work on SM3.0 platforms, so I'm not too worried about that. smile.png

If you want to look at it from a performance point of view then blending in the shader is always going to win. With multiple passes you end up doing the same amount of work per-pixel, except you have to pay for alpha blending and processing/rasterizing your triangles for a second time.

To get around blending 8+ textures (or at least get around the increasing performance hit for such) more people are going for baked blending using Megatextures. All your blending baked into one texture, a good trade off between performance and disc space if you've got the latter to spare.

Of course I wouldn't consider this a silver bullet. Odds are digital distribution will become momentously more popular for the next generation of consoles, and the less disc space you use the easier it is for people to get.


Yeah that is one of the really nice things about unique virtual texturing...it must be nice to not have to use vertex painting or decals to get some surface variety. Personally though the combination of LOTS of disc space + crappy runtime texture compression + lower peak texel density aren't very appealing.

Are you completely sure of that? An artist told me that he could blend separate materials in UDK and asked me if I could do the same in Unity. Of course, "material" is quite a high-level concept which differs in UDK and Unity, so I was wondering how this could actually be done technically in UDK.

No, for realz. There may be other approaches, but the specific materials used in the video you linked to were all designed explicitly to support vertex color-based blending. Unreal lacks the concept of multipass rendering for materials outright.

EDIT: In fairness, I think lighting is done multipass, but this is not something you work with as an artist. The material compiler generates a lightmap-lit shader for 'ambient' and point light additive shaders.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

This topic is closed to new replies.

Advertisement