Search Unity

Is there any way to read scene geometry/ triangle list from vertex/ fragment shader?

Discussion in 'Shaders' started by whynotme, Jan 4, 2014.

  1. whynotme

    whynotme

    Joined:
    Mar 24, 2012
    Posts:
    54
    I read that there is screen space ray tracing, how do people do that, use shader or CPU?

    I want to cast ray in shader, and I think since GPU must store geometry somewhere, is there any way to read that data from fragment shader?

    Regards
     
  2. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
  3. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Screen space ray tracing does not use any geometry information. The only data it uses is the screen space per-pixel depth. With that, you can roughly recreate the currently visible scene. These algorithms have the obvious downside that anything outside of your field of view or anything hidden behind another object does not contribute to the result, because you have no information about it.

    If you want to go on full ray tracing, you should be able to access the VBOs with a CPU and then pass them as structured buffers into your shader / compute shader. That of course requires dx11.
     
  4. whynotme

    whynotme

    Joined:
    Mar 24, 2012
    Posts:
    54
    Thanks
     
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I think its kind of up to you what you do in screenspace and whether or not you deal with geometry on your own. Basic raytracing would have you fire a ray at each pixel fragment into the screen Z, and then traverse some data structure containing `objects`, and then possibly also bounce the ray around in the data structure to do reflections/shadows etc. It's up to you how far you take it. I've seen screen-space metaballs which fires rays to collide with a dynamic object surface. You could store your geometry in a custom structure in a texture and then traverse through that structure to find surfaces etc.