Search Unity

Opinions on this implementation (outline glow effect)?

Discussion in 'General Graphics' started by Deleted User, Jan 16, 2018.

  1. Deleted User

    Deleted User

    Guest

    I want to do this for Star-Wars-like laser "shots." Unlit solid color/white core objects with a solid color outline - the "glow" or large transparency region would be a huge bonus.

    I can make effects like this but I'm curious how you would. Limitations:

    1.) There may be many, many shots on screen. (hundreds?)
    2.) I want to use deferred lighting pre-pass so I can have many pixel lights. My deferred pass shader uses a cel-lighting function.

    The answer is always try and find out- I can't until much later in the day. How do you feel about this implementation considering my intentions?

    https://willweissman.wordpress.com/tutorials/shaders/unity-shaderlab-object-outlines/

    -------------------------------------------------------------------------------------------

    Aside: Messing with deferred lighting(shading?), Unity's .cginclude files, and Shader Forge has helped further my understanding of shader programming. I'm still apprehensive about mixing forward & deferred, though Unity seems to handle it just fine: and after all, one of the visual filters is for verifying render paths.

    Is there anything you'd like me to know about deferred?

    I've learned a lot from you, thanks for carrying that torch.
    https://i.imgur.com/OVBf1V7.gif
     
    Last edited by a moderator: Jan 16, 2018
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    I would suggest against it. That'll add a ton of overhead for something that could be replicated with proper use of HDR and bloom.

    Alternatively you could just render the bolts as volumetric lines like this asset:
    https://www.assetstore.unity3d.com/en/#!/content/29160

    or this one from Unity themselves:
    https://github.com/Unity-Technologies/XRLineRenderer

    Basically it's a line with two camera facing caps on either end. Very cheap to render and lets you control the styling quite easily.

    Anything that's transparent has to be rendered using the forward rendering path. That's just the nature of current deferred rendering techniques. There are possible issues with lighting not matching or any depth based effects like depth blur, but those are issues that exists in Unity's current pure forward rendering path too.
     
    theANMATOR2b likes this.
  3. SVKsuli

    SVKsuli

    Joined:
    Mar 23, 2014
    Posts:
    63
  4. Deleted User

    Deleted User

    Guest

    I figured as much but wasn't sure. I'll explore the bloom + HDR thing; I'm curious to see how bloom actually functions. (I know how it works in concept) Just have the lasers be what's in your HDR value range and voila.

    I had the idea to do something similar to the Git project you linked, so I appreciate that because I never would have found it.

    This stuff I knew so... that's good! I assumed it'd basically be "somebody's the forward pixel lights." Which creates opportunity for discontinuity.

    Most of the stuff I want to do in forward is what you'd call unlit - things like self-lit holo shaders, maybe a few small transparencies for sci-fi thruster volumes.

    Edit: (obviously terrible mockup)



    Neat! I knew what HDR was (light values over 1 for utility) - I knew what bloom was; but I didn't consider how HDR and bloom work together.
     
    Last edited by a moderator: Jan 17, 2018
  5. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    ... nice images that do no exist !!!!! :mad:
     
  6. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    This thread is 2.5 years old...
     
  7. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    and ?
    Is it because it's 2.5yold that it's non interresting ?
     
  8. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    If your going to necro a thread, you generally want to add something to it, and not just an emoji and a lot of exclamation marks.

    For example, are you trying to implement a similar effect, and are stuck and looking for help?
     
  9. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    edit: post deleted because stupid & useless ^^
     
    Last edited: Jul 8, 2020
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    So the original poster either deleted their account at some point or got nuked by Unity for doing something bad, and the imgur links either timed out or were also delete by that user. Not really anything we can do about that here, and there's not really a point at complaining since the OP will never see it.


    For trying to do a glow effect, the answer is still here in the thread. Use an HDR emissive color and bloom post processing.

    For a custom unlit shader, you'd want to have an HDR color property:
    Code (csharp):
    1. [HDR] _EmissionColor ("Emission Color", Color) = (1,1,1,1)
    2.  
    3. // ...
    4.  
    5. half4 _EmissionColor;
    6.  
    7. half4 frag () : SV_Target
    8. {
    9.     return _EmissionColor;
    10. }
    If you don't want to use bloom post processing, then you probably just want to use a blurred texture on line / camera facing particle.
     
    bobisgod234 likes this.
  11. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Your words really don't have the meaning you seem to think they do. Nobody can read your mind. If you want help, ask for help. Don't make people pry the questions out of you like this.

    If I were to go about adding a glow to something like a laser, I would try one of:

    A. The easiest thing to do: Just try cranking up the emission on the object real high, and letting the bloom take care of it. This tended to work better on older-style bloom effects that basically just applied Gaussian-blur to the screen.

    B. The traditional method of doing an outline effect; render the mesh twice, the first time you move vertices along their normals by a fixed amount (effectively ballooning the mesh) and render it with an emissive and partially transparent shader, and the second time you render it normally. This should give you a hard, partially transparent outline that you sometimes see in sci-fi effects
     
    Last edited: Jul 8, 2020
  12. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    hi @bgolus & @bobisgod234

    The think is that i dont want to use the bloom prostpro. Though it would simply answer my needs, it's simply too heavy for small platforms like smartphones.

    The idea of particle from @bgolus is interresting as much as the B from @bobisgod234.
    I will try both of them.

    Finally i saw this on youtube wich also seems interresting:


    But it is made in shader graph and i wonder how to translate it to a vert/frag shader.
    would anyone please have a clue for this ?

    Thanks and happy blending ! :)
     
  13. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    That's just a slightly fancier way of doing what I said above. That's using an HDR color emissive & bloom post processing. The only difference is the SRP default scenes have bloom enabled by default so there's no step to add / enable it. Without the bloom it looks like it does in the Shader Graph preview, which is essentially just a solid color. The Fresnel step only really works if you have a mostly round object, like a sphere. Otherwise for things like a hard edge box you might not get any glow at all from some view angles.
     
    grobonom likes this.
  14. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    Thanks a lot for all those details @bgolus :)

    then i think that i'll have to find a way of making bloom work on mobile for having those effects.
    As a postpro effect i guess bloom runs at the same speed whatever the scene is ?
    Am i right ?

    The particle and mesh growing i tried are not a visually correct solution for my needs.
    Also i have more than 230 lights for dazzling/blinding the user.

    Therefore i imagine the bloom is a good mean for this as it gets rid of ligth sources count.

    Now my later question:
    Is there a way to apply bloom on certain objects only in the scene ?

    I red about a 2nd camera needed ( heavier way ) and also color trimming under bloom treshold.
    Would you have an idea on this please ?

    thanks a lot and happy unitying ! :)
     
  15. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The second camera method is the easiest way to only do bloom on specific objects, and indeed in the early days of bloom before HDR rendering was plausible, this was often the solution. The existing Post Processing Stack bloom already has a threshold option, but in my experience using a threshold doesn't work all that well if you want a bright bloom as it's not unusual for regularly lit surfaces to get bright enough to pass the threshold, meaning you have to limit the bloom intensity to something quite subdued. Playdead's Inside used another option, which is it encoded the HDR brightness of something in the frame buffer's alpha channel. This allowed them to get away with not using an HDR render target, but still get more "real" HDR, and fine control over what did and didn't get glows. To do that requires every single shader you use cannot be any of Unity's built in shaders as all of them write to the frame buffer alpha channel with arbitrary data, because it's usually not something anyone cares about.

    Unity's official post processing stack's bloom is also not very good for mobile. There are assets on the store that are going to be much faster, but they come at the cost of being more approximate. More specifically small bright objects may not glow at all, or will flicker as the camera / object moves. Technically this is true of even the post processing stack, but it's worse for "mobile" bloom, as the easiest way to improve performance is to reduce the resolution of the effect.

    As for cost, yes. Bloom can be a fixed cost regardless of the scene content, depending on the shader implementation. If that cost is low enough for your use case on mobile ... that's going to be a bigger question.

    Also, it's not uncommon to use both bloom and particles at the same time, as you can use particles with a min screen size to ensure the bloom effect picks it up. I don't know what your specific look is, but I can kind of guarantee you that particles (or more specifically camera facing quads) are the best option for performance 99% of the time.
     
  16. pitibonom

    pitibonom

    Joined:
    Aug 17, 2010
    Posts:
    220
    Hi @bgolus :)

    Finally, after some struggle in blender python script for adding a small plane over each of the 230 spotlights, i managed to do something interresting with bloom and HDR emissive shader :) .

    The base setup it expensive and strange on droid mobile phones but after some trimmings ( and also understanding of how works postprocessing ) it runs properly with a fair frame per second :)

    Here's what it looks like in U3D:
    carcassonne bloom.jpg

    The bad part is that bloom costs render time
    The good part is that i can add thousands of lights and it won't run slower ! ( wich is not the case of particles ) or just a bit for rendering simple small squares in the scene....

    I just regret i wasted time with some YT tuts that simply forgot to mention the bloom postpro :(

    Only small defect comes as you said, at far spotlights that are too small for beeing caught by bloom but the result keeps beeing a good compromise :)

    thanks again for your time & knowledge

    and happy unitying !
     
    bgolus likes this.