Search Unity

Standard shader Decals question

Discussion in 'Shaders' started by vovo801, Jul 29, 2020.

  1. vovo801

    vovo801

    Joined:
    Feb 3, 2015
    Posts:
    18
    Hello!

    TLDR: Wanted to use the Standard shader to render decals on a car. Added the decal texture into the Detail Albedo of the material with a Standard shader. Results are perfect apart from the blend mode of the texture. I wanted to overlay the texture over the main Texture of the material, instead it's rendering like "Multiply" (tinting the main texture).
    Goal: have a lit shader similar to the Standard one with a dedicated slot for a decal that will be rendered on top of the main texture and the whole surface should be lit/metallic.

    Expanding on TLDR, what I tried so far:
    1) Tried Legacy Shaders/Decal. Result is perfect in terms of blending mode (the decal texture is overlaid on top of the main texture, the main texture is not visible under the decal). But it is not lit. Having this Decal shader with some lit/metallic properties would also be a perfectly valid solution.

    2) Downloaded the builtin-shaders archive. Discovered that the Standard shader contains the line:
    #pragma shader_feature_local _DETAIL_MULX2
    In UnityStandardInput.cginc that was included into the builtin-shaders archive, discovered that there are other defines _DETAIL_MUL, _DETAIL_ADD, _DETAIL_LERP.
    Created a copy of the Standard shader, tried replacing all of the _DETAIL_MULX2 mentions in the file with all of the other define versions (_DETAIL_MUL, _DETAIL_ADD, _DETAIL_LERP). With each of these other ones the decal texture disappears completely from the model. With _DETAIL_MULX2 it renders fine, but, of course, again, with a multiply effect.

    Thanks for reading till this point. If you can point me in the right direction with this or if you happen to have a similar shader, please help me out.
     
    Salvador-Romero likes this.
  2. vovo801

    vovo801

    Joined:
    Feb 3, 2015
    Posts:
    18
    For anyone still looking for the solution - we ended up using a paid asset "Pro Car Paint Shader" by Boundary Studio:
    https://assetstore.unity.com/packages/vfx/shaders/directx-11/pro-car-paint-shader-102063

    It supports base color + several layers of decals. Decals support tint and transparency. We used white transparent pngs and tinted them different colors.
    I am not the author of this asset and I am not related to this asset in any way, just sharing the solution that worked for us.
     
  3. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    781
    I just ended up here after trying all the exact same steps as you, with the same results.

    Despite not finding a solution here, I've now solved it, so here's the solution:
    • Copy across StandardShaderGUI.cs from the standard shader files as well. Name it something different.
    • Find the line "SetKeyword(material, "_DETAIL_MULX2"...) and change it to "SetKeyword(material, "_DETAIL_MUL"...).
    • In your version of Standard.shader that you've also modified (probably changing _DETAIL_MULX2 to _DETAIL_MULX), change the line at the bottom (CustomEditor "StandardShaderGUI") to be the name of your modified GUI.
    Now it works. Turns out you need to enable the keywords that your shader wants to use.
     
    Last edited: Jun 26, 2022
    vovo801 likes this.