Search Unity

The Better Lit Shader : Replacement Lit Shader for URP/HDRP/Standard

Discussion in 'Assets and Asset Store' started by jbooth, Apr 7, 2021.

  1. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    The Better Lit Shader acts as a replacement for the Built in pipeline's Standard shader and URP/HDRP Lit shaders with the following features and improvements:
    • Supports URP, HDRP, and the Built In rendering pipelines, tested on 2019.4LTS and 2020.3LTS
    • HDRP style texture packing, or a custom tightly packed texture format for even faster shading
    • Tessellation & Parallax Support
    • Crack Free Tessellation mesh preprocessor
    • Stochastic sampling of textures to remove tiling
    • Tint Masking, allowing you to colorize 4 separate parts of the main texture layer independently.
    • HDRP Style Detail Texturing
    • Three additional independent Texture Layers, which can be used as a detail texturing, height blended, or alpha blended, with independent options for Triplanar and Stochastic on each layer. These can also be masked via vertex painting, noise functions, and procedural functions, allowing you to create many different effects.
    • MicroShadows and Fuzzy Shading available on every layer
    • Use UV, UV1, Triplanar, or world projections on each texture layer
    • Flat Shading
    • Single or Double Sided
    • Wetness, automatically integrates with Enviro and Weather Maker
    • Puddles, automatically integrates with Enviro and Weather Maker
    • Automatic placement of puddles via noise functions and angle filters
    • Snow system, automatically integrates with Enviro and Weather Maker
    • Wind system, for particulate wind over surfaces
    • Dissolve Effect, with optional gradient edge w/ optional emissive
    • Trax integration allows you to leave trails on any material you create
    • Vegetation Studio procedural indirect support
    • Support for all VR rendering modes
    • Generate normals directly in the shader to save sampling/memory on low end systems, or use the Surface Gradient framework for higher quality blending.
    • Branch Sampling, to reduce the cost of stochastic and triplanar sampling
    • Debuging mode to visualize actual sample count used by the shader
    • LOD Dither fading
    • Custom Material Interface
    • Bakery Support
    Online Documentation

    The Better Lit Shader was built using Better Shaders and is tested on URP7.x, URP10.x, HDRP7.x, HDRP10.x, and the Built in Rendering pipeline. No special install is required, just a single shader that runs on all of these different rendering systems.
    Full source code in Better Shaders format is included, and all features are done as stackables, making them easy to add to your own shaders, or customize for your own needs.

    All features work together and are available via an custom material GUI. Unused features are conditionally compiled out of the shader, and many features are available to make the shader more efficient than the URP Lit or Built In Standard shader.

    Working in URP and want HDRP style features? Or want a more efficient URP shader? Want to port between pipelines and have everything "just work"? Want to apply unique procedural damage across your entire level? Want the most advanced shader available, regardless of which rendering pipeline you use? This is the shader for you.





     
    Last edited: Jun 19, 2021
  2. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,274
    Such a very awesome asset. I had the pleasure of being in the beta and toy around. The ideas keep on spreading once you start using the asset. Can't wait to see what everyone else comes up with. By the way, most notably: This was HDRP, works the same in Standard and URP.

    Here's eg the dragon on a road mesh:



    This is one of the screenshots I took ingame:

    Pavement damaged 1.jpg
    So Trax working on mesh is super exciting.

    You can also just simply overlay the texture with another to get e. g. Dirt on the Pavement. Top is original, bottom is with a stacked texture:

    dirt.jpg

    Or just add other textures with noise in world space to make every house unique, here's an example with weathering effect:

    comparison.jpg
     
    jbooth likes this.
  3. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,274
    What's also exciting is that you can define the strength of the effects. I tried with my own Fader asset to interpolate the strength over time, worked perfectly:



    Don't mind the missing obligatory splatter :D I just wanted to show the effect ;)

    The indoor puddles are exciting. Of course I had water first, but usually one thing leads to another and I wanted to toy around with a different category of game I've never done before :D

    zombie puddle.jpg
    outside.jpg
     
    jbooth and ftejada like this.
  4. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,274
    I just toyed around with the layer blending. It's really nice how easily you can change the look with it:

     
    jbooth, keeponshading and ftejada like this.
  5. GCatz

    GCatz

    Joined:
    Jul 31, 2012
    Posts:
    282
    will it support SRP Batching ?
    what is the minimum SM needed for it
     
  6. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,274
    Been toying around with snow. While doing so I thought why not abuse it to give desert bricks some sandy look at the sides and on the top:

    desert test.jpg
    I should add terrain blending as well with microsplat
     
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Yes, though there is a Unity bug in SRP which prevents it with two variants of the shader - repro'd by Unity. Minimum is 3.0.
     
  8. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,274
    Been experimenting. I gave Irval a Tattoo :D

    tattoo 1.jpg
    Works also as War Paint :D

    war paint.jpg

    If you do that, keep in mind to set the tattoo texture's own Wrap Mode to Clamp, so that it doesn't tile.
     
    ftejada and knxrb like this.
  9. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,526
    Does blending work with Better Lit Shader? Would love to see a test for this
     
  10. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,274
    What exactly do you mean? The fading video above is sliding through the blend strengths of the layers
     
  11. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    192
    We just started testing this out for a major upcoming project (Pigeon Simulator) and seems really awesome so far!

    Curious about a couple of things:
    1. Any plans to add Texture Array support?
    2. We're using GPU Instancer extensively. Currently we're using some colors and float value arrays with it to vary the looks of things within a draw. Moreover, we're using a uint structured buffer ("Variation Values" in GPU Instancer) to reference which texture in a texture array gets used. This is all pretty niche stuff, but any chance we can do this with your product?
    Thank you for your time, and for building this shader magic!
     
  12. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You'd need to modify the source and recompile it with Better Shaders. Shouldn't be harder than changing a surface shader to do the same thing.
     
    HakJak likes this.
  13. WuceBayne

    WuceBayne

    Joined:
    May 19, 2017
    Posts:
    9
    Hi there!

    Unity 2020.3.5f1 - Built-in render pipeline - Latest version of Better Lit Shader (1.07)

    I get the following error message whenever I select or create a material using Better Lit Shader:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.MaterialEditor.TexturePropertyWithHDRColor (UnityEngine.GUIContent label, UnityEditor.MaterialProperty textureProp, UnityEditor.MaterialProperty colorProperty, System.Boolean showAlpha) (at <411aa9fd83b6416fab626ca292954771>:0)
    JBooth.BetterLit.LitBaseStub.OnLitGUI (UnityEditor.MaterialEditor materialEditor, UnityEditor.MaterialProperty[] props) (at Assets/BetterLitShader/Scripts/Editor/EditorStub.cs:1552)
    JBooth.BetterLit.LitBaseMaterialEditor.OnGUI (UnityEditor.MaterialEditor materialEditor, UnityEditor.MaterialProperty[] props) (at Assets/BetterLitShader/Scripts/Editor/LitBaseMaterialEditor.cs:47)
    UnityEditor.MaterialEditor.PropertiesGUI () (at <411aa9fd83b6416fab626ca292954771>:0)
    UnityEditor.MaterialEditor.OnInspectorGUI () (at <411aa9fd83b6416fab626ca292954771>:0)
    UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <0fdaf67e8e744beea25e77915c19f81b>:0)
    UnityEngine.GUIUtility: ProcessEvent(Int32, IntPtr, Boolean&)

    Also, the Inspector is blank, so I can't use the shader at all.

    I was able to reproduce this bug in a brand new project.
     
  14. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I pushed a patch to this last night- hopefully it'll appear on the store today. You can also PM me your invoice number if you need it sooner.
     
    WuceBayne likes this.
  15. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Hi!

    1) Do micro shadows depend on the volume override and are used for the directional light only or is this your own implementation?

    2) Do you have any plans to support Virtual Textures?

    3) How often do you plan to update this asset? Will it be compatible with LTS only releases, or can we hope for other stable or even beta versions support?

    4) Do you have any plans to integrate Bakery features into it?

    Thanks!
     
    Last edited: May 11, 2021
  16. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    It's based on naughty dog's technique, for the directional light only.

    Not currently.

    I will only officially support LTS releases, because doing anything else means you're effectively Unity's indentured servant, chasing after undocumented and unfinished changes on a constant basis with no help from Unity.

    Yes.
     
    hopeful and Kennth like this.
  17. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Thanks for the reply! A couple more questions if you don't mind.

    Because they are experimental or its hard to implement this feature anyway?

    Do you think new versions will likely break your asset? From your experience. Have you tested it in the resent non LTS versions?

    Any ETA on this?

    Thanks!
     
  18. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Haven't really looked at it yet as it's quite new in Unity.

    I can't control what Unity breaks. In the past, they've broken things in LTS versions and between point releases (7.18 to 7.21 in URP for instance), which isn't supposed to happen. In general, the SRPs are pretty unstable, though I'd say the trend is that they break things less these days than they used to. While many people run non-LTS versions, I don't even look at them, since Unity can't really be bothered to document their pipeline any change requires diffing tens of thousands of lines of code.

    I don't give ETAs..
     
    hopeful and Kennth like this.
  19. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Too bad, though understandable. Your shader looks perfect, and I would gladly replace a lot of shaders in my project with it, except I can't, because they heavily depend on the Bakery SH + Specular feature. I've also planned to update them to use SVT, but haven't tried it yet as well.
     
  20. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,274
    I couldn't be bothered to convert 10 materials of a humanoid manually, so I took Unity's HDRP converter and made a BetterLitShader converter mod of it which at its current state converts selected or all project materials from HDRP/Lit to Better Lit/Lit.

    Please note the Unity Companion License in case you want to use it:

    https://github.com/Roland09/BetterLitShaderExtensions
     
  21. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,274
    After converting all HDRP/Lit to Better Lit/Lit I experimented around a bit. Quite interesting what you can achieve with just layering and fading materials:

     
    keeponshading likes this.
  22. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    OK, so just so I have this straight...

    When using the "fastest" texture packing option...

    create a texture by..

    Bake textures in blender..
    Open Photoshop create new 16bit RGB document
    open bakes and copy and paste each image into these channels on the new doc:

    Baked Norm Red - Alpha Packed
    Baked Norm Green - Green Packed
    Baked Smooth - Red Packed -- White is shiny black is matte
    Baked AO - Blue Packed

    Baked Color Red - Albedo Red
    Baked Color Green - Albedo Green
    Baked Color Blue - Albedo Blue
    Baked Height - Albedo Alpha

    EXPORT them in photoshop to TIFF 16bit

    Import in Unity and uncheck sRGB


    I feel like something is wrong in this process because when i uncheck sRGB my red green and blue channels get wiped (they are solids colors in the respective channel previews)
     
  23. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461

    Well you don't need to do 16bpp files, Unity has limited support for 16 bit per channel data and squashes them down to 8bpc anyway. I'd just use a 32bit targa.
     
  24. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Oh i see thanks. I had heard somewhere that normal maps should be 16bit, heightmaps 32 or something like that..
     
  25. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Hmm, take a look at the Triplanar UVs in Local mode for the layer 0 texture. Lighting appears to be inverted or shifted by about 45 degrees. The world space triplanar UVs are fine though.
     
  26. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Interesting, I'll check that out - does it move with the object rotation?
     
  27. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Yep its does. As if a directional light were a child of the object.
     
  28. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Sorry to pile on the problems but it looks like the alpha mode is not working right as well. I have a gradient from black to white in the alpha channel of the albedo texture, set the shader to alpha mode and the whole model goes to about 50% opacity.
     
  29. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,274
  30. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    192
    Hi, which variants are not compatible? Or rather what settings/features cause those variants?
     
  31. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    649
    Hey Jason,

    I'm looking to get the highest quality baked lightmap that can run on older machines (historical settings in schools ... shadowmask so almost everything is lightmapped, with a few dynamic objects in there using light probes + real time shadows). I'm looking at using this with Bakery to handle different weather types + grunge in an efficient way. However, I'm also curious about using Bakery's Spherical Harmonics, since they claim that's the best quality.

    Is there any way this can work with that? They have a custom shader, but it would be fantastic if somehow that were able to be used in this as well. From their documentation: "RNM and SH can be only used with Bakery shader or require adjustments to your shaders".

    Thanks!
     
    Last edited: May 30, 2021
  32. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    We're working on a bakery integration right now, actually. Should be out soon.
     
    Mark_01, sjm-tech and DGordon like this.
  33. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    649
    Wow, thank you so much. That's awesome!

    Also, just curious since this has to run on older hardware. If no extra stuff is turned on, is this actually more performant (or at least comparable) than the built in standard pbr shader? Are things like snow / wetness relatively cheap, or weathering? Basically, just making sure this wont be much more taxing than using the standard shader or using ASE to do a few minor effects myself.

    Thanks again.
     
    Last edited: May 30, 2021
  34. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    lol, i dont think anyone is capable of writing more efficient shaders than jbooth my dude...
     
    HakJak and DGordon like this.
  35. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    649
    Sorry for the questions.

    Is it possible to achieve the shape/trails of snow in this using the snow layer, or does that only use noise and this would need to be done using texture layers? Is this something I should be using microsplat for (dynamic snow there)? Im assuming performance on this is a lot better.

    Thank you.

    [Edit -- after thinking about this, I suspect I should just use microsplat + my own terrain layer for snow, so I have more control, as well as to muddy things up where needed ... but still curious if this can be done with this.]
     

    Attached Files:

    Last edited: May 31, 2021
  36. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Generally more performant based on just the texture packing. A full PBR texted surface in the Lit/Standard shader is 4-5 textures, where it can be done in 2 or 3 in Better Lit, saving significant bandwidth.

    There isn't any kind of "painted" layer for snow coverage. You could do snow using two texture layers though instead of using the dynamic system if you wanted to carefully paint coverage though.
     
    DGordon likes this.
  37. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    649
    I'm using microsplat + this for non terrain. Its working well so far.
     
  38. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Would it be possible to add a checkbox for disabling/enabling Unity Fog for the shader?
     
  39. wetcircuit

    wetcircuit

    Joined:
    Jul 17, 2012
    Posts:
    1,409
    I think I read this shader is sm3…? Has anyone used it in webGL2. Is it compatible?
     
  40. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    649
    Hi, sorry for another question.

    How do I use this with AssetBundles? When I load my ab, the material is pink. If I try to always include the shader in the build, it yells about shader variants. If I just use the standard material, everything comes in fine.

    Not sure what I'm really doing here with this. Any ideas? The same goes for microsplat terrain ...

    The following is the error I get when trying to build an AssetBundle with this added to the always include shader: "Better Lit/Lit has too many Shader variants(4827858800541171712).To resolve this, go to Project Settings > Graphics and remove this Shader from the Always Included Shaders list.For more explicit control over how Unity includes specific Shader variants in a build, use a ShaderVariantCollection.".

    Is there an easy way to fix this, or am I not able to use this in the end because of this?
     
    Last edited: Jun 2, 2021
  41. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You need to include the shader in the bundle, or load it some other way (resources, etc). Usually you'd want the shader to be in it's own bundle which any bundles can have a dependency on, so that each asset doesn't load a separate copy of the shader.
     
    hopeful likes this.
  42. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    649
    Okay, I'll look into this. Thanks.
     
  43. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hi. I use lots of decall in HDRP. Are they supported?
     
  44. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    should be.
     
  45. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hi.
    Unity 2020.3.11f1
    HDRP 10.5.0
    Latest Bakery 1.9

    I tried the Better Lit LightMap Mode SH
    with Enable Lightmap specular
    on a copy Bakery SG example with these settings.

    Do you have an idea whats wrong here.
    Marked Plane is the Better Lit.
    Non marked Plane ist the BakerySH Shadergraph.
    Unbenannt.JPG

    The Light Map Mode SH setting in the Better Lit UI seems not to work.

    I compared the result with the Bakery Standard on BuiltInRP and it looks the same when i disable AllowSH Lightmaps there.
     
    Last edited: Jun 18, 2021
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    For any bakery questions you should ask Frank- he wrote the stackable used for integration.. (It ships with Better Shaders as well, the idea being that any asset using Better Shaders to author it's shaders gets an easy Bakery integration).
     
  47. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    OK. I will do.
    I leave this here to because of an compiler error in the shader.
    Probably you have an idea.

    Left
    Bakery Standard BIRP, Unity 2019.3.11f

    Right
    BetterLit HDRP 10.5.0, Unity 2019.3.11f

    Settings are all the same.
    Set Albedo Color.
    Set Normal Map.
    Set Roughness 0,507
    +
    enable Lightmap Mode SH in your Better Lit

    BetterLitSH.JPG


    compile.JPG

    full list

    fulllist.JPG
     
    Last edited: Jun 18, 2021
  48. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461

    Hmm, that’s from the bakery code but I’ll make it at least compile..
     
  49. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Step by step. Nice Job. This is a really powerful and transparent extension.
    The Bakery integration on this level is also very helpful.

    It s kind of a game changer for me for my mesh based driving tracks and cars.
     
    Last edited: Jun 19, 2021
  50. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    i asked Mr.F here.
    The compile error is gone but i cannot run the Bakery SH and Bakery Volume Demos with BetterLit.


    Unity 2020.3.11f1, HDRP 10.5.0
    latest Bakery updated (26.06)
    latest BetterLit (26.06)

    The first 3 Bakery BetterLit tests on Bakery Standard Demos went negative.

    BetterLit SH Test , (example_mixed_directional_mode.scene and example_directional_SH.scene)
    BetterLit Volume Shadowmask Test (example_volumes_simple_shadowmask.scene)

    https://forum.unity.com/threads/bak...preview-released.536008/page-106#post-7273978
     
    Last edited: Jun 26, 2021