Commit 6f7937e8 authored by Michael Migliore's avatar Michael Migliore

Add FXAA Pass for multipass rendering

parent 72e216b7
Pipeline #135176 passed with stage
......@@ -29,6 +29,7 @@ set(classes
vtkOpenGLCamera
vtkOpenGLCellToVTKCellMap
vtkOpenGLFXAAFilter
vtkOpenGLFXAAPass
vtkOpenGLFramebufferObject
vtkOpenGLGL2PSHelper
vtkOpenGLGlyph3DHelper
......
......@@ -16,6 +16,7 @@ vtk_add_test_cxx(vtkRenderingOpenGL2CxxTests tests
TestFramebufferPass.cxx
TestFramebufferHDR.cxx
TestFXAAFilter.cxx
TestFXAAPass.cxx
TestGaussianBlurPass.cxx
TestGlyph3DMapperEdges.cxx
TestGlyph3DMapperCellPicking.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
//
// This test is unlikely to fail if FXAA isn't working, but can be used to
// quickly check the same scene with/without FXAA enabled.
//
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCameraPass.h"
#include "vtkConeSource.h"
#include "vtkCylinderSource.h"
#include "vtkDefaultPass.h"
#include "vtkDiskSource.h"
#include "vtkLightsPass.h"
#include "vtkLineSource.h"
#include "vtkNew.h"
#include "vtkOpenGLFXAAPass.h"
#include "vtkOpenGLRenderer.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderPassCollection.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSequencePass.h"
#include "vtkSphereSource.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
namespace
{
void BuildRenderer(vtkRenderer* renderer, int widthBias)
{
const size_t NUM_LINES = 10;
vtkNew<vtkLineSource> lines[NUM_LINES];
vtkNew<vtkPolyDataMapper> mappers[NUM_LINES];
vtkNew<vtkActor> actors[NUM_LINES];
for (size_t i = 0; i < NUM_LINES; ++i)
{
double c = static_cast<double>(2 * i) / static_cast<double>(NUM_LINES - 1) - 1.;
lines[i]->SetPoint1(-1, c, 0.);
lines[i]->SetPoint2(1, -c, 0.);
mappers[i]->SetInputConnection(lines[i]->GetOutputPort());
actors[i]->SetMapper(mappers[i]);
actors[i]->GetProperty()->SetColor(0., 1., 0.);
actors[i]->GetProperty()->SetRepresentationToWireframe();
actors[i]->GetProperty()->SetLineWidth(((i + widthBias) % 2) ? 1 : 3);
renderer->AddActor(actors[i]);
}
vtkNew<vtkSphereSource> sphere;
sphere->SetCenter(0., 0.6, 0.);
sphere->SetThetaResolution(80);
sphere->SetPhiResolution(80);
sphere->SetRadius(0.4);
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphere->GetOutputPort());
vtkNew<vtkActor> sphereActor;
sphereActor->SetMapper(sphereMapper);
sphereActor->GetProperty()->SetColor(0.9, 0.4, 0.2);
sphereActor->GetProperty()->SetAmbient(.6);
sphereActor->GetProperty()->SetDiffuse(.4);
renderer->AddActor(sphereActor);
vtkNew<vtkConeSource> cone;
cone->SetCenter(0., 0.5, -0.5);
cone->SetResolution(160);
cone->SetRadius(.9);
cone->SetHeight(0.9);
cone->SetDirection(0., -1., 0.);
vtkNew<vtkPolyDataMapper> coneMapper;
coneMapper->SetInputConnection(cone->GetOutputPort());
vtkNew<vtkActor> coneActor;
coneActor->SetMapper(coneMapper);
coneActor->GetProperty()->SetColor(0.9, .6, 0.8);
coneActor->GetProperty()->SetAmbient(.6);
coneActor->GetProperty()->SetDiffuse(.4);
renderer->AddActor(coneActor);
vtkNew<vtkDiskSource> disk;
disk->SetCircumferentialResolution(80);
disk->SetInnerRadius(0);
disk->SetOuterRadius(0.5);
vtkNew<vtkPolyDataMapper> diskMapper;
diskMapper->SetInputConnection(disk->GetOutputPort());
vtkNew<vtkActor> diskActor;
diskActor->SetPosition(0., -0.5, -0.5);
diskActor->SetMapper(diskMapper);
diskActor->GetProperty()->SetColor(.3, .1, .4);
diskActor->GetProperty()->SetAmbient(.6);
diskActor->GetProperty()->SetDiffuse(.4);
renderer->AddActor(diskActor);
vtkNew<vtkCylinderSource> cyl;
cyl->SetCenter(0., -.5, 0.);
cyl->SetHeight(.6);
cyl->SetRadius(.2);
cyl->SetResolution(80);
vtkNew<vtkPolyDataMapper> cylMapper;
cylMapper->SetInputConnection(cyl->GetOutputPort());
vtkNew<vtkActor> cylActor;
cylActor->SetOrigin(cyl->GetCenter());
cylActor->RotateWXYZ(35, -0.2, 0., 1.);
cylActor->SetMapper(cylMapper);
cylActor->GetProperty()->SetColor(0.3, .9, .4);
cylActor->GetProperty()->SetAmbient(.6);
cylActor->GetProperty()->SetDiffuse(.4);
renderer->AddActor(cylActor);
renderer->SetBackground(0., 0., 0.);
renderer->GetActiveCamera()->ParallelProjectionOn();
renderer->ResetCamera();
renderer->ResetCameraClippingRange();
renderer->GetActiveCamera()->SetParallelScale(0.9);
}
} // end anon namespace
int TestFXAAPass(int argc, char* argv[])
{
vtkNew<vtkRenderWindowInteractor> iren;
vtkNew<vtkRenderWindow> renWin;
renWin->SetMultiSamples(0);
iren->SetRenderWindow(renWin);
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderer> rendererFXAA;
rendererFXAA->UseFXAAOn();
// custom passes
vtkNew<vtkCameraPass> cameraP;
vtkNew<vtkSequencePass> seq;
vtkNew<vtkDefaultPass> defaultP;
vtkNew<vtkLightsPass> lights;
vtkNew<vtkOpenGLFXAAPass> fxaa;
vtkNew<vtkRenderPassCollection> passes;
passes->AddItem(lights);
passes->AddItem(defaultP);
seq->SetPasses(passes);
cameraP->SetDelegatePass(seq);
fxaa->SetDelegatePass(cameraP);
vtkOpenGLRenderer::SafeDownCast(rendererFXAA)->SetPass(fxaa);
vtkNew<vtkTextActor> label;
label->SetInput("No FXAA");
label->GetTextProperty()->SetFontSize(20);
label->GetTextProperty()->SetJustificationToCentered();
label->GetTextProperty()->SetVerticalJustificationToBottom();
label->SetPosition(85, 10);
renderer->AddActor2D(label);
vtkNew<vtkTextActor> labelFXAA;
labelFXAA->SetInput("FXAA");
labelFXAA->GetTextProperty()->SetFontSize(20);
labelFXAA->GetTextProperty()->SetJustificationToCentered();
labelFXAA->GetTextProperty()->SetVerticalJustificationToBottom();
labelFXAA->SetPosition(85, 10);
rendererFXAA->AddActor2D(labelFXAA);
renderer->SetViewport(0., 0., .5, 1.);
BuildRenderer(renderer, 0);
renWin->AddRenderer(renderer);
rendererFXAA->SetViewport(.5, 0., 1., 1.);
BuildRenderer(rendererFXAA, 1);
renWin->AddRenderer(rendererFXAA);
renWin->SetSize(1000, 500);
renWin->Render();
int retVal = vtkRegressionTestImage(renWin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
502b35dc60b17bed39f78ddf1c77d14cb9cef116de21874decf8a5c265803eb6b900e965d846c14793186b8f86a0e4089a3f82636904ae5fe9646e31eef2102d
#include "vtkOpenGLFXAAPass.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLState.h"
#include "vtkRenderState.h"
vtkStandardNewMacro(vtkOpenGLFXAAPass);
// ----------------------------------------------------------------------------
void vtkOpenGLFXAAPass::Render(const vtkRenderState* s)
{
vtkOpenGLRenderer* r = vtkOpenGLRenderer::SafeDownCast(s->GetRenderer());
vtkOpenGLRenderWindow* renWin = vtkOpenGLRenderWindow::SafeDownCast(r->GetRenderWindow());
vtkOpenGLState* ostate = renWin->GetState();
vtkOpenGLState::ScopedglEnableDisable dsaver(ostate, GL_DEPTH_TEST);
int x, y, w, h;
r->GetTiledSizeAndOrigin(&w, &h, &x, &y);
ostate->vtkglViewport(x, y, w, h);
ostate->vtkglScissor(x, y, w, h);
if (this->DelegatePass == nullptr)
{
vtkWarningMacro("no delegate in vtkOpenGLFXAAPass.");
return;
}
this->DelegatePass->Render(s);
this->NumberOfRenderedProps = this->DelegatePass->GetNumberOfRenderedProps();
if (r->GetFXAAOptions())
{
this->FXAAFilter->UpdateConfiguration(r->GetFXAAOptions());
}
this->FXAAFilter->Execute(r);
}
// ----------------------------------------------------------------------------
void vtkOpenGLFXAAPass::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLFXAAPass.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkOpenGLFXAAPass
* @brief Render pass calling the FXAA filter
*
* vtkOpenGLFXAAPass is an image post processing render pass. It is a fast anti aliasing
* filter.
*
* This pass usually takes the camera pass as its delegate pass.
*
* @note Currently, this pass wraps the existing FXAA implementation. It copies the pixels
* from the framebuffer to a texture. A better approach would be to use the usual render pass
* workflow to create a framebuffer drawing directly on the texture.
*
* @sa
* vtkRenderPass vtkDefaultPass
*/
#ifndef vtkOpenGLFXAAPass_h
#define vtkOpenGLFXAAPass_h
#include "vtkImageProcessingPass.h"
#include "vtkNew.h" // For vtkNew
#include "vtkOpenGLFXAAFilter.h" // For vtkOpenGLFXAAFilter
#include "vtkRenderingOpenGL2Module.h" // For export macro
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLFXAAPass : public vtkImageProcessingPass
{
public:
static vtkOpenGLFXAAPass* New();
vtkTypeMacro(vtkOpenGLFXAAPass, vtkImageProcessingPass);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Perform rendering according to a render state.
*/
void Render(const vtkRenderState* s) override;
protected:
vtkOpenGLFXAAPass() = default;
~vtkOpenGLFXAAPass() override = default;
/**
* Graphics resources.
*/
vtkNew<vtkOpenGLFXAAFilter> FXAAFilter;
private:
vtkOpenGLFXAAPass(const vtkOpenGLFXAAPass&) = delete;
void operator=(const vtkOpenGLFXAAPass&) = delete;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment