[vtk-developers] vtk-developers Digest, Vol 143, Issue 30

Brad Hollister behollis at sci.utah.edu
Thu Mar 24 13:08:04 EDT 2016


This should help. However, it looks like depth peeling isn't being 
enable regardless of using custom shaders.

I just saw this old email thread:

http://www.vtk.org/pipermail/vtkusers/2010-August/062106.html

We're using QVTK / Python bindings. Is there a problem with depth 
peeling and the Python modules?

Regards,
Brad

> Date: Thu, 24 Mar 2016 08:26:30 -0400
>From: Ken Martin <ken.martin at kitware.com>
> To: Brad Hollister <behollis at sci.utah.edu>
> Cc: VTK Developers <vtk-developers at vtk.org>
> Subject: Re: [vtk-developers] transparent foreground polygons
> 	occluding background geometry
> Message-ID:
> 	<CANXz0Sb_qKZkgny0eymo6xZJuw-w653VtP0nr843NR7MAQ8V9A at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> Your custom shader has to be written to work with depth peeling. 
>When in a
> depth peeling pass it needs to do some texture lookups and discard
> fragments based on those lookups. I've included the general gist 
>below. I
> use string replacements to handle it but you are free to use other
> approaches as long as the end result in a depth peeling pass has 
>something
> like the following in it.
> 
> Thanks
> Ken
> 
>  // are we using depth peeling?
>  vtkInformation *info = actor->GetPropertyKeys();
>  if (info && info->Has(vtkDepthPeelingPass::OpaqueZTextureUnit()))
>    {
>    vtkShaderProgram::Substitute(FSSource, 
>"//VTK::DepthPeeling::Dec",
>      "uniform vec2 screenSize;\n"
>      "uniform sampler2D opaqueZTexture;\n"
>      "uniform sampler2D translucentZTexture;\n");
>    // the .0000001 below is an epsilon.  It turns out that
>    // graphics cards can render the same polygon two times
>    // in a row with different z values. I suspect it has to
>    // do with how rasterization of the polygon is broken up.
>    // A different breakup across fragment shaders can result in
>    // very slightly different z values for some of the pixels.
>    // The end result is that with depth peeling, you can end up
>    // counting/accumulating pixels of the same surface twice
>    // simply due to this randomness in z values. So we introduce
>    // an epsilon into the transparent test to require some
>    // minimal z separation between pixels
>    vtkShaderProgram::Substitute(FSSource, 
>"//VTK::DepthPeeling::Impl",
>      "float odepth = texture2D(opaqueZTexture,
> gl_FragCoord.xy/screenSize).r;\n"
>      "  if (gl_FragCoord.z >= odepth) { discard; }\n"
>      "  float tdepth = texture2D(translucentZTexture,
> gl_FragCoord.xy/screenSize).r;\n"
>      "  if (gl_FragCoord.z <= tdepth + .0000001) { discard; }\n"
> 
> 
> 
> 
> On Wed, Mar 23, 2016 at 7:08 PM, Brad Hollister 
><behollis at sci.utah.edu>
> wrote:
> 
>> Hi,
>>
>> We have a problem with transparent foreground polys occluding 
>>geometry.
>>
>> We're trying to use depth peeling to handle foreground polygons with
>> transparency. However, while depth peeling is enabled,
>> GetLastRenderingUsedDepthPeeling() returns false.
>>
>> (The polygons also intersect other similar polygons so that some 
>>parts of
>> them are in front of others, while other parts of the same poly may 
>>be
>> behind others. Another reason to use depth peeling as opposed to 
>>depth
>> sorting, in our opinion.)
>>
>> We also require custom shaders, using
>> vtkOpenGLPolyDataMapper::SetVertexShader(), etc. From the test code 
>>@
>> http://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Rendering/OpenGL2/Testing/Cxx/TestUserShader2.cxx,
>> it looks as though custom shaders can't be used with depth peeling 
>>in VTK.
>>
>> Thus, is there another way to enable depth peeling or to have 
>>transparent
>> foreground polys in our usage scenario?
>>
>> Regards,
>> Brad
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Search the list archives at: 
>>http://markmail.org/search/?q=vtk-developers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtk-developers
>>
>>
> 
> 
> -- 
> Ken Martin PhD
> Chairman & CFO
> Kitware Inc.
> 28 Corporate Drive
> Clifton Park NY 12065
> 518 371 3971


More information about the vtk-developers mailing list