Vertex painted cracked wall material - trying to add 'shadowing' effect in the normal

Hi guys, I’ve been trying to dissect the method shown here: Cracked wall material ~ Yet Another Developer's Blog
However I’m still relatively new to the node graph. It’s clear that something is going wrong at the ‘adding shadows in the normal’ stage. Here’s without that portion of the graph, and with;

And sorry in advance for this poorly stitched together node graph;

It’s clear that something is going wrong regarding the normals, as if you were to rotate the house the shading would change (https://i.gyazo.com/94095bccc015dc4e5f6de55c295990b3.mp4)
The normals on the house have been set by averaged faces, but I don’t think this has anything to do with the problem.
I’ve been toying with the nodes and can’t seem to get any closer to a good result, and am at a loss at this point. I would greatly appreciate any help.

That method used the Normal from Function node and -to my limited knowledge- is extremely prone to complete garbage results. You are way better off using a dedicated blend normal texture. You can pass this back into the diffuse channel for some fake shadows (look at the Elemental Demo ‘Throneroom master’ or something material to see how) and/or you can just create small offset masks from your paintmask to create even more shadows/AO.

I added NormalFromFunction and it is definitely not very user friendly. Unfortunately to get a normal (without using screen space methods like ddx and ddy), you need to sample the textures with multiple offsets. And that means if you are mixing a function with your textures, you need to sample all of that using the same multiple offsets.

For that reason, I usually suggest when using it for complex materials like this, that you condense whatever is the height-input into a material function. That means everything it does should be contained in there. Give it an input just for coordinates. Then use the actual output pins from NormalFromFunction as the INPUT coordinates for each copy. In the tutorial you linked, the output pins (UV1, UV2, and UV3) were not used and it looks like he instead tried to do them manually. That is ok if you know exactly what you are doing, but otherwise I suggest to use the output UVs as the UVs.

Another note: Technically Vertex Color masking is incompatible with NormalFromFunction. It is just impossible to sample the values with offset UV coordinates. So that basically means the result in that tutorial would have looked the same if VertexColor masking was omitted from everything going into NormalFromFunction.

This also means you can get almost the same result by precomputing a normal map from the blend modulation texture. It will only be accurate when most of the shape of the damage comes from the noisy heightmap itself, and not from the vertex paint since that is sampled without offsets.

If you want to get correct normals with the vertex colors being more dominant, the only methods I am aware of are:

  1. using ddx and ddy. The function “Derive Tangent Basis” actually has most of this math and with only minor changes can do it. Downside is the result will be in 2x2 pixel blocks.
  2. Use a render target process to unwrap the mesh and generate the normal from the height result and store it to a texture. With that method, it will be possible to get very accurate results but you may lose resolution due to having to store it in unique UV space.

For gears of war, I just made a precomputed normal map from the blend modulation texture. Then I applied it only to the edge of the vertexblend modulated result. I also flattened that normal’s Z channel pretty aggressively and normalized it which made it stronger. It didn’t always match 100%, but it should look similar to the results in that tutorial because the vertex color isn’t affecting the normal there either. Knowing the limitation meant I learned to paint vertex colors and favor painting where the heightmap agreed, if that makes sense. So start painting, see where the erosion was strongest, and kind of follow it. And not fight areas where it would clearly take more vertex darkening to show the destruction. This tends to happen automatically for the most part, but you can certainly paint edge cases that break the illusion.

Ah, thank you very much for the detailed explanation! It’s clear that I’ll just have to dig in this weekend and really try to get to grips with these nodes, as this is rapidly exiting my current ability level, and I could barely understand the tutorial in the first place. Thanks again

@RyanB I don’t suppose you still have one of those ‘Gears’ examples ready to paste for an example right? :rolleyes: It would help approx. a dozen people or more a tremendous amount. This is the x-th topic about good edge normals when painting with vertexcolors popping up and I’m just guessing it certainly won’t be the last :slight_smile:

Unfortunately when Epic sold the right to Gears to Microsoft, part of the deal was an agreement to delete all file history in perforce and on the network. I was not prepared for it since it was not widely announced and lost tons of personal screenshots and examples that were stored on the server, such as years of art meeting content. That is why on my blog/portfolio, most of the gears stuff is from screenshots of the game instead of the nice in editor renders.

Gears1 PC may have some of the stuff but the method wasn’t really refined until gears 2 and 3. Especially 3 with the Mercy materials. And also Nick Donaldson and Jordan Walker did some great shaders using that technique for gears3.

Pity :frowning:
And I guess it’s so tremendously complicated that for you guys to add this -for instance- to the Content Samples, would make Epic go bankrupt and create a fissure in the tectonic plates that will spawn black cats?
I knew it!

haha. I like the cats theme. Fits with your user name.

But no, it’s not really that complicated. but it still would be a few hours of work for somebody to set up. I will try to find time to make an example of it at some point soon. It’s just I am already about 5 things deep in terms of promising examples and blogs for certain things.

Yeah, I can totally imagine someone like you getting completely swamped by requests all the time…‘Perks’ of being good :slight_smile:

I dunno if you guys read this, but it could potentially help out. Sorry for the necro.