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

Merge topic 'transparency' into master

4ea5a7c1 Fix for the case when there is nothing to draw
d24fcf92 Forgot to comment out debug statement
944ee020 A number of transparency related issues fixed
parents 24a829a6 4ea5a7c1
......@@ -395,7 +395,7 @@ ballTC.SetInputData(model)
lut = vtk.vtkLookupTable()
lut.SetNumberOfColors(3)
lut.Build()
lut.SetTableValue(0,0,0,0,0)
lut.SetTableValue(0,0,0,0,1)
lut.SetTableValue(1,1,.3,.3,1)
lut.SetTableValue(2,.8,.8,.9,1)
mapper = vtk.vtkDataSetMapper()
......
......@@ -399,7 +399,7 @@ vtkTextureMapToSphere ballTC
vtkLookupTable lut
lut SetNumberOfColors 3
lut Build
lut SetTableValue 0 0 0 0 0
lut SetTableValue 0 0 0 0 1
lut SetTableValue 1 1 .3 .3 1
lut SetTableValue 2 .8 .8 .9 1
......
if(VTK_RENDERING_BACKEND STREQUAL "OpenGL2")
set(extra_opengl2_tests
TestCompositePolyDataMapper2.cxx,NO_DATA
TestAreaSelections.cxx) # incorrect results in OpenGL
# the following produce incorrect results in OpenGL
TestTranslucentLUTAlphaBlending.cxx
TestTranslucentLUTTextureAlphaBlending.cxx
TestAreaSelections.cxx
)
endif()
vtk_add_test_cxx(${vtk-module}CxxTests tests
......@@ -59,9 +63,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestTransformCoordinateUseDouble.cxx
TestTranslucentImageActorAlphaBlending.cxx
TestTranslucentImageActorDepthPeeling.cxx
TestTranslucentLUTAlphaBlending.cxx
TestTranslucentLUTDepthPeeling.cxx
TestTranslucentLUTTextureAlphaBlending.cxx
TestTranslucentLUTTextureDepthPeeling.cxx
TestTStripsColorsTCoords.cxx
TestTStripsNormalsColorsTCoords.cxx
......
8687dc14fab46f34e86c8da88aa1dc0e
6c9b293a7537053efa4ed43fdc8a9d96
......@@ -30,7 +30,6 @@
#include "vtkActor.h"
#include "vtkBrownianPoints.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkPointGaussianMapper.h"
......@@ -56,18 +55,13 @@ int TestPointGaussianMapper(int argc, char *argv[])
vtkNew<vtkPointSource> points;
points->SetNumberOfPoints(desiredPoints);
points->SetRadius(pow(desiredPoints,0.33)*5.0);
vtkNew<vtkBrownianPoints> randomVector;
randomVector->SetMinimumSpeed(0);
randomVector->SetMaximumSpeed(1);
randomVector->SetInputConnection(points->GetOutputPort());
points->SetRadius(pow(desiredPoints,0.33)*20.0);
vtkNew<vtkRandomAttributeGenerator> randomAttr;
randomAttr->SetDataTypeToFloat();
randomAttr->GeneratePointScalarsOn();
randomAttr->GeneratePointVectorsOn();
randomAttr->SetInputConnection(randomVector->GetOutputPort());
randomAttr->SetInputConnection(points->GetOutputPort());
randomAttr->Update();
......@@ -87,17 +81,18 @@ int TestPointGaussianMapper(int argc, char *argv[])
ctf->SetColorSpaceToRGB();
mapper->SetLookupTable(ctf.Get());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.Get());
vtkNew<vtkRenderer> renderer;
renderer->SetBackground(0.0, 0.0, 0.0);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(900, 900);
renderWindow->AddRenderer(renderer.Get());
renderer->AddActor(actor.Get());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renderWindow.Get());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.Get());
renderer->AddActor(actor.Get());
vtkNew<vtkTimerLog> timer;
timer->StartTimer();
renderWindow->Render();
......@@ -134,5 +129,5 @@ int TestPointGaussianMapper(int argc, char *argv[])
iren->Start();
}
return EXIT_SUCCESS;
return !retVal;
}
71f5af0ed95b703b72ea17c2a471a962
7289527bd2b777a40b853cdfdf8bc826
......@@ -21,14 +21,26 @@ varying vec2 tcoordVC;
uniform sampler2D translucentRGBATexture;
uniform sampler2D currentRGBATexture;
uniform int lastpass;
void main()
{
// current is what is most recently rendered
// translucent is what is in FRONT of it
// we render front to back
vec4 t1Color = texture2D(translucentRGBATexture, tcoordVC);
vec4 t2Color = texture2D(currentRGBATexture, tcoordVC);
gl_FragColor.a = t1Color.a + t2Color.a * (1.0-t1Color.a);
if (gl_FragColor.a > 0.0)
{
gl_FragColor.rgb = (t1Color.rgb*t1Color.a + t2Color.rgb*t2Color.a*(1.0-t1Color.a))/gl_FragColor.a;
if (lastpass == 1)
{
gl_FragColor.rgb = (t1Color.rgb*t1Color.a + t2Color.rgb*(1.0-t1Color.a))/gl_FragColor.a;
}
else
{
gl_FragColor.rgb = (t1Color.rgb*t1Color.a + t2Color.rgb*t2Color.a*(1.0-t1Color.a))/gl_FragColor.a;
}
}
else
{
......
......@@ -59,7 +59,12 @@ void main()
// compute the projected vertex position
vec4 vertexVC = MCVCMatrix * vertexMC;
float radius2 = dot(offsetMC,offsetMC)*0.25;
// the offsets sent down are positioned
// at 2.0*radius*3.0 from the center of the
// gaussian. This has to be consistent
// with the offsets we build into the VBO
float radius = sqrt(dot(offsetMC,offsetMC))/6.0;
// make the triangle face the camera
if (cameraParallel == 0)
......@@ -75,6 +80,6 @@ void main()
vertexVC.xy = vertexVC.xy + offsetMC;
}
offsetVC = offsetMC/sqrt(radius2);
offsetVC = offsetMC/radius;
gl_Position = VCDCMatrix * vertexVC;
}
......@@ -198,7 +198,9 @@ vtkTextureObject *vtkDepthPeelingPassCreateTextureObject(
return result;
}
void vtkDepthPeelingPass::BlendIntermediatePeels(vtkOpenGLRenderWindow *renWin)
void vtkDepthPeelingPass::BlendIntermediatePeels(
vtkOpenGLRenderWindow *renWin,
bool done)
{
this->CurrentRGBATexture->CopyFromFrameBuffer(this->ViewportX, this->ViewportY,
this->ViewportX, this->ViewportY,
......@@ -224,6 +226,8 @@ void vtkDepthPeelingPass::BlendIntermediatePeels(vtkOpenGLRenderWindow *renWin)
"translucentRGBATexture", this->TranslucentRGBATexture->GetTextureUnit());
this->IntermediateBlendProgram->Program->SetUniformi(
"currentRGBATexture", this->CurrentRGBATexture->GetTextureUnit());
this->IntermediateBlendProgram->Program->SetUniformi(
"lastpass", done ? 1 : 0);
glDisable(GL_DEPTH_TEST);
this->CurrentRGBATexture->CopyToFrameBuffer(0, 0,
......@@ -378,7 +382,7 @@ void vtkDepthPeelingPass::Render(const vtkRenderState *s)
this->SetLastRenderingUsedDepthPeeling(s->GetRenderer(), true);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
// glClearColor(0.0,0.0,0.0,0.0); // always clear to black
glClearColor(0.0,0.0,0.0,0.0); // always clear to black
// glClearDepth(static_cast<GLclampf>(1.0));
#ifdef GL_MULTISAMPLE
glDisable(GL_MULTISAMPLE);
......@@ -430,7 +434,7 @@ void vtkDepthPeelingPass::Render(const vtkRenderState *s)
#endif
bool done = false;
GLuint nbPixels = 0;
GLuint nbPixels = threshold + 1;
int peelCount = 0;
while(!done)
{
......@@ -445,38 +449,60 @@ void vtkDepthPeelingPass::Render(const vtkRenderState *s)
glBeginQuery(GL_SAMPLES_PASSED,queryId);
#endif
// check if we are going to exceed the max number of peels or if we
// exceeded the pixel threshold last time
peelCount++;
if ((this->MaximumNumberOfPeels && peelCount >= this->MaximumNumberOfPeels) ||
nbPixels <= threshold)
{
done = true;
// if so we do this last render using alpha blending for all
// the stuff that is left
glEnable(GL_BLEND);
glDepthFunc( GL_ALWAYS );
}
this->TranslucentPass->Render(s);
// update translucentZ
this->TranslucentZTexture->CopyFromFrameBuffer(this->ViewportX, this->ViewportY,
this->ViewportX, this->ViewportY,
this->ViewportWidth, this->ViewportHeight);
glDepthFunc( GL_LEQUAL );
glDisable(GL_BLEND);
#if GL_ES_VERSION_2_0 != 1
glEndQuery(GL_SAMPLES_PASSED);
glGetQueryObjectuiv(queryId,GL_QUERY_RESULT,&nbPixels);
if (nbPixels <= threshold)
{
done = true;
}
#endif
peelCount++;
if(this->MaximumNumberOfPeels && peelCount >= this->MaximumNumberOfPeels)
// cerr << "Pass " << peelCount << " pixels Drawn " << nbPixels << "\n";
// if something was drawn, blend it in
if (nbPixels > 0)
{
done = true;
}
//cerr << "Pass " << peelCount << " pixels Drawn " << nbPixels << "\n";
// update translucentZ
this->TranslucentZTexture->CopyFromFrameBuffer(this->ViewportX, this->ViewportY,
this->ViewportX, this->ViewportY,
this->ViewportWidth, this->ViewportHeight);
// blend the last two peels together
if (peelCount > 1)
{
this->BlendIntermediatePeels(renWin,done);
}
// blend the last two peels together
if (peelCount > 1)
// update translucent RGBA
this->TranslucentRGBATexture->CopyFromFrameBuffer(this->ViewportX, this->ViewportY,
this->ViewportX, this->ViewportY,
this->ViewportWidth, this->ViewportHeight);
}
else // if we drew nothing we are done
{
this->BlendIntermediatePeels(renWin);
// if we drew nothing on the very first frame we still
// need a valid texture to blend with so copy it
if (peelCount == 1)
{
this->TranslucentRGBATexture->CopyFromFrameBuffer(this->ViewportX, this->ViewportY,
this->ViewportX, this->ViewportY,
this->ViewportWidth, this->ViewportHeight);
}
done = true;
}
// update translucent RGBA
this->TranslucentRGBATexture->CopyFromFrameBuffer(this->ViewportX, this->ViewportY,
this->ViewportX, this->ViewportY,
this->ViewportWidth, this->ViewportHeight);
}
// unload the textures we are done with
......
......@@ -178,7 +178,7 @@ public:
vtkTextureObject *CurrentRGBATexture;
std::vector<float> *DepthZData;
void BlendIntermediatePeels(vtkOpenGLRenderWindow *renWin);
void BlendIntermediatePeels(vtkOpenGLRenderWindow *renWin, bool);
void BlendFinalPeel(vtkOpenGLRenderWindow *renWin);
private:
......
......@@ -50,8 +50,8 @@ void vtkOpenGLActor::Render(vtkRenderer *ren, vtkMapper *mapper)
vtkOpenGLClearErrorMacro();
// get opacity
double opacity = this->GetProperty()->GetOpacity();
if (opacity == 1.0)
bool opaque = this->GetIsOpaque();
if (opaque)
{
glDepthMask(GL_TRUE);
}
......@@ -79,7 +79,7 @@ void vtkOpenGLActor::Render(vtkRenderer *ren, vtkMapper *mapper)
// send a render to the mapper; update pipeline
mapper->Render(ren, this);
if (opacity != 1.0)
if (!opaque)
{
glDepthMask(GL_TRUE);
}
......
......@@ -126,10 +126,10 @@ void vtkOpenGLPointGaussianMapperHelper::ReplaceShaderValues(std::string &VSSour
// compute the eye position and unit direction
"//VTK::Color::Impl\n"
" float dist2 = dot(offsetVC.xy,offsetVC.xy);\n"
" float gaussian = exp(-0.5*16.0*dist2);\n"
// " diffuseColor = vertexColor.rgb;\n"
// " ambientColor = vertexColor.rgb;\n"
" if (dist2 > 9.0) { discard; }\n"
" float gaussian = exp(-0.5*dist2);\n"
" opacity = opacity*gaussian;"
// " opacity = opacity*0.5;"
, false);
this->Superclass::ReplaceShaderValues(VSSource,FSSource,GSSource,lightComplexity,ren,actor);
......@@ -216,6 +216,7 @@ void vtkOpenGLPointGaussianMapperHelperPackVBOTemplate2(
pointPtr = points + i*3;
colorPtr = colors ? (colors + i*colorComponents) : white;
float radius = sizes ? sizes[i] : defaultSize;
radius *= 3.0;
// Vertices
*(it++) = pointPtr[0];
......
......@@ -522,11 +522,22 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues(std::string &VSSource,
"uniform vec2 screenSize;\n"
"uniform sampler2D opaqueZTexture;\n"
"uniform sampler2D translucentZTexture;\n");
// the .0000001 below is an epsilon. It turns out that
// graphics cards can render the same polygon two times
// in a row with different z values. I suspect it has to
// do with how rasterinzation of the polygon is broken up.
// A different breakup across fragment shaders can result in
// very slightly different z values for some of the pixels.
// The end result is that with depth peeling, you can end up
// counting/accumulating pixels of the same surface twice
// simply due to this randomness in z values. So we introduce
// an epsilon into the transparent test to require some
// minimal z seperation between pixels
substitute(FSSource, "//VTK::DepthPeeling::Impl",
"float odepth = texture2D(opaqueZTexture, gl_FragCoord.xy/screenSize).r;\n"
" if (gl_FragCoord.z >= odepth) { discard; }\n"
" float tdepth = texture2D(translucentZTexture, gl_FragCoord.xy/screenSize).r;\n"
" if (gl_FragCoord.z <= tdepth) { discard; }\n"
" if (gl_FragCoord.z <= tdepth + .0000001) { discard; }\n"
// "gl_FragColor = vec4(odepth*odepth,tdepth*tdepth,gl_FragCoord.z*gl_FragCoord.z,1.0);"
);
}
......
if(VTK_RENDERING_BACKEND STREQUAL "OpenGL2")
set(extra_opengl2_tests
# the following produce incorrect results in OpenGL
TestConeLayoutStrategy.cxx
)
endif()
vtk_add_test_cxx(${vtk-module}CxxTests tests
${extra_opengl2_tests}
TestCoincidentGraphLayoutView.cxx
TestColumnTree.cxx
TestConeLayoutStrategy.cxx
TestDendrogramItem.cxx
TestGraphLayoutView.cxx
TestHeatmapCategoryLegend.cxx
......
e3e1f31b6d238602055f7f58dac034a3
dcedd666812674f4fe4829c3ebc4edc3
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