Search Unity

optimized way to render occludable flare(mobile)?

Discussion in 'Shaders' started by colin299, May 22, 2017.

  1. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    181
    flare = billboard tight mesh with Ztest always,
    writing a non occludable flare shader is very simple.

    The hard part is, how to occlude flare with minimum performance cost?
    I tried 2 approaches to correctly occlude flare,

    #1 occlude flare purely in CPU, by adding collider to every possible occluder & raycast from camera to flare's center to determine flare occlusion.


    -need additional collider setup per object
    -performance = scene complexity(# of flare occluder colliders)
    -can disable rendering if flare is fully occluded(still you need to pay the occlusion test cost)
    -do not rely on depth texture
    -dynamic batchable flares
    -fake smooth flare intensity at position where occlusion start /end, by adding constant short fade in / out time, so flare don't "pop out"

    because this method only works on simple shape(collider), and we want our characters to occlude flare, we end up not consider this method
    ------------------------------------------------------
    #2 occlude flare purely in GPU, by reading depth texture & compare to flare's center's depth(all in view space)


    -need depth info texture
    -pixel correct flare(alpha test object can occlude flare as well)
    -extra texture read(depth texture) in flare shader

    this is the approach we are using.

    *#2 approach needs depth texture and usually getting depth texture on mobile is costly, but #2 approach can be quite fast, if - when you normally renders your opaque objects, you additionally render all opaque object's depth in RenderTarget's alpha channel.
    But because our game needs alpha blending, and alpha blending pass will "pollute" the depth info already in alpha channel, so we tried to make alpha blending pass not "pollute" depth info in alpha by forcing all alpha blending shader adding ColorMask rgb, but according to Unity & my experience, only ColorMask 0 will improve performance(usually used in z-pre pass), while ColorMask rgb actually have much more performance cost on mobile.(not very sure about ColorMask performance cost on mobile, I just have some very rough test on this, I can't see any performance difference between using ColorMask rgb & without ColorMask at all)
    ---------------------------------------------------------

    So, my questions are:
    Q1.is there any better way to render flare other than my #1 CPU method / #2 GPU method?
    Q2.is ColorMask rgb really bad on mobile? I am not very sure about this, only Unity said that it is bad for mobile, I can't find any other information about ColorMask rgb 's performance impact on mobile (Aras mentioned, ColorMask rgb will always be slower than NOT applying any ColorMask, but is it worth it if we can get a free depth texture by adding ColorMask rgb to all our alpha blend shader?)

    thanks.
     
    Last edited: May 22, 2017
    celikomerdev likes this.