Commit 0857be6f authored by Michael Migliore's avatar Michael Migliore

Add an optional user light transformation

This transformation is useful to transform lights attached to the camera
parent ac9c897b
......@@ -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;
......
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