Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bakery Decals (does anyone need this?)

Discussion in 'Assets and Asset Store' started by guycalledfrank, Dec 12, 2022.

?

Should I polish and release it?

  1. Yay

    79 vote(s)
    100.0%
  2. Nay

    0 vote(s)
    0.0%
  1. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    For a few years I was using a handy custom decal system. If you saw my game, you saw these decals pretty much everywhere. The concept is simple: just generate a mesh that follows the surface of an object, but clip it by the shape of the decal itself. Keep decal UV0 and vertex color (I'm using vertex alpha fading a lot), but project UV1 (lightmaps) and normals/tangents from the surface.

    Because these decals are just meshes with a rather unsophisticated alpha-blended shader (with a little Z trick), they can be easily adapted to any render pipeline, platform or GAPI. You don't need any GBuffer, you barely need any shaders at all to render them.

    I saw similar solutions used in GTA 4/5. Why limit your decals to some deferred projective shapes, when you can just model them as literally any mesh? This way decals can be also used to neatly hide UV seams, speeding up modelling.
    You can model any curved shape which doesn't have to follow the receiving surface exactly, and then the script will align it to the surface. Decal can be a simple quad, or a specially cut shape, or even some wobbling ring around a cylinder.
    Additionally, these decals support all Bakery features.

    So the question is: YAY OR NAY? Should I polish and release it to the store? (I don't think it should be expensive)

    The only reason I didn't do it before is because the resulting mesh is sometimes unoptimized. I need to add some vertex welding and decimation, but even in its current form I'm using it a lot.

    It seems there are also existing mesh decal assets. I wonder if they already solve all these problems? Then maybe I'll just keep this solution for myself :D









    upload_2022-12-12_13-43-0.png


    Here I'm applying curved road geometry as a decal, conformed to terrain:

    upload_2022-12-12_13-47-39.png


    Super old usage video (UI can be improved):
     
    Last edited: Dec 12, 2022
  2. Game-Dragon

    Game-Dragon

    Joined:
    Nov 16, 2012
    Posts:
    22
    I'm really loving MonoSH in Bakery, and having a decal system that supports it would be amazing.
     
    guycalledfrank likes this.
  3. simonkingandaoking

    simonkingandaoking

    Joined:
    Dec 27, 2021
    Posts:
    15
    release it please()wonder if i can use it on skinned meshes?
     
    guycalledfrank likes this.
  4. Vincentin

    Vincentin

    Joined:
    Feb 4, 2017
    Posts:
    8
    Mega Yay!
     
    guycalledfrank and atomicjoe like this.
  5. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,866
    There are, yes. The one I use is EasyDecal by Sycoforge Technologies, which can do exactly what yours does plus screen space and deferred, but I have only used it the way you do: generating static geometry and that's it. (because performance matters)

    However your system is the only one to account for the lightmap UVs, cut the mesh to the texture and support vertex alpha. Others just expect the decal to be applied by multiply or additive shaders, which is not ideal.

    I'm definitively interested! :)

    One thing I miss from your screenshots though is an option to stretch the decal so it isn't cut on 90º angles, like in the walls in this screenshot:
    Other than that, I love it! :)
     
    guycalledfrank likes this.
  6. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    Not yet. But it should be possible to add.

    They were stretched originally, but then you have these awful stretched lines which look kinda like a bug, so I decided to just clip polygons by angle instead...
     
  7. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,866
    That's what I guessed. Then maybe just make it user configurable :p
     
    guycalledfrank likes this.
  8. orels1

    orels1

    Joined:
    Mar 23, 2017
    Posts:
    1
    Please do!

    Projecting lightmap UVs is something I miss dearly in Unity.
    It would be awesome also to allow non-deforming relatively flat meshes, e.g. Picture frames and the like to be used in the same way too
    But even the decals would be a huge boon for forward-rendered games which have most things already lightmapped
     
    guycalledfrank likes this.
  9. RobOuellette

    RobOuellette

    Joined:
    Jun 5, 2018
    Posts:
    10
    Definitely interested - forward needs better decal solutions!

    There have been times where I've applied a normal map from an underlying material to my decal floater material + manually offset it to match; it felt so silly. Using tangent info from the directional map would be so much better.

    Also, I despise placing edge decals so anything that aims to ease that is deeply appreciated.
     
    guycalledfrank likes this.
  10. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    How do you imagine automating it? You don't want to place them on EVERY sharp edge, right?
    To me it's a very case-by-case thing that I take care of during modelling.
     
  11. RobOuellette

    RobOuellette

    Joined:
    Jun 5, 2018
    Posts:
    10
    It's definitely case-by-case, yeah. I'm currently working on a project that's forcing me to do it a bit so I may be biased in my loathing for it. I'm not sure if you've had a chance to check out the game Control at all, but their brutalist environment direction is a great example because it seemed like an overwhelming majority of their structural geo was primitives and base materials with almost every hard edge given an edge normal decal, haha.

    I'm curious if a plausible method would be to do something similar to Unity's LM unwrap where it looks at the angle of neighboring triangles (of tagged objects) + generates off some angle threshold of error? I'd also be happy if I could click on two verts + have it generate a strip across or something too. I'm not fully sure, but spitballin!
     
  12. Hugo99999999

    Hugo99999999

    Joined:
    Jun 8, 2022
    Posts:
    21
    Sorry I've spent a month working on bakery. but it has more or less problems every time. I have no choice. Had to give it up to use the unity default pipeline for bakery. Is there any bakery tutorial that you would recommend for me to learn it systematically.
     
  13. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    This thread is unrelated, but maybe

    1. My quickstart?
    https://geom.io/bakery/wiki/index.php?title=Manual#Quickstart

    2. Silent's guide?
    https://gitlab.com/s-ilent/SCSS/-/wikis/Other/Light-Baking

    3. Just ask me questions for anything you can't get right?
     
  14. NoxityGames

    NoxityGames

    Joined:
    Jul 1, 2018
    Posts:
    21
    As for the decal system - how would this work with placing decals at runtime ? The only way I could see that properly supporting baked lighting is with meshless light baking (volumes or such), and I don't think that that is currently possible with Bakery (would be absolutely awesome to see though).
     
  15. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    No problem creating decals at runtime at all - just the same mesh generation/UV projection code. I did implement similar decals in the pre-Unity times, and it was pretty fast even on my 2009 machine.
    (can be slow if projected on a very high-poly mesh though)
     
  16. NoxityGames

    NoxityGames

    Joined:
    Jul 1, 2018
    Posts:
    21
    Oh that's amazing ! Then this solution seems absolutely very promising - hope to see it sometime soon in the future !

    Meshless lighting (light/irradiance volumes) are still Nr.1 on my Bakery wishlist though :) Maybe some improvements to Bakery's light volumes could get us there ?
     
    guycalledfrank likes this.
  17. GoldFireStudios

    GoldFireStudios

    Joined:
    Nov 21, 2018
    Posts:
    156
    Would this work standalone without Bakery if we just need a simple mesh decal system?
     
  18. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    Yeah, it definitely doesn't have to be dependent on Bakery.
     
    jirimotejlek likes this.
  19. NoxityGames

    NoxityGames

    Joined:
    Jul 1, 2018
    Posts:
    21
    Hi! Are there any updates on this? I could really use a system like this for current projects :)
     
    jirimotejlek likes this.
  20. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    Not yet, but will release the 1st version this year!
     
    ronjart, NoxityGames and jirimotejlek like this.
  21. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    20
    Looking forward to it, can't wait
     
    guycalledfrank likes this.
  22. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    320
    I've been wondering for a while if it would be possible to project textures into the lightmap texture, mostly for grime to break up tiled surfaces. This way there would be no additional cost at runtime.

    Correct me if I'm wrong but this tool projects a mesh on top of the surface rather then blending it into the lightmap texture?
     
  23. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    It projects lightmap UV onto decal UV, so the decal shader can sample it and blend in.
     
    sh0v0r likes this.
  24. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    320
    Gotcha, on a related note though, do you think it would be possible to project/combine textures into the lightmap so no additional runtime overhead for texture memory and the decal mesh?

    We've been looking at a work flow where we take an environment uber mesh, export it out with lightmap UV's to Substance and run a weathering pass to create dirt build up and water stains that we would combine into the lightmap. Only problem is its a laborious process that has to be done again if anything changes. I wish there was a way to do that directly in Unity after the lighting is baked or as a prebake process that saves of the projected textures and combines them at the end of the Lightmap bake perhaps.

    I have no illusions or expectations you'll look into it, just curious about your thoughts about the idea?
     
  25. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    That's out of scope for this particular tool, but it's totally possible to write a script that would blend albedo/emission/decals into the lightmap. UV1-mapped albedo/emission textures are already precomputed before baking, so it's possible to read them and blend automatically. Write me an email/DM so I remember this and I'll write something for you (without the decals for now).
     
    sh0v0r likes this.
  26. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    320
    Shot you a msg on Discord as well mate.
     
    guycalledfrank likes this.
  27. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,629
    Alright, so I'm finishing this now.

    First, I implemented a normal UI that is not painful to use:

    upload_2023-11-14_16-50-24.png

    With "Pick in scene" you can just click of stuff you want to receive the decal without having to scroll through object lists:

    upload_2023-11-14_16-52-35.png

    Don't want to select receivers manually? Cool, got you covered:

    upload_2023-11-14_16-53-13.png


    "Live Preview" button allows moving the decal and changing any of its settings interactively. When you're happy with the decal, just exit Live Preview or (if you didn't enter it), click "Update" once. Usually for a single decal mesh generation is just a few milliseconds (obviously it only happens once on a dev machine, then it's just a simple mesh).

    I also implemented skinned decals, but for now they have some limitations, namely they're being applied to the PRE-skinned model, i.e. if you want to apply a decal to character's leg, you need to transform into its pre-skinned position and apply the decal there... maybe I'll find ways to make it easier. Here is a random graffiti sprayed on legs:

    upload_2023-11-14_16-58-0.png


    Next, I added runtime decaling methods, because obviously we want be able to apply decals during the game for any kinds of splatter, dirt, footsteps, holes, whatever? And while the current solution is usable at runtime, it... could be faster!

    So I decided, why shouldn't I write a complete new fully GPU decal system from scratch? :D
    Unlike the CPU system, which supports arbitrary volumetric shapes as decals, the GPU system only uses quadrilateral decals, but I think it's enough for most in-game purposes (curved decals are more important for level design). Mesh generation is done completely on the GPU. Then, this mesh can be either rendered with DrawIndirect (possibly needs some render pipeline hacking) or downloaded back to CPU and used to create a normal Mesh object. Right now even the 2nd method doesn't seem to cause any noticeable slowdowns (and it only needs to happen in one frame when the decal is created).

    Both solutions will be included in the asset.

    Little test video of the GPU system: https://twitter.com/guycalledfrank/status/1724454193337942243

    Better test video: https://twitter.com/guycalledfrank/status/1724501378272215249

    upload_2023-11-14_19-57-22.png
     
    Last edited: Nov 14, 2023 at 6:57 PM