Commit be38a502 authored by Ken Martin's avatar Ken Martin Committed by Code Review
Browse files

Merge topic 'matrix_cleanup' into master

427694b7 Fix a compiler warning
2577188a Use MCDCMatrix in shaders
de8deb6a Use MCDCMatrix in shaders
parents c05171bf 427694b7
......@@ -43,8 +43,7 @@ uniform mat3 normalMatrix; // transform model coordinate directions to view coor
//VTK::Clip::Dec
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
//VTK::Camera::Dec
varying vec4 vertexVCClose;
varying float radiusVC;
......
......@@ -47,8 +47,7 @@ uniform mat3 normalMatrix; // transform model coordinate directions to view coor
//VTK::Clip::Dec
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
//VTK::Camera::Dec
varying vec4 vertexVCClose;
varying float radiusVC;
......
......@@ -15,9 +15,10 @@
#include "vtkglVBOHelper.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkMath.h"
#include "vtkMatrix4x4.h"
#include "vtkOpenGLActor.h"
#include "vtkOpenGLCamera.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
......@@ -27,7 +28,7 @@
#include "vtkSphereMapperVS.h"
using vtkgl::replace;
using vtkgl::substitute;
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkOpenGLSphereMapper)
......@@ -41,11 +42,12 @@ vtkOpenGLSphereMapper::vtkOpenGLSphereMapper()
//-----------------------------------------------------------------------------
void vtkOpenGLSphereMapper::GetShaderTemplate(std::string &VSSource,
std::string &FSSource,
std::string &GSSource,
int lightComplexity, vtkRenderer* ren, vtkActor *actor)
std::string &FSSource,
std::string &GSSource,
int lightComplexity, vtkRenderer* ren, vtkActor *actor)
{
this->Superclass::GetShaderTemplate(VSSource,FSSource,GSSource,lightComplexity,ren,actor);
this->Superclass::GetShaderTemplate(VSSource,FSSource,GSSource,
lightComplexity,ren,actor);
VSSource = vtkSphereMapperVS;
}
......@@ -57,7 +59,12 @@ void vtkOpenGLSphereMapper::ReplaceShaderValues(std::string &VSSource,
vtkRenderer* ren,
vtkActor *actor)
{
FSSource = replace(FSSource,
substitute(VSSource,
"//VTK::Camera::Dec",
"uniform mat4 VCDCMatrix;\n"
"uniform mat4 MCVCMatrix;");
substitute(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVCClose;");
......@@ -73,9 +80,9 @@ void vtkOpenGLSphereMapper::ReplaceShaderValues(std::string &VSSource,
{
replacement += "uniform mat4 VCDCMatrix;\n";
}
FSSource = replace(FSSource,"//VTK::Normal::Dec",replacement);
substitute(FSSource,"//VTK::Normal::Dec",replacement);
FSSource = replace(FSSource,"//VTK::Normal::Impl",
substitute(FSSource,"//VTK::Normal::Impl",
// compute the eye position and unit direction
"vec4 vertexVC = vertexVCClose;\n"
" vec3 EyePos = vec3(0.0,0.0,0.0);\n"
......@@ -114,7 +121,7 @@ void vtkOpenGLSphereMapper::ReplaceShaderValues(std::string &VSSource,
if (ren->GetLastRenderingUsedDepthPeeling())
{
FSSource = vtkgl::replace(FSSource,
substitute(FSSource,
"//VTK::DepthPeeling::Impl",
"float odepth = texture2D(opaqueZTexture, gl_FragCoord.xy/screenSize).r;\n"
" if (gl_FragDepth >= odepth) { discard; }\n"
......@@ -123,7 +130,8 @@ void vtkOpenGLSphereMapper::ReplaceShaderValues(std::string &VSSource,
);
}
this->Superclass::ReplaceShaderValues(VSSource,FSSource,GSSource,lightComplexity,ren,actor);
this->Superclass::ReplaceShaderValues(VSSource,FSSource,GSSource,
lightComplexity,ren,actor);
}
//-----------------------------------------------------------------------------
......@@ -134,14 +142,34 @@ vtkOpenGLSphereMapper::~vtkOpenGLSphereMapper()
//-----------------------------------------------------------------------------
void vtkOpenGLSphereMapper::SetCameraShaderParameters(vtkgl::CellBO &cellBO,
vtkRenderer* ren, vtkActor *actor)
void vtkOpenGLSphereMapper::SetCameraShaderParameters(
vtkgl::CellBO &cellBO,
vtkRenderer* ren, vtkActor *actor)
{
// do the superclass and then reset a couple values
this->Superclass::SetCameraShaderParameters(cellBO,ren,actor);
vtkShaderProgram *program = cellBO.Program;
vtkOpenGLCamera *cam = (vtkOpenGLCamera *)(ren->GetActiveCamera());
vtkMatrix4x4 *wcdc;
vtkMatrix4x4 *wcvc;
vtkMatrix3x3 *norms;
vtkMatrix4x4 *vcdc;
cam->GetKeyMatrices(ren,wcvc,norms,vcdc,wcdc);
program->SetUniformMatrix("VCDCMatrix", vcdc);
if (!actor->GetIsIdentity())
{
vtkMatrix4x4 *mcwc;
vtkMatrix3x3 *anorms;
((vtkOpenGLActor *)actor)->GetKeyMatrices(mcwc,anorms);
vtkMatrix4x4::Multiply4x4(mcwc, wcvc, this->TempMatrix4);
program->SetUniformMatrix("MCVCMatrix", this->TempMatrix4);
}
else
{
program->SetUniformMatrix("MCVCMatrix", wcvc);
}
// add in uniforms for parallel and distance
vtkCamera *cam = ren->GetActiveCamera();
cellBO.Program->SetUniformi("cameraParallel", cam->GetParallelProjection());
}
......
......@@ -15,7 +15,10 @@
#include "vtkglVBOHelper.h"
#include "vtkCamera.h"
#include "vtkMatrix3x3.h"
#include "vtkMatrix4x4.h"
#include "vtkOpenGLActor.h"
#include "vtkOpenGLCamera.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
......@@ -26,7 +29,7 @@
#include "vtkStickMapperVS.h"
using vtkgl::replace;
using vtkgl::substitute;
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkOpenGLStickMapper)
......@@ -57,7 +60,12 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(std::string &VSSource,
vtkRenderer* ren,
vtkActor *actor)
{
FSSource = replace(FSSource,
substitute(VSSource,
"//VTK::Camera::Dec",
"uniform mat4 VCDCMatrix;\n"
"uniform mat4 MCVCMatrix;");
substitute(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVCClose;");
......@@ -74,11 +82,11 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(std::string &VSSource,
{
replacement += "uniform mat4 VCDCMatrix;\n";
}
FSSource = replace(FSSource,"//VTK::Normal::Dec",replacement);
substitute(FSSource,"//VTK::Normal::Dec",replacement);
// see https://www.cl.cam.ac.uk/teaching/1999/AGraphHCI/SMAG/node2.html
FSSource = replace(FSSource,"//VTK::Normal::Impl",
substitute(FSSource,"//VTK::Normal::Impl",
// compute the eye position and unit direction
" vec4 vertexVC = vertexVCClose;\n"
" vec3 EyePos = vec3(0.0,0.0,0.0);\n"
......@@ -88,7 +96,8 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(std::string &VSSource,
" vec3 EyeDir = vertexVC.xyz - EyePos;\n"
" float lengthED = length(EyeDir);\n"
" EyeDir = normalize(EyeDir);\n"
" if (lengthED > (radiusVC+lengthVC)*3.0) { EyePos = vertexVC.xyz - EyeDir*3.0*(radiusVC+lengthVC);}\n"
" if (lengthED > (radiusVC+lengthVC)*3.0) \n"
" { EyePos = vertexVC.xyz - EyeDir*3.0*(radiusVC+lengthVC);}\n"
// translate to Cylinder center
" EyePos = EyePos - centerVC;\n"
......@@ -148,18 +157,18 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(std::string &VSSource,
bool picking = (ren->GetRenderWindow()->GetIsPicking() || selector != NULL);
if (picking)
{
VSSource = vtkgl::replace(VSSource,
substitute(VSSource,
"//VTK::Picking::Dec",
"attribute vec4 selectionId;\n"
"varying vec4 selectionIdFrag;");
VSSource = vtkgl::replace(VSSource,
substitute(VSSource,
"//VTK::Picking::Impl",
"selectionIdFrag = selectionId;");
FSSource = vtkgl::replace(FSSource,
substitute(FSSource,
"//VTK::Picking::Dec",
"uniform vec3 mapperIndex;\n"
"varying vec4 selectionIdFrag;");
FSSource = vtkgl::replace(FSSource,
substitute(FSSource,
"//VTK::Picking::Impl",
"if (mapperIndex == vec3(0.0,0.0,0.0))\n"
" {\n"
......@@ -174,7 +183,7 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(std::string &VSSource,
if (ren->GetLastRenderingUsedDepthPeeling())
{
FSSource = vtkgl::replace(FSSource,
substitute(FSSource,
"//VTK::DepthPeeling::Impl",
"float odepth = texture2D(opaqueZTexture, gl_FragCoord.xy/screenSize).r;\n"
" if (gl_FragDepth >= odepth) { discard; }\n"
......@@ -201,11 +210,33 @@ vtkOpenGLStickMapper::~vtkOpenGLStickMapper()
void vtkOpenGLStickMapper::SetCameraShaderParameters(vtkgl::CellBO &cellBO,
vtkRenderer* ren, vtkActor *actor)
{
// do the superclass and then reset a couple values
this->Superclass::SetCameraShaderParameters(cellBO,ren,actor);
vtkShaderProgram *program = cellBO.Program;
vtkOpenGLCamera *cam = (vtkOpenGLCamera *)(ren->GetActiveCamera());
vtkMatrix4x4 *wcdc;
vtkMatrix4x4 *wcvc;
vtkMatrix3x3 *norms;
vtkMatrix4x4 *vcdc;
cam->GetKeyMatrices(ren,wcvc,norms,vcdc,wcdc);
program->SetUniformMatrix("VCDCMatrix", vcdc);
if (!actor->GetIsIdentity())
{
vtkMatrix4x4 *mcwc;
vtkMatrix3x3 *anorms;
((vtkOpenGLActor *)actor)->GetKeyMatrices(mcwc,anorms);
vtkMatrix4x4::Multiply4x4(mcwc, wcvc, this->TempMatrix4);
program->SetUniformMatrix("MCVCMatrix", this->TempMatrix4);
vtkMatrix3x3::Multiply3x3(anorms, norms, this->TempMatrix3);
program->SetUniformMatrix("normalMatrix", this->TempMatrix3);
}
else
{
program->SetUniformMatrix("MCVCMatrix", wcvc);
program->SetUniformMatrix("normalMatrix", norms);
}
// add in uniforms for parallel and distance
vtkCamera *cam = ren->GetActiveCamera();
cellBO.Program->SetUniformi("cameraParallel", cam->GetParallelProjection());
}
......
......@@ -7,15 +7,11 @@
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkCommand.h>
#include <vtkWidgetEvent.h>
#include <vtkCallbackCommand.h>
#include <vtkWidgetEventTranslator.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkSliderWidget.h>
#include <vtkSliderRepresentation2D.h>
#include <vtkProperty.h>
......
......@@ -19,10 +19,13 @@
#include "vtkInformation.h"
#include "vtkInformationIterator.h"
#include "vtkInformationKey.h"
#include "vtkInformationIntegerKey.h"
#include <cassert>
vtkCxxSetObjectMacro(vtkProp,PropertyKeys,vtkInformation);
vtkInformationKeyMacro(vtkProp,GeneralTextureUnit,Integer);
//----------------------------------------------------------------------------
// Creates an Prop with the following defaults: visibility on.
vtkProp::vtkProp()
......
......@@ -35,6 +35,7 @@ class vtkPropCollection;
class vtkViewport;
class vtkWindow;
class vtkInformation;
class vtkInformationIntegerKey;
class VTKRENDERINGCORE_EXPORT vtkProp : public vtkObject
{
......@@ -153,6 +154,17 @@ public:
virtual vtkIdType GetConvertedPickValue(vtkIdType idIn,
int vtkNotUsed(fieldassociation)) { return idIn; }
// Description:
// Optional Key Indicating the texture unit for general texture mapping
// Old OpenGL was a state machine where you would push or pop
// items. The new OpenGL design is more mapper centric. Some
// classes push a texture and then assume a mapper will use it.
// The new design wants explicit comunication of when a texture
// is being used. This key can be used to pass that information
// down to a mapper.
static vtkInformationIntegerKey *GeneralTextureUnit();
//BTX
// Description:
// WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
......
......@@ -18,6 +18,7 @@
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
......@@ -345,20 +346,38 @@ int vtkTextMapper::SetMultipleRelativeFontSize(vtkViewport *viewport,
void vtkTextMapper::RenderOverlay(vtkViewport *viewport, vtkActor2D *actor)
{
vtkDebugMacro(<<"RenderOverlay called");
vtkRenderer *ren = NULL;
if (this->Input && this->Input[0])
{
this->UpdateImage();
this->UpdateQuad(actor);
if (vtkRenderer *ren = vtkRenderer::SafeDownCast(viewport))
ren = vtkRenderer::SafeDownCast(viewport);
if (ren)
{
vtkDebugMacro(<<"Texture::Render called");
this->Texture->Render(ren);
vtkInformation *info = actor->GetPropertyKeys();
if (!info)
{
info = vtkInformation::New();
actor->SetPropertyKeys(info);
info->Delete();
}
info->Set(vtkProp::GeneralTextureUnit(),
this->Texture->GetTextureUnit());
}
}
vtkDebugMacro(<<"PolyData::RenderOverlay called");
this->Mapper->RenderOverlay(viewport, actor);
// clean up
if (ren)
{
this->Texture->PostRender(ren);
}
vtkDebugMacro(<<"Superclass::RenderOverlay called");
this->Superclass::RenderOverlay(viewport, actor);
}
......
......@@ -204,6 +204,10 @@ public:
// Interpolate flag is turn off.
virtual int IsTranslucent();
// Description:
// Return the texture unit used for this texture
virtual int GetTextureUnit() { return 0; }
protected:
vtkTexture();
~vtkTexture();
......
......@@ -14,6 +14,7 @@
=========================================================================*/
#include "vtkTexturedActor2D.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkTexture.h"
......@@ -51,9 +52,22 @@ int vtkTexturedActor2D::RenderOverlay(vtkViewport* viewport)
{
// Render the texture.
vtkRenderer* ren = vtkRenderer::SafeDownCast(viewport);
vtkInformation *info = this->GetPropertyKeys();
if (this->Texture)
{
this->Texture->Render(ren);
if (!info)
{
info = vtkInformation::New();
this->SetPropertyKeys(info);
info->Delete();
}
info->Set(vtkProp::GeneralTextureUnit(),
this->Texture->GetTextureUnit());
}
else if (info)
{
info->Remove(vtkProp::GeneralTextureUnit());
}
int result=this->Superclass::RenderOverlay(viewport);
if (this->Texture)
......
......@@ -35,8 +35,6 @@ attribute vec2 offsetMC;
// Texture coordinates
//VTK::TCoord::Dec
uniform mat3 normalMatrix; // transform model coordinate directions to view coordinates
// material property values
//VTK::Color::Dec
......@@ -44,8 +42,7 @@ uniform mat3 normalMatrix; // transform model coordinate directions to view coor
//VTK::Clip::Dec
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
//VTK::Camera::Dec
varying vec2 offsetVC;
uniform int cameraParallel;
......
......@@ -37,14 +37,11 @@ attribute vec4 vertexMC;
// Texture coordinates
//VTK::TCoord::Dec
uniform mat3 normalMatrix; // transform model coordinate directions to view coordinates
// material property values
//VTK::Color::Dec
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
//VTK::Camera::Dec
//VTK::Glyph::Dec
......
......@@ -26,10 +26,7 @@
// DC - Display Coordinates
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
uniform mat3 normalMatrix; // transform model coordinate directions to view coordinates
//VTK::Camera::Dec
uniform int numberOfLights; // only allow for up to 6 active lights
uniform vec3 lightColor[6]; // intensity weighted color
......
......@@ -27,10 +27,7 @@
// DC - Display Coordinates
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
uniform mat3 normalMatrix; // transform model coordinate directions to view coordinates
//VTK::Camera::Dec
uniform int numberOfLights; // only allow for up to 6 active lights
uniform vec3 lightColor[6]; // intensity weighted color
......
......@@ -37,8 +37,6 @@ attribute vec4 vertexMC;
// Texture coordinates
//VTK::TCoord::Dec
uniform mat3 normalMatrix; // transform model coordinate directions to view coordinates
// material property values
//VTK::Color::Dec
......@@ -46,8 +44,7 @@ uniform mat3 normalMatrix; // transform model coordinate directions to view coor
//VTK::Clip::Dec
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
//VTK::Camera::Dec
void main()
{
......
......@@ -31,8 +31,7 @@ attribute vec4 vertexMC;
//VTK::Color::Dec
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
//VTK::Camera::Dec
// Texture coordinates
//VTK::TCoord::Dec
......
......@@ -28,6 +28,7 @@ vtkStandardNewMacro(vtkOpenGLCamera);
vtkOpenGLCamera::vtkOpenGLCamera()
{
this->WCDCMatrix = vtkMatrix4x4::New();
this->WCVCMatrix = vtkMatrix4x4::New();
this->NormalMatrix = vtkMatrix3x3::New();
this->VCDCMatrix = vtkMatrix4x4::New();
......@@ -36,6 +37,7 @@ vtkOpenGLCamera::vtkOpenGLCamera()
vtkOpenGLCamera::~vtkOpenGLCamera()
{
this->WCDCMatrix->Delete();
this->WCVCMatrix->Delete();
this->NormalMatrix->Delete();
this->VCDCMatrix->Delete();
......@@ -156,7 +158,7 @@ void vtkOpenGLCamera::PrintSelf(ostream& os, vtkIndent indent)
}
void vtkOpenGLCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
vtkMatrix3x3 *&normMat, vtkMatrix4x4 *&vcdc)
vtkMatrix3x3 *&normMat, vtkMatrix4x4 *&vcdc, vtkMatrix4x4 *&wcdc)
{
// has the camera changed?
if (ren != this->LastRenderer ||
......@@ -195,6 +197,8 @@ void vtkOpenGLCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
this->VCDCMatrix->Transpose();
}
vtkMatrix4x4::Multiply4x4(this->WCVCMatrix, this->VCDCMatrix, this->WCDCMatrix);
this->KeyMatrixTime.Modified();
this->LastRenderer = ren;
}
......@@ -202,4 +206,5 @@ void vtkOpenGLCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
wcvc = this->WCVCMatrix;
normMat = this->NormalMatrix;
vcdc = this->VCDCMatrix;
wcdc = this->WCDCMatrix;
}
\ No newline at end of file
......@@ -40,12 +40,13 @@ public:
void UpdateViewport(vtkRenderer *ren);
void GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&WCVCMatrix,
vtkMatrix3x3 *&normalMatrix, vtkMatrix4x4 *&VCDCMatrix);
vtkMatrix3x3 *&normalMatrix, vtkMatrix4x4 *&VCDCMatrix, vtkMatrix4x4 *&WCDCMatrix);
protected:
vtkOpenGLCamera();
~vtkOpenGLCamera();
vtkMatrix4x4 *WCDCMatrix;
vtkMatrix4x4 *WCVCMatrix;
vtkMatrix3x3 *NormalMatrix;
vtkMatrix4x4 *VCDCMatrix;
......
......@@ -36,7 +36,7 @@
#include "vtkglGlyph3DVSFragmentLit.h"
using vtkgl::replace;
using vtkgl::substitute;
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkOpenGLGlyph3DHelper)
......@@ -77,28 +77,28 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderValues(std::string &VSSource,
if (lightComplexity > 0)
{
// we use vertex instead of vertexMC
VSSource = replace(VSSource,
substitute(VSSource,
"//VTK::PositionVC::Impl",
"vertexVC = MCVCMatrix * vertex;\n"
" gl_Position = VCDCMatrix * vertexVC;\n");
" gl_Position = MCDCMatrix * vertex;\n");
}
// deal with color
if (this->UsingInstancing)
{
VSSource = replace(VSSource,"//VTK::Color::Dec",
"attribute vec4 glyphColor;\n"
"varying vec4 vertexColor;");
substitute(VSSource,"//VTK::Color::Dec",
"attribute vec4 glyphColor;\n"
"varying vec4 vertexColor;");
}
else
{
VSSource = replace(VSSource,
"//VTK::Color::Dec",
"uniform vec4 glyphColor;\n"
"varying vec4 vertexColor;");
substitute(VSSource,
"//VTK::Color::Dec",
"uniform vec4 glyphColor;\n"
"varying vec4 vertexColor;");
}
VSSource = replace(VSSource,"//VTK::Color::Impl",