How can we create a custom mesh decal shader?

I recently realized HDRP supported mesh decals (all you had to do was use the decal material on a standard mesh instead of decal projector). This means it might be possible to move our mesh decal dependent assets to HDRP - if a custom decal shader can be made.

Here is some context on why built-in decal shader doesn’t work for us. We build our mechs using a decal mesh and a surface mesh - surface contains the main volume, while decal mesh contains labels, rivets, seams, hatches and other small reused detail. This is a relatively popular workflow (used in Star Citizen, Alien Isolation etc.), and for basic props, it can be more or less replicated with the built-in decal shader.

However, the objects we use that workflow on are not static props. Mechs are supposed to be destructible, with the surfaces accumulating pockmarks, holes and eventually fully dissolving away. Those effects are completely supposed to be ynced on traditional surface shaders we currently use both the base material and the decal material get holes in same places, dissolve with per-pixel precision etc, so you can’t rely on standard decal shader

Outside custom destruction effects, our mesh decals also need parallax mapping (since they depict things like deep seams or protrusions), handling of special color customization properties (like accent colors), per-output masks (so that decals can influence normal over one area, albedo over another area and smoothness over yet another area) and so on.

The standard way of making custom shaders in HDRP seems to be Shader Graph, but I’m not entirely sure how to create a custom mesh decal shader using it, since the available outputs seem limited to Lit-like shaders. Am I understanding right that as of right now, I’ll need to create a fork of the HLSL decal code to be able to get a custom version of it working?


^ parallax sample


^ vertex/fragment destruction effects sample

minorscentedafricanelephant
^ old damage effects sample

2 Likes

Shadergraph is more ment to make surface shaders, not decals. So, like you said, you will have to fork the HLSL decal shader code to modify it to your uses…

Since everything custom I want to have in a decal (damage, etc.) would also be required in another, traditional surface shader, I’m assuming that I can create that traditional shader in Shader Graph, lift the generated code of all the custom parts, and create a decal fork using that. That way I don’t have to touch anything related to standard Lit-like baseline - lights, shading, reflections, ambient and the rest of the huge set of ever-updated standard features.

Could you point me in the right direction there? Generated code is pretty long, so I’d like to be sure I’m copying the right parts into right places and modifying the correct files.

You probably don’t even have to touch the lit shader here. For what I know of the pipeline (I can ask the devs for further info if needed), the decals are first done after a depth pass, and rendered in a decal buffer, and then they get composited on the other opaque objects when they get rendered. And for transparent, they are applied directly in forward.
So you’ll “only” have to create a new decal shader if you want, and write to the decal buffer properly.
If you feel adventurous you could even create yourself a decal master node for shader graph :slight_smile:

Thanks for the advice! Making a new master node sounds like a perfect direction - could you point me to the files I need to modify? The docs only show how to make a plain intermediate node with inputs and outputs, as far as I see.

Am also interested in this. Was hoping for Shader Graph support for decal shaders in the form of a supplied master node, but now it looks like we’ll have to do this ourselves?

It seems like custom decal shaders are a commonly requested thing, as shown by the number of posts about HDRP decals in the beta forum.

It’s a shame. Registering my interest for decals with pixel displacement though. Should be baseline as decals are such a brilliant feature :slight_smile:

@Remy_Unity Decal graph would be a great solution i think

Hi,

decal master node for shader graph is on our 2019 roadmap, it will be only for opaque object (i.E mesh decals and projector affecting opaque).

If you want to do it yourself (ours is not there yet). You need to create a master node for the shader graph.
You can take a look at the file use to make a HD Lit master node in the Material/lit folder.

the .template contain the shader code and HDLitSubShader contain the code to generate the various pass required for HDRP. Then you need to adapt this code to do the same thing that the decal.shader file in material/decal.

This is moderate difficulty and require time and testing. Need to be careful to not break the various pass and stencil state. Dev team will not provide any support if you choose this path :slight_smile:

4 Likes

Great that it’s on the roadmap! I’m hoping emission will be supported in the decal master node.

Emissivion is something different, not related to shader graph support.

What we could do is add support of “additive” emission for decal, but not lerp. i.e we can’t remove emission from underlying surface but we can add emission on top of surface (this is for performance reasons).
I think it will be valid use case in your scenario?

3 Likes

@SebLagarde Am I understanding correctly that a “Decal Master” node I see in Shader Graph is the HDRP-compatible decal master node you referred to as planned for 2019?

@SebLagarde do we have an update or ETA as to when a more robust HDRP-compatible Shader Graph Decal Master node is coming online? I’m on 2019.1.8f1 and I’m confused as to whether what I’m currently seeing is the full featured one or not, can’t find it on the roadmap. Thanks for your time.