Commit 71787eba authored by Michael Migliore's avatar Michael Migliore Committed by Kitware Robot

Merge topic 'env-proj'

4a842da9 Add a panoramic projection pass
0857be6f Add an optional user light transformation
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Mathieu Westphal's avatarMathieu Westphal <mathieu.westphal@kitware.com>
Merge-request: !4709
parents ac9c897b 4a842da9
......@@ -71,6 +71,7 @@ set(Module_SRCS
vtkOpenGLVertexBufferObjectGroup.cxx
vtkOrderIndependentTranslucentPass.cxx
vtkOverlayPass.cxx
vtkPanoramicProjectionPass.cxx
vtkPixelBufferObject.cxx
vtkPointFillPass.cxx
vtkRenderPassCollection.cxx
......
......@@ -26,6 +26,7 @@ vtk_add_test_cxx(vtkRenderingOpenGL2CxxTests tests
TestMultiTexturing.cxx
TestOffscreenRenderingResize.cxx
TestOrderIndependentTranslucentPass.cxx
TestPanoramicProjectionPass.cxx,NO_DATA
TestPointFillPass.cxx
TestPointGaussianSelection.cxx,NO_DATA
TestPropPicker2Renderers.cxx,NO_DATA
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestPanoramicProjectionPass.cxx
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 covers the tone mapping post-processing render pass.
// It renders an opaque actor with a lot of lights.
#include "vtkRegressionTestImage.h"
#include "vtkTestUtilities.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCameraPass.h"
#include "vtkCullerCollection.h"
#include "vtkPanoramicProjectionPass.h"
#include "vtkLight.h"
#include "vtkLightsPass.h"
#include "vtkOpaquePass.h"
#include "vtkOpenGLRenderer.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderPassCollection.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSequencePass.h"
#include "vtkSphereSource.h"
int TestPanoramicProjectionPass(int argc, char* argv[])
{
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(400, 400);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
vtkNew<vtkSphereSource> sphere;
sphere->SetRadius(1.0);
vtkNew<vtkRenderer> renderer;
renderer->GetCullers()->RemoveAllItems();
renderer->SetBackground(1.0, 1.0, 1.0);
renderer->AutomaticLightCreationOff();
vtkNew<vtkLight> light;
light->SetPosition(0.0, 10.0, 0.0);
light->SetFocalPoint(0.0, 0.0, 0.0);
light->SetLightTypeToSceneLight();
renderer->AddLight(light);
// custom passes
vtkNew<vtkCameraPass> cameraP;
vtkNew<vtkSequencePass> seq;
vtkNew<vtkOpaquePass> opaque;
vtkNew<vtkLightsPass> lights;
vtkNew<vtkRenderPassCollection> passes;
passes->AddItem(lights);
passes->AddItem(opaque);
seq->SetPasses(passes);
cameraP->SetDelegatePass(seq);
vtkNew<vtkPanoramicProjectionPass> projectionP;
projectionP->SetProjectionTypeToAzimuthal();
projectionP->SetAngle(360.0);
projectionP->SetDelegatePass(cameraP);
vtkOpenGLRenderer::SafeDownCast(renderer)->SetPass(projectionP);
renWin->AddRenderer(renderer);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(sphere->GetOutputPort());
for (int i = 0; i < 4; i++)
{
double f = i & 1 ? -2.0 : 2.0;
double x = i & 2 ? 1.0 : 0.0;
double c[3] = { static_cast<double>((i + 1) & 1),
static_cast<double>(((i + 1) >> 1) & 1),
static_cast<double>(((i + 1) >> 2) & 1) };
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->SetPosition(f * x, 0.0, f * (1.0 - x));
actor->GetProperty()->SetColor(c);
renderer->AddActor(actor);
}
vtkNew<vtkCamera> camera;
camera->SetPosition(0.0, 0.0, 0.0);
camera->SetFocalPoint(0.0, 0.0, 1.0);
camera->SetViewUp(0.0, 1.0, 0.0);
renderer->SetActiveCamera(camera);
renWin->Render();
int retVal = vtkRegressionTestImage(renWin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
11e1f1020ba1c5681a90095c9cc2415c9d20c0ebff5941c352add3bd93d79404fbe87987aec172dc0e4f8e925c6323836beefcc75988ef912337ad9b2b4ea3a5
......@@ -983,10 +983,22 @@ void vtkOpenGLRenderer::UpdateLightingUniforms(vtkShaderProgram *program)
double lightDir[3];
vtkMath::Subtract(lfp,lp,lightDir);
vtkMath::Normalize(lightDir);
double *tDir = viewTF->TransformNormal(lightDir);
lightDirection[0] = tDir[0];
lightDirection[1] = tDir[1];
lightDirection[2] = tDir[2];
double tDirView[3];
viewTF->TransformNormal(lightDir, tDirView);
if (!light->LightTypeIsSceneLight() && this->UserLightTransform.GetPointer() != nullptr)
{
double *tDir = this->UserLightTransform->TransformNormal(tDirView);
lightDirection[0] = tDir[0];
lightDirection[1] = tDir[1];
lightDirection[2] = tDir[2];
}
else
{
lightDirection[0] = tDirView[0];
lightDirection[1] = tDirView[1];
lightDirection[2] = tDirView[2];
}
program->SetUniform3f((ldir + count).c_str(), lightDirection);
......@@ -1000,10 +1012,21 @@ void vtkOpenGLRenderer::UpdateLightingUniforms(vtkShaderProgram *program)
lightAttenuation[0] = attn[0];
lightAttenuation[1] = attn[1];
lightAttenuation[2] = attn[2];
double *tlp = viewTF->TransformPoint(lp);
lightPosition[0] = tlp[0];
lightPosition[1] = tlp[1];
lightPosition[2] = tlp[2];
double tlpView[3];
viewTF->TransformPoint(lp, tlpView);
if (!light->LightTypeIsSceneLight() && this->UserLightTransform.GetPointer() != nullptr)
{
double *tlp = this->UserLightTransform->TransformPoint(tlpView);
lightPosition[0] = tlp[0];
lightPosition[1] = tlp[1];
lightPosition[2] = tlp[2];
}
else
{
lightPosition[0] = tlpView[0];
lightPosition[1] = tlpView[1];
lightPosition[2] = tlpView[2];
}
program->SetUniform3f((latten + count).c_str(), lightAttenuation);
program->SetUniformi((lpositional + count).c_str(), light->GetPositional());
......@@ -1018,3 +1041,8 @@ void vtkOpenGLRenderer::UpdateLightingUniforms(vtkShaderProgram *program)
program->SetUniformGroupUpdateTime(vtkShaderProgram::LightingGroup, ltime);
}
void vtkOpenGLRenderer::SetUserLightTransform(vtkTransform* transform)
{
this->UserLightTransform = transform;
}
......@@ -25,6 +25,7 @@
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkRenderer.h"
#include "vtkSmartPointer.h" // For vtkSmartPointer
#include <vector> // STL Header
#include <string> // Ivars
......@@ -127,6 +128,12 @@ public:
// get the number of lights turned on
vtkGetMacro(LightingCount, int);
/**
* Set the user light transform applied after the camera transform.
* Can be null to disable it.
*/
void SetUserLightTransform(vtkTransform* transform);
protected:
vtkOpenGLRenderer();
~vtkOpenGLRenderer() override;
......@@ -187,6 +194,11 @@ protected:
int LightingCount;
vtkMTimeType LightingUpdateTime;
/**
* Optional user transform for lights
*/
vtkSmartPointer<vtkTransform> UserLightTransform;
private:
vtkOpenGLRenderer(const vtkOpenGLRenderer&) = delete;
void operator=(const vtkOpenGLRenderer&) = delete;
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPanoramicProjectionPass.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 vtkPanoramicProjectionPass
* @brief Render pass that render the scene in a cubemap and project
* these six renderings to a single quad.
* There are currently two differents projections implemented (Equirectangular and Azimuthal).
* This pass can be used to produce images that can be visualize with specific devices that re-maps
* the distorted image to a panoramic view (for instance VR headsets, domes, panoramic screens)
*
* Note that it is often necessary to disable frustum cullers in order to render
* properly objects that are behind the camera.
*
* @sa
* vtkRenderPass
*/
#ifndef vtkPanoramicProjectionPass_h
#define vtkPanoramicProjectionPass_h
#include "vtkImageProcessingPass.h"
#include "vtkRenderingOpenGL2Module.h" // For export macro
class vtkOpenGLFramebufferObject;
class vtkOpenGLQuadHelper;
class vtkTextureObject;
class VTKRENDERINGOPENGL2_EXPORT vtkPanoramicProjectionPass : public vtkImageProcessingPass
{
public:
static vtkPanoramicProjectionPass* New();
vtkTypeMacro(vtkPanoramicProjectionPass, vtkImageProcessingPass);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Perform rendering according to a render state.
*/
void Render(const vtkRenderState* s) override;
/**
* Release graphics resources and ask components to release their own resources.
*/
void ReleaseGraphicsResources(vtkWindow* w) override;
//@{
/**
* Get/Set the cubemap textures resolution used to render (offscreen) all directions.
* Default is 300.
*/
vtkGetMacro(CubeResolution, unsigned int);
vtkSetMacro(CubeResolution, unsigned int);
//@}
/**
* Enumeration of projection types.
*/
enum : int
{
Equirectangular = 1, /**< Equirectangular projection */
Azimuthal = 2 /**< Azimuthal equidistant projection */
};
//@{
/**
* Get/Set the type of projection.
* Equirectangular projection maps meridians to vertical straight lines and circles of latitude to
* horizontal straight lines.
* Azimuthal equidistant projection maps all points of the scene based on their distance to the
* view direction. This projection produces a fisheye effect.
* Default is Equirectangular.
*/
vtkGetMacro(ProjectionType, int);
vtkSetClampMacro(ProjectionType, int, Equirectangular, Azimuthal);
void SetProjectionTypeToEquirectangular() { this->SetProjectionType(Equirectangular); }
void SetProjectionTypeToAzimuthal() { this->SetProjectionType(Azimuthal); }
//@}
//@{
/**
* Get/Set the vertical angle of projection.
* 180 degrees is a half sphere, 360 degrees is a full sphere,
* but any values in the range (90;360) can be set.
* Default is 180 degrees.
*/
vtkGetMacro(Angle, double);
vtkSetClampMacro(Angle, double, 90.0, 360.0);
//@}
protected:
vtkPanoramicProjectionPass() = default;
~vtkPanoramicProjectionPass() override = default;
void RenderOnFace(const vtkRenderState* s, int index);
void Project(vtkOpenGLRenderWindow* renWin);
void InitOpenGLResources(vtkOpenGLRenderWindow* renWin);
/**
* Graphics resources.
*/
vtkOpenGLFramebufferObject* FrameBufferObject = nullptr;
vtkTextureObject* CubeMapTexture = nullptr;
vtkOpenGLQuadHelper* QuadHelper = nullptr;
unsigned int CubeResolution = 300;
int ProjectionType = Equirectangular;
double Angle = 180.0;
private:
vtkPanoramicProjectionPass(const vtkPanoramicProjectionPass&) = delete;
void operator=(const vtkPanoramicProjectionPass&) = 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