Search Unity

Glow shader, not bloom?

Discussion in 'Editor & General Support' started by Martin-Schultz, Feb 2, 2008.

  1. Martin-Schultz

    Martin-Schultz

    Joined:
    Jan 10, 2006
    Posts:
    1,377
    Hey guys,

    I was talking today with Thomas Lund and Magnus Blikstad about a game we want to make and one of the nice-to-have features would be to have a puck/ball thing with glowing parts on it. So we searched in the forums but didn't find anything explicetly on glow shaders, so I wanted to ask about how to do it.

    So what we want to archieve is to have a glow on a part of a model and this glow effect should be controlled / managed on object basis, not on scene basis. If I understood the glow effect of Unity so far right, it is more kind of a bloom effect working on the entire scene, is that right? But what we search for is more a glow that is somehow controllable by its intensity and works per object, not per scene. Is that possible somehow and maybe stock in Unity already?

    Thanks for your help,
    Martin
     
  2. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    No, it's not part of Unity at the moment, but would be GREATLY welcomed if it was.

    The Unity Glow (Bloom) works of each surfaces Alpha channel, which for 80% of the time is fine, unless of course you have an object that is using alpha to have transparent areas.. then you are screwed because to see the transparency, your object glows when maybe you don't want it to.

    I would love a solution for this on an object by object basis, or another glow channel that glow can use so it doesnt have to use alpha.
     
  3. Dragon Rider

    Dragon Rider

    Joined:
    Jan 17, 2008
    Posts:
    280
    Until then, you could use a somewhat intense point light with "Force Pixel Shading" enabled. This may not achieve the effect you are looking for, but it might work. Another thing that might work is a lamp halo or flare...
     
  4. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    All of what you want is possible already. :)

    http://unity3d.com/support/documentation/Components/script-GlowEffect.html

    Basically just change the scene view to render alpha only, and tweak away at your materials. (The tip at the bottom of that page.) White is lots of glow, black is none.

    Unity's built in shaders tend to write the most logical thing into alpha. In the case of transparent shaders or particles, you'll have to alter the built in shaders slightly if you want to write out some sort of alpha for Glow in addition to using it for transparency. I did this in Big Bang Reaction among other things.

    Cheers,
    -Jon
     
  5. Martin-Schultz

    Martin-Schultz

    Joined:
    Jan 10, 2006
    Posts:
    1,377
    Thanks for the infos so far.

    @Jon: No, it's not precisely the same. The alpha still controls the overall scene glow, not the individual object glow, even if the alpha values are different for the individual objects. This is especially different as the alpha value possibly controls multiple things at once, like for example the amount of reflectivity too, so there you get in conflict quckly.

    So in this kind of scenario, a seperate glow thingie would make sense to avoid the shared alpha value troubles. Not sure, but maybe there is another way around to avoid this / get it working?
     
  6. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Guess I don't understand, but having a separate buffer for every object's glow wouldn't be performant. You can write whatever you want into the framebuffer alpha in whatever amount of passes. I've used the alpha channel to control transparency, then in a second pass write to the alpha channel for the amount of glow.
     
  7. Martin-Schultz

    Martin-Schultz

    Joined:
    Jan 10, 2006
    Posts:
    1,377
    Hehe, possibly my explanation was not so good :)
    Right, might be a performance hit, but currently there's kind of "collision" having the alpha value control both, the glow AND for example the reflectivity. So if in this case a seperate buffer could exist to control them seperately, that would be great.
     
  8. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    You need to write your own shader, even something simple. For example you could do:

    Code (csharp):
    1.  
    2. Shader "Fire zee alpha!" {
    3.     Properties {
    4.         _Color ("Main Color, Alpha", Color) = (1,1,1,1)
    5.     }
    6.     Category {
    7.         ZWrite On
    8.         Lighting Off
    9.         Color [_Color]
    10.         SubShader {
    11.             Pass {
    12.                 Colormask A
    13.                 Offset -1, -1
    14.                 Cull Back
    15.             }
    16.         }
    17.     }
    18. }
    19.  
    Then apply that shader to a copy of the object you want to glow.

    In these types of situations you have to think about exactly what goes on in between the shader, rendered frame, and glow effect. There is almost always a solution, and if your good you can often pull it off without adding passes.
     
  9. Dragon Rider

    Dragon Rider

    Joined:
    Jan 17, 2008
    Posts:
    280
    Heh. I couldn't write a shader for the life of me...
     
  10. Martin-Schultz

    Martin-Schultz

    Joined:
    Jan 10, 2006
    Posts:
    1,377
    Cool, thanks for the hints. Seems I need to dive possibly into shaders... :)
     
  11. boxy

    boxy

    Joined:
    Aug 10, 2005
    Posts:
    675
    I was just looking for something exactly like this. I wanted lightbloom only on the face of a rock or roof which faces the sun. I am just now half wondering whether it could be achieved with particles...hmmm
    Cheers
    Boxy
     
  12. blikstad

    blikstad

    Joined:
    Nov 3, 2007
    Posts:
    37
    Okay, got it all working.

    Did something very similar to what yoggy suggested, here's my shader;

    Code (csharp):
    1.  
    2. Shader "Alpha Override" {
    3.     Properties
    4.     {
    5.         _Color ("Main Color", Color) = (1,1,1,1)
    6.         _GlowMap ("Glow (A)", 2D) = "bump" {}
    7.     }
    8.     Category
    9.     {
    10.         Tags {"Queue" = "Transparent" }
    11.         SubShader
    12.         {
    13.                 Pass
    14.             {                  
    15.                 ZWrite Off
    16.                     Offset -1, -1
    17.                     Cull Back
    18.                 Colormask A
    19.                 SetTexture [_GlowMap]
    20.                 {
    21.                     constantColor [_Color]
    22.                     combine constant, texture * constant
    23.                 }
    24.  
    25.                 }
    26.         }
    27.     }
    28. }
    29.  

    Basically just make a copy of the object (or actually you only need JUST the polygons that need glow) and apply this shader. I have all my materials set to Bumped Specular and store the "glow map" in the bump maps alpha. Apply this shader to the copy and drag the bump map over to the "glow map". There you go. Separated specular and glow controls!
     
  13. grojguy

    grojguy

    Joined:
    Jul 13, 2009
    Posts:
    35
    I hope it is OK to resurrect here...
    This object-based glow shader is just what I need, but I'm not clear on how to correctly implement it. I'll shamefully admit I've not delved into shaders yet (but will after this current deadline). For now, I just need to (hopefully) leverage some expertise here.

    I've read blikstad's explanation. The problem is, I do not yet have the shader understanding to know the "why" and therefore am likely missing something(s). I've excerpted individual steps from blikstad's explanation above, then listed my attempt to follow...

    1. I create a Cube, and duplicate it as Cube copy ... OK, easy

    Does "all materials" mean the Cube's materials and the Cube copy's material?
    2. I set Cube to a new material with Bumped Specular shader Is this correct?

    What does this mean? Bump Specular shader has "Base(RGB) Gloss(A)" and "Bumpmap(RGB)" textures...what is "bump maps alpha" ?
    3. I guessed here - I set Bumpmap to a bumpmap texture

    4. Select a new material for Cube copy, then set it to use this shader ("Alpha Override"), then set "Glow(A)" texture to a bumpmap. ... OK, got that

    Not surprisingly, my attempt does not work - I see no visual effect.
    Perhaps I am using an invalid glowmap/bumpmap? What properties are needed for the glowmap/bumpmap to accomplish the glow?
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you using the full-screen glow effect? The shader is for use in combination with that, so you can better control what glows and what doesn't...you're not going to get a glow effect with the shader alone.

    --Eric
     
  15. grojguy

    grojguy

    Joined:
    Jul 13, 2009
    Posts:
    35
    Aah, OK now I understand. Thank you Eric. I totally missed the point there.

    Ultimately what I need is to make an object glow uniformly on all faces. I was just about to ask how to do this, but then I did a search for self-illuminating shaders, and it looks like that might be a solution. I am now examining exactly how those work.

    However, I believe there is still the issue of uniform glow on all faces. All faces do glow evenly with the self-illum shader and no external light source. But add an external light and glow is additive and thus still brighter on faces facing towards the light.

    I could put the glow objects on a different layer not affected by the scene lighting, but that could have other complications. What about a shader that nullifies or normalizes the effect of external lighting? Or am I thinking incorrectly there? Perhaps modify a Self-Illum shader or this Alpha Override shader? Would that be considered an efficient solution, or is there a more render-efficient approach?
     
  16. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I think there's still some confusion in this thread as to how the glow effect works. As Jonathan said, most built-in shaders allow you to change the glow on a per-texel basis using the alpha channel of the main texture, and modulate it using the main colour's alpha (just like you can modulate the colour of the whole object).

    The only time you need a special shader is when you have a shader that uses its texture alpha channel for something else. Usually, these shaders do not write to the screen's alpha, and so you can do one of two things:

    • 1. Add a pass (and possibly a source texture) to the shader in that writes alpha to the screen.
      2. Duplicate the geometry you want to glow, and use an alpha-only shader, such as "Fire zee alpha" from above, or something that gives you a source texture.