Jump to content

Depth buffer in UUSL


photo

Recommended Posts

Posted

I can't seem to figure out how to access the depth buffer in UUSL in my fragment shader. Is it possible to do? I want to get a Z value for a pixel

Posted

Hi Angus,

 

Getting the depth buffer is depends on task that you are trying to achieve.

 

  1. If you are trying to read depth in deferred pass - it's not possible in DX11 / OpenGL render, you will get black texture.
  2. In Forward (Ambient pass) you can get access to the opacity depth buffer: opacity_depth texture. You can check the usage in unigine_particles.mat:
    <texture unit="11" type="opacity_depth" volume="1"/>
    

    and corresponding fragment shader (core/shaders/particles/fragment/ambient.frag):

    INIT_TEXTURE(11,TEX_DEPTH)
  3. For post processing you can get access to the current_depth (transparent + opacity depth) and opacity_depth textures.

 

 

Simple reading from TEX_DEPTH texture will return native depth (as stored on GPU) in R channel. 

getLinearizedDepth(TEX_DEPTH, SCREEN_UV) will return depth in [0, far_plane] range and multiplying by s_depth_range.w will give you normalized depth in [0..1] interval (you can check this calculations in core/shaders/particles/fragment/ambient.frag shader).

 

Thanks!

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

×
×
  • Create New...