Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Occlude Lens Flare by Render Geometry (without collider)

Discussion in 'General Graphics' started by djweinbaum, Jan 16, 2015.

  1. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Does anyone know of any clever ways for having a lens flare culled by normal render geometry rather than just collision? Perhaps a custom shader or something? I know a lot of other engines do it somehow. The reason I'm looking to do this is because I don't want to author intricate collision for things way out of the players reach.
     
  2. jistyles

    jistyles

    Joined:
    Nov 6, 2013
    Posts:
    34
    Usually it's done by harware occlusion queries. For a high level description and some proposed integration suggestions, see:
    http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter06.html

    tl;dr summary:
    To my knowledge unity has no interface to use hardware occlusion queries.

    tl;dr description:
    you submit basic geometry to the gpu which renders it against the z buffer and records the number of rejected pixels. The next frame the cpu can read this data back and you can use the information; traditionally this is culling geometry when it's occluded by other things (eg, a room behind a closed door), but it's also useful for effects like lens flare's since you can figure out how much of your proxy area was visible or not.

    So as I mentioned above, to my knowledge unity has no interface to use hardware occlusion queries, and unfortunately there's no other fast way to get read-back on the cpu. There are alternatives involving manual cpu read-back, or gpu only depth test->write->vertex read, but these can be slow and/or a decent amount of effort to implement.
     
  3. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Ah, darn. I'm afraid I'm not up to those tasks. Well, I really appreciate your answer. Its good to know for certain. I guess I'll stick to authoring collision all over the place.