Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I write a normal decal shader using a newly added (Unity 5.2) "finalgbuffer" modifier?

Discussion in 'Shaders' started by bac9-flcl, Sep 22, 2015.

  1. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    All variations already use albedo from a packed map. If you want Standard shader style RGB albedo, use Split shader type included in the repo, it should allow that.
     
  2. wafflesnbiscuits

    wafflesnbiscuits

    Joined:
    Feb 1, 2016
    Posts:
    2
    Thank you for the reply, and I do apologize, but I may not have been as clear in my original question as I meant to. I want to be able to use all the awesome features your shader has, but also be able to use a specific albedo map for labels/stickers and such.

    I'm hoping to be able to use the shader for all the awesome normal details that you show in your examples, but also use it for things like text, warning stickers, labels, insignia, etc...
     
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Any progress on the Asset Store submission?
     
  4. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Just in case you overlooked it, you can already download it from the repository:
     
  5. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    It was rejected from the store because I forgot to fill the publisher info, and I hasn't bothered to resubmit it yet. :D Will do it once more if I'll solve the issues described in the repository main page, I guess.
     
  6. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    I saw the repository, thanks.

    Actually, it is not just the publisher information they want. If you just fill in your publisher info and submit it again, you can be sure it will be rejected again. There is an undocumented requirement to have your own webpage, and put some prior work onto it. I found this out the hard way and so did many other people. There are some serious issues at the Asset Store department :(
     
    Martin_H likes this.
  7. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Ha, thanks for the info. I wonder how artists selling their assets fill that out - with portfolio page links, I guess?
     
  8. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    This is not an undocumented requirement - its just a requirement - just as it is a requirement to have a customer support email address.
    When you sign up as a publisher there is a customer support fill in which lists a url and email address. The url can even link to your twitter account which several have done. Others have setup a simple blog or wordpress site that only has a link to the email - to provide for customer support.
    I even saw an asset where the publishers customer support url links directly back to the Asset Publisher Page which only has an email address listed.
    There is no requirement to have a website that has prior work on it.
     
    Martin_H likes this.
  9. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    That is great news! Because initially I just had an Asset Publisher Page which only has an email address listed and I got this email:

    But just to be sure, where did you get that info from and how old is that?
     
    Last edited: Feb 5, 2016
  10. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Admittedly it has been some time ago - I'd say since Unity 5 came out. When all asset publishers received the notice of cleaning up assets and the asset store and deprecating some of the content.
    The email you received might be related to that update - regarding publishers not having proper support channels for there customers, though they seem to be mostly concerned with the authenticity of the content submitted.
    Here is just a quick selection of links - to facebook, linkedin, a site with a 2 pictures, and a dead link & link to a site that looks to be maybe? related - just to name a few.
    https://www.assetstore.unity3d.com/en/#!/content/55354
    https://www.assetstore.unity3d.com/en/#!/content/55255
    https://www.assetstore.unity3d.com/en/#!/content/55277
    https://www.assetstore.unity3d.com/en/#!/content/55225
     
  11. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Yeah, I think they are more strict now. I also thought that they where worried about me or my asset, but as it turns out, everyone gets the same message if you don't show your prior work. The same thing happened to Scrawk when he published Ceto for example.
     
    theANMATOR2b likes this.
  12. GreyDesigns

    GreyDesigns

    Joined:
    Apr 25, 2014
    Posts:
    8
    This is a great shader, thank you so much for creating it, and sharing it with everyone. As with wafflesnbiscuits, I was wondering how hard it would be to create a version with an albedo bitmap input. Instead of just the RGB value. That would be a really useful addition. That way if I had a more dynamic decal like a vent for example, I could have different colours for the different parts. Or stickers, etc. But awesome work, It was exactly what I was looking for! :D

    I'm guessing as it is right now, I will need to duplicate the shader and have different materials to have different colours. Which isn't ideal.
     
  13. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Err, there already is a version with completely separated inputs, including albedo. It's not a good idea to use it, since it wastes a ton of texture samplers vs. a packed approach, but it works as an example. Recheck the included files. :)

    • Path: Shading / Assets / Packages / HardsurfaceShading / Shaders / HCDecalDeferredSplit.shader
    • Input: _ColorMain ("Dielectric albedo/Metal specular", Color)
     
  14. GreyDesigns

    GreyDesigns

    Joined:
    Apr 25, 2014
    Posts:
    8
    I had a go at making a version myself, haha. It works well enough for what I need I think. :)
     

    Attached Files:

  15. GreyDesigns

    GreyDesigns

    Joined:
    Apr 25, 2014
    Posts:
    8
    I'm probably being stupid, but when I try and use that shader I only get the RGB picker? -
     

    Attached Files:

  16. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Ah, right, sorry - forgot I set it up that way since overwriting albedo with a map makes it almost pointless to use deferred decals over traditional alpha blended decals. I'll see about adding a split variety with an albedo map if I'll have the time.
     
    theANMATOR2b likes this.
  17. GreyDesigns

    GreyDesigns

    Joined:
    Apr 25, 2014
    Posts:
    8
    I just wanted to come back and say thanks again for all your work on this, I was using it to do my art test for Foundry 42 so that I could get a similar style, and it was a massive help - I am about to start my second week there as a 3D Vehicle Artist!

    If you have a paypal, let me know and I will fire you some 'beer money' when I get paid, haha! :D
     
  18. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Hey! Glad to hear my repo has helped you. Can you, by any chance (if it's not under NDA), show me your Unity work based on that shader? I'm yet to receive a single example back from all the others using the repo, so it would be fun to take a look.

    My PP is paypal.me/bac9, but I'm not sure if foreign transfers even work anymore (since the crackdown on payment systems using foreign currencies in Russia), so don't worry about it. I'm glad to help!
     
    zyzyx likes this.
  19. GreyDesigns

    GreyDesigns

    Joined:
    Apr 25, 2014
    Posts:
    8
    Hey sorry for the delay, I'm not very punctual!

    Have you got an email I could contact you through?
     
  20. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Sure thing, it's artyom.zuev at gmail.
     
    GreyDesigns likes this.
  21. Froxi

    Froxi

    Joined:
    Feb 13, 2014
    Posts:
    1
    Hey first of all, awesome shader, thank you for providing this!
    I have a question, does someone know if something like this is possible in forward rendering? We're currently working on a VR Game and we really need Antialiasing, so Deffered Rendering is a no go performance wise.
     
  22. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Nope, there is no way to do anything similar since in forward rendering every surface shader directly outputs the final on-screen pixel color. There are no intermediate buffers with PBR values to hijack.

    Your best bet would probably be packing decals into the same mesh, mapping them to a secondary UV channel, and writing a surface shader that first draws the surface and then draws the decals. Obviously, that will limit the decals, making them able to overlay only their own mesh/material seamlessly - no fancy tricks with separate meshes blending over dozens of materials possible. Better than nothing, though.
     
    Fera_KM likes this.
  23. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    I know this is a really old thread, but I literally come back here weakly for information on deferred rendering shader magic. Just wanted to actually say thank you to all participants on here for the information.
     
    arnoob likes this.
  24. Zenchuck

    Zenchuck

    Joined:
    Jun 2, 2010
    Posts:
    297
    How is dirt or wear added?
     
  25. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Personally, I prefer to use a low resolution curvature/AO bake mapped through UV2 to the main body and driving dirt/wear through masks dervied from those bakes. But you can also do this with more decals (that's what Star Citizen artists do).
     
    theANMATOR2b and Zenchuck like this.
  26. Zenchuck

    Zenchuck

    Joined:
    Jun 2, 2010
    Posts:
    297
    For creating the decal layer are you duplicating the main body and cutting parts of it away? I am interested in the modelling technique. Also, have you tried implementing a similar shader in Unreal? I will be studying these example shaders to try and understand how this effect is achieved. Thank you for providing the files to the community. This is an excellent technique.
     
  27. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    You can duplicate the body and cut it, but I prefer modeling a library of small details and using normal-aligned placement to insert them.



    That leaves seams and other nonstandard shape-dependent detail, which I like to make by drawing edges on top of the main body, extruding a cylinder over that path, then using it to cut part of the main body into a new mesh - that creates very nice strips of uniform width and uniform intersection volume, ideal for mapping of seams.

    You can definitely prepare some modular seam parts, though - for instance, I like to model some turns, place them with normal aligned move tool, and join them with stretched straight segments.



     
  28. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    @bac9-flcl
    Nice tool for placing these decals. Is that your own creation or some plugin for Blender/Max/Maya/Modo/whatever?
     
  29. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Nah, it's just standard toolset in SketchUp (plane-aligned instances). It goes beyond normal snapping, even cutting holes for inset shapes, as you can see on the gif. It creates surprisingly clean geometry, so I use it as my main hardsurface modeling tool. I don't do much more than material splits and base geometry there, though - I run some custom scripts in Unity to create UVs, bake stuff, merge meshes and materials and so on.

    Another artist on our team is using Modo, which, I'm told, has good normal-snapping support and easy ways of cutting decal strips from base geometry.
     
    Marco-Sperling likes this.
  30. franck_Extriple

    franck_Extriple

    Joined:
    Oct 27, 2017
    Posts:
    20
    Does anyone have tried to recreate that shader effect through Amplify Shader Editor ?
     
    zyzyx likes this.
  31. Amplify_Paulo

    Amplify_Paulo

    Joined:
    Jul 13, 2017
    Posts:
    297
    I've sent you a message.

    Coincidentally enough I was researching this exact subject to add to ASE when I found this thread and your post :D

    Either way I just wanted to add my own contribution to this solution in case someone finds it useful.

    I found two major issues with it. One might be possible to fix the other not so much.

    One of them is the fact that stacking them is a pain. You get all sort of ordering issues. You could expose the offset property and have it change between materials but that's still a pain to manage. That is to be expected I guess.

    The other which might be a deal breaker for many users is the fact the it breaks batching for those objects, this is because it becomes a multipass shaders that the batching system doesn't like. You also have to keep in mind the fact that you now render each decal twice. So in effect it kinda defeats the purpose of using this. I'm pretty sure many of you might still find some use for them but I wanted to share that information with you anyway so that you know the limitations. It's still a pretty clever solution ;]

    cheers ;)
     
    arnoob likes this.
  32. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    The shader has no need for a second pass unless you want to smoothly blend roughness, as far as I remember (alternative and more radical solution would be to set up a custom deferred layout with smoothness in a separate render target). Of course, this sort of a shader would usually be used on hero assets (a-la Star Citizen ships), which have limited benefits from instancing, so for some projects multiple passes won't be that much of an issue.

    You're right about the stacking - generally, this sort of a decal shader would be used for carefully designed hardsurface detail where overlaps are controlled through separate materials with different offsets or are completely missing. It's not suited well for decorating the levels with puddles and rubble and other traditional cases of overlapping decal use.

     
    Last edited: Nov 29, 2017
    arnoob and Amplify_Paulo like this.
  33. franck_Extriple

    franck_Extriple

    Joined:
    Oct 27, 2017
    Posts:
    20
    Thanks Artyom for your post. I'm also a fan of Machine from Blender Forum. to me if may fit some of my needs on creating Heavy industries machine and stuff that i'm working on for Hololens Teaching app. but unfortunately the Deferred render cost a lot in performance on this untethered device.
     
  34. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    This workflow can't be used on mobile devices since it only works with deferred rendering - which is not a good option at their performance. I'd suggest looking into traditional single-material workflows like normal maps baked from highpoly or floaters.
     
    Last edited: Dec 1, 2017
  35. MACHIN3

    MACHIN3

    Joined:
    May 25, 2016
    Posts:
    61
    What are your thoughts on the new Scriptable Render Pipeline? Can we benefit from this, maybe even get rid of the second pass for the speculars?
     
  36. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Absolutely. We don't have our hands on the reference implementation of new deferred rendering path for scriptable render pipeline yet (the so called "HD" path), but SRP should make it easy to rearrange the GBuffer or request separate targets to make proper smoothness blending possible.

    Well, it's possible to give smoothness a separate nicely blended target right now - through changing the buffer layout by replacing all deferred shaders through Unity project settings with your custom ones (and we're evaluating that option). But I wouldn't recommend doing that since you probably want compatibility with all the assets and projects reliant on current GBuffer layout.
     
  37. MACHIN3

    MACHIN3

    Joined:
    May 25, 2016
    Posts:
    61
    Fantastic! :D
     
  38. Remi_Tribia

    Remi_Tribia

    Joined:
    Apr 29, 2015
    Posts:
    40
    Hi, thanks for these amazing shaders!

    I'm using it to add stitches to fabric, and wanted to know if it's possible to combine both normal maps (not only alpha blend them) within the main mask areas.

    Here's an example (I boosted the smoothness to better see normals) :


    Decal's normal kicks in with the main mask, and I'd like to combine both normals within the main mask (so in this example, the smoothed areas would be fabric's normal + decal's normal) and only apply decal's normal within the secondary mask (threads in this example) ?

    I opened the shader code but don't know how to retrieve the underlying object's normal map (fabric here.)

    Thanks in advance!
     
    Martin_H likes this.
  39. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Looks good, I'm interested to know what your application for this level of detail on clothing is. Is it for a game or some kind of fashion design related tool?
     
  40. Remi_Tribia

    Remi_Tribia

    Joined:
    Apr 29, 2015
    Posts:
    40
    It's more oriented towards fashion industry, I'm just using Unity to visualize and validate the seam textures, which are meant to be used in a totally different application.
     
    Martin_H likes this.
  41. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Hi! It's impossible to retrieve any info about underlying normals, that's the fundamental limitation of any deferred surface shader. You can't sample the normal buffer because it's being written to at exact same moment. You're limited to modifying opacity of your contribution to deferred buffers through the finalgbuffer function.

    Technically, you can copy the normals buffer into another render target at the end of each frame and sample that new global texture in your shaders to achieve fancy blending of normals, though that requires more than just a surface shader and would make the mixing rely on potentially outdated pixel information (since everything will lag by 1 frame).
     
    Martin_H and Remi_Tribia like this.
  42. Remi_Tribia

    Remi_Tribia

    Joined:
    Apr 29, 2015
    Posts:
    40
    Thanks for the clarification! It's kind of a side project and I don't have much knowledge about shaders, I guess it'll remain as it is :)
     
  43. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    423
    Oh wow! Thank you thank you thank you!
    This is a revolution in 3D modeling! Thank you for your efforts and for sharing such a great result!
     
  44. smoluck

    smoluck

    Joined:
    Mar 8, 2016
    Posts:
    25
    I'm wondering if someone have tried to port that project to Unity 2018.2 release. i'm having some issue on it.
     
  45. vitamincpp

    vitamincpp

    Joined:
    Mar 21, 2018
    Posts:
    14
    Any news on getting @bac9-flcl decal shaders working with Unitys new HDRP rendering pipeline? This really would be awesome, because it enables such a nice modelling pipeline to us! ;-) BTW Amplify also added HDRP support for their ASE! ;-)
     
  46. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    I think HDRP already have a built in Decal Support, Mesh Decal and Deffered Decal
     
  47. vitamincpp

    vitamincpp

    Joined:
    Mar 21, 2018
    Posts:
    14
    @Reanimate_L Yes, but AFAIK they don't support custom meshes as decal projectors? There is only a decal projector component for now.
     
  48. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    you can use mesh
    MeshDecal.png
     
    Last edited: Oct 17, 2018
  49. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Yeah, this is a common misunderstanding of the purpose of these shaders. They have nothing to do with projected decals, they are intended for use on premodeled decal surfaces.
     
  50. vitamincpp

    vitamincpp

    Joined:
    Mar 21, 2018
    Posts:
    14
    @bac9-flcl Exactly! But I think they have one thing in common... They both need to write to the G/DBuffer directly. So if Unity have succeeded doing this for their decal projectors, it also should IMHO be possible to implement a solution with premodeled decal surfaces.