Skip to content

Commit f573109

Browse files
sankheshkwrobot
authored andcommitted
Merge topic 'oit_msaa'
584e289 Add release note for the new UseOIT flag 2f293a0 Add a test for vtkRenderer::UseOIT 2109b3c Add an option to toggle using OIT for translucent actors Acked-by: Kitware Robot <[email protected]> Tested-by: buildbot <[email protected]> Reviewed-by: Lucas Gandel <[email protected]> Acked-by: Lucas Givord <[email protected]> Merge-request: !12001
2 parents cd19f92 + 584e289 commit f573109

File tree

7 files changed

+135
-16
lines changed

7 files changed

+135
-16
lines changed
2.62 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Add UseOIT flag to vtkRenderer
2+
3+
`vtkRenderer` now has a new flag (`UseOIT`) to toggle the use of the new
4+
`vtkOrderIndependentTranslucentPass` (OIT) for rendering translucent polygonal geometry. This flag
5+
is enabled by default which means the renderer uses OIT by default.
6+
7+
OIT is a newer approach to translucent rendering that yields better results without any performance
8+
trade-offs. However, this conflicts with other features of the vtkRenderer, namely MSAA based
9+
anti-aliasing. If you would like to use MSAA for anti-aliasing in a scene with translucent geometry,
10+
it is best to disable `UseOIT`.
11+
12+
The following pair of images show the use of this flag.
13+
14+
|MultiSamples: 8, UseOIT: True|MultiSamples: 8, UseOIT: False|
15+
|:--:|:--:|
16+
|i.e. MSAA with OIT |i.e. MSAA without OIT |
17+
|![](./OIT_with_MSAA.png)|![](https://vtk.org/files/ExternalData/SHA512/b5dce5a56db0d685c638e3383536bcbb1cbf0b71040989c7fad040f221f4527f761d7cd22c7e4dd63aaf368cc236e366d37c4832b07f59f50b6928d223f7da9e)|

Rendering/Core/Testing/Cxx/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ vtk_add_test_cxx(vtkRenderingCoreCxxTests tests
9595
TestOffAxisStereo.cxx
9696
TestOnAndOffScreenConeCxx.cxx
9797
TestOpacity.cxx
98+
TestOpacityMSAA.cxx
9899
TestOrderedTriangulator.cxx
99100
TestOSConeCxx.cxx
100101
TestPickingManager.cxx,NO_VALID
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
/**
5+
* This test covers rendering of translucent geometry along with anti-aliasing using MSAA
6+
*/
7+
8+
#include "vtkActor.h"
9+
#include "vtkCamera.h"
10+
#include "vtkConeSource.h"
11+
#include "vtkNew.h"
12+
#include "vtkPolyDataMapper.h"
13+
#include "vtkProperty.h"
14+
#include "vtkRegressionTestImage.h"
15+
#include "vtkRenderWindow.h"
16+
#include "vtkRenderWindowInteractor.h"
17+
#include "vtkRenderer.h"
18+
#include "vtkTesting.h"
19+
20+
int TestOpacityMSAA(int argc, char* argv[])
21+
{
22+
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
23+
24+
vtkNew<vtkConeSource> c1;
25+
c1->SetResolution(1);
26+
c1->SetCenter(-0.5, 0, 0);
27+
c1->SetRadius(1.3);
28+
vtkNew<vtkPolyDataMapper> m1;
29+
m1->SetInputConnection(c1->GetOutputPort());
30+
vtkNew<vtkActor> a1;
31+
a1->SetMapper(m1);
32+
33+
vtkNew<vtkConeSource> c2;
34+
c2->SetResolution(1);
35+
c2->SetCenter(0.5, 0, 0);
36+
c2->SetRadius(1.3);
37+
c2->SetDirection(-1, 0, 0);
38+
vtkNew<vtkPolyDataMapper> m2;
39+
m2->SetInputConnection(c2->GetOutputPort());
40+
vtkNew<vtkActor> a2;
41+
a2->SetMapper(m2);
42+
a2->GetProperty()->SetOpacity(0.5);
43+
44+
vtkNew<vtkRenderWindow> renWin;
45+
renWin->SetMultiSamples(8); // enable multisampling
46+
renWin->SetSize(301, 300); // Intentional NPOT size
47+
48+
vtkNew<vtkRenderer> ren;
49+
ren->AddActor(a1);
50+
ren->AddActor(a2);
51+
renWin->AddRenderer(ren);
52+
ren->ResetCamera();
53+
ren->GetActiveCamera()->Roll(4);
54+
ren->SetUseOIT(false); // disable OIT pass
55+
56+
vtkNew<vtkRenderWindowInteractor> iren;
57+
iren->SetRenderWindow(renWin);
58+
59+
renWin->Render();
60+
int retVal = vtkRegressionTestImage(renWin);
61+
if (retVal == vtkRegressionTester::DO_INTERACTOR)
62+
{
63+
iren->Start();
64+
}
65+
66+
return !retVal;
67+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b5dce5a56db0d685c638e3383536bcbb1cbf0b71040989c7fad040f221f4527f761d7cd22c7e4dd63aaf368cc236e366d37c4832b07f59f50b6928d223f7da9e

Rendering/Core/vtkRenderer.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,23 @@ class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO vtkRenderer : public vtkViewport
917917
vtkSetVector3Macro(EnvironmentRight, double);
918918
///@}
919919

920+
///@{
921+
/**
922+
* If UseOIT is on and there are translucent props in the scene, the renderer will use the
923+
* OrderIndependentTranslucentPass to render. If UseOIT is disabled, traditional depth sorting is
924+
* used for translucency.
925+
* By default, UseOIT is on.
926+
*
927+
* \note OIT is a newer(better) approach for translucent rendering but doesn't support hardware
928+
* multi-sampling. Use FXAA in that case.
929+
*
930+
* \sa SetUseFXAA()
931+
*/
932+
vtkSetMacro(UseOIT, bool);
933+
vtkGetMacro(UseOIT, bool);
934+
vtkBooleanMacro(UseOIT, bool);
935+
///@}
936+
920937
protected:
921938
vtkRenderer();
922939
~vtkRenderer() override;
@@ -1139,6 +1156,19 @@ class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO vtkRenderer : public vtkViewport
11391156
unsigned int SSAOKernelSize = 32;
11401157
bool SSAOBlur = false;
11411158

1159+
/**
1160+
* If UseOIT is on and there are translucent props in the scene, the renderer will use the
1161+
* OrderIndependentTranslucentPass to render. If UseOIT is disabled, traditional depth sorting is
1162+
* used for translucency.
1163+
* By default, UseOIT is on.
1164+
*
1165+
* \note OIT is a newer(better) approach for translucent rendering but doesn't support hardware
1166+
* multi-sampling. Use FXAA in that case.
1167+
*
1168+
* \sa SetUseFXAA()
1169+
*/
1170+
bool UseOIT = true;
1171+
11421172
/**
11431173
* Tells if the last call to DeviceRenderTranslucentPolygonalGeometry()
11441174
* actually used depth peeling.

Rendering/OpenGL2/vtkOpenGLRenderer.cxx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -629,25 +629,28 @@ void vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry(vtkFrameBufferO
629629

630630
if (!this->UseDepthPeeling)
631631
{
632-
// old code
633-
// this->UpdateTranslucentPolygonalGeometry();
634-
635-
// new approach
636-
if (!this->TranslucentPass)
632+
if (!this->UseOIT)
637633
{
638-
vtkOrderIndependentTranslucentPass* oit = vtkOrderIndependentTranslucentPass::New();
639-
this->TranslucentPass = oit;
634+
this->UpdateTranslucentPolygonalGeometry();
640635
}
641-
vtkTranslucentPass* tp = vtkTranslucentPass::New();
642-
this->TranslucentPass->SetTranslucentPass(tp);
643-
tp->Delete();
636+
else
637+
{
638+
if (!this->TranslucentPass)
639+
{
640+
vtkOrderIndependentTranslucentPass* oit = vtkOrderIndependentTranslucentPass::New();
641+
this->TranslucentPass = oit;
642+
}
643+
vtkTranslucentPass* tp = vtkTranslucentPass::New();
644+
this->TranslucentPass->SetTranslucentPass(tp);
645+
tp->Delete();
644646

645-
vtkRenderState s(this);
646-
s.SetPropArrayAndCount(this->PropArray, this->PropArrayCount);
647-
s.SetFrameBuffer(fbo);
648-
this->LastRenderingUsedDepthPeeling = 0;
649-
this->TranslucentPass->Render(&s);
650-
this->NumberOfPropsRendered += this->TranslucentPass->GetNumberOfRenderedProps();
647+
vtkRenderState s(this);
648+
s.SetPropArrayAndCount(this->PropArray, this->PropArrayCount);
649+
s.SetFrameBuffer(fbo);
650+
this->LastRenderingUsedDepthPeeling = 0;
651+
this->TranslucentPass->Render(&s);
652+
this->NumberOfPropsRendered += this->TranslucentPass->GetNumberOfRenderedProps();
653+
}
651654
}
652655
else // depth peeling.
653656
{

0 commit comments

Comments
 (0)