Author Topic: Image effect for GUI layer works with UILabels only. What does wrong?  (Read 5079 times)

Lex_87

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Hi everyone  :)

I want to use image effect (e.g. bloom) for only for the single of several Camera layers which contents GUI.

But as a result i have processed UILabels only:


Implementation:

I use two cameras. First camera clears alpha to apply image effect to last layer only.

 ??? Wherein: If i did not apply clear alpha script for the first camera then i have image effect for the whole screenspace like this:


Second camera does image effect for own layer.

Scene hierarchy:
- UIRoot
-- UICamera (layer 1) [clear alpha shader]
--- UIWidgets
--- ...
--- ...
-- UICamera (layer 2) [image effect script]
--- UIWidgets <- Here must be bloomed whole content of this layer but it works with UILabels only
--- ...
--- ...

Clear alpha shader is:
  1. Shader ""ClearAlpha"" {
  2.         SubShader {
  3.                 ColorMask A
  4.                 ZTest Always Cull Off ZWrite Off Fog { Mode Off }
  5.                 Pass { Color (0,0,0,0) }
  6.         }
  7.  
  8.         Fallback off
  9. }
  10.  


OnRenderImage method of the clear alpha script:
  1.         void OnRenderImage (RenderTexture source, RenderTexture destination) {
  2.                 Graphics.Blit (source, destination, material);
  3.         }
  4.  

OnRenderImage method of the image effect script:
  1.         void OnRenderImage (RenderTexture source, RenderTexture destination)
  2.         {
  3.                 amount = Mathf.Sin (Time.fixedTime);
  4.                 material.SetFloat("_Amount", amount);
  5.                 Graphics.Blit (source, destination, material);
  6.         }
  7.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Image effect for GUI layer works with UILabels only. What does wrong?
« Reply #1 on: February 19, 2014, 03:38:23 PM »
Not sure which bloom you're using, but a typical Bloom effect takes all color above the specified threshold and blurs it, then applies it on top of the original image.

Label is the only thing white in your screenshot, so likely the only thing that exceeds the set threshold.

If you're using Unity's old-school bloom effect, then it's even worse. That one does blooming based on the values of the alpha channel, and is only meant for solid objects (objects with no transparency), which happens to exclude UI as all UI elements have transparency.

Lex_87

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Image effect for GUI layer works with UILabels only. What does wrong?
« Reply #2 on: February 20, 2014, 12:45:44 AM »
Hmm.. no! It is my custom bloom with soft threshold of bright pass through all color dynamics from the darkness to brightness.

(Possible that equals of that worst old school bloom, haha :) )

Image 2/2 in a first post of this topic demonstrates that bloom threshold affects on an orange widget. Image 1/2 demonstrates that something does wrong.

I want to bloom with soft threshold orange widget, UILabel above them and blue transparent window. All these widgets are rendered by camera with image effect.
Blue bottle, background and content of the another screenspace I do not want to bloom.
 
Instead of what i want I have either whole screenspace effect or bloomed UILabels only.
« Last Edit: February 20, 2014, 01:30:15 AM by Lex_87 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Image effect for GUI layer works with UILabels only. What does wrong?
« Reply #3 on: February 20, 2014, 09:50:00 AM »
You can't do what you're trying to do this way.

Reason being, the UI is drawn on top of what's already there -- your world. When you bloom it, you bloom everything that came before it. You can't selectively bloom only the UI unless you draw the UI into a separate render target.

Lex_87

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Image effect for GUI layer works with UILabels only. What does wrong?
« Reply #4 on: February 20, 2014, 10:22:47 AM »
I lose my hope...

But what is it?
With 3D geometry it works fine.
http://forum.unity3d.com/threads/141870-Apply-post-processing-image-effects-to-specific-camera-layer

What separates NGUI from World geometry in this case?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Image effect for GUI layer works with UILabels only. What does wrong?
« Reply #5 on: February 20, 2014, 10:31:55 AM »
From that post:
Quote
Image effects apply always to the current content on screen, which includes any pixels rendered with another camera before.
However, some effects like "glow" are using the alpha channel as mask. So all you have to do is clear the alpha channel, either by not writing it in the first place or by clearing it afterwards.
As I was explaining -- solid objects, alpha is used to "mark" areas of the screen. But NGUI already uses alpha for transparency.

You could probably use the stencil buffer to mark certain areas of the screen for bloom effect, but I really can't advise you much there as it's not an NGUI question at all. I would suggest asking on Unity's forums or answers page.

Lex_87

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Image effect for GUI layer works with UILabels only. What does wrong?
« Reply #6 on: February 21, 2014, 03:19:35 AM »
Thank you for a good idea!