Skip to content
/ VTK Public

Commit 7996928

Browse files
committed
Support any texture with interpolate scalars
VTK !8186 added support for using multitexturing with InterpolateScalarsBeforeMappingOn to allow for blending interpolated scalars with texture coloring. This commit extends this support to the "actortexture" and "albedoTex" textures that can be respectively set with vtkActor::SetTexture() and vtkActor::GetProperty()->SetBaseColorTexture(). When turning on InterpolateScalarsBeforeMapping, the mapper internally creates a texture with the associated texture coordinates. This commit adds a specific attribute for those tcoords to avoid overriding the existing polydata tcoords.
1 parent eb73d7f commit 7996928

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ std::string vtkOpenGLPolyDataMapper::GetTextureCoordinateName(const char* tname)
422422
return it.first;
423423
}
424424
}
425+
426+
// Return the attribute name of the specific tcoords used for scalar coloring with texture
427+
if (tname == std::string("colortexture"))
428+
{
429+
return "colorTCoord";
430+
}
431+
425432
return std::string("tcoord");
426433
}
427434

@@ -473,8 +480,7 @@ std::vector<texinfo> vtkOpenGLPolyDataMapper::GetTextures(vtkActor* actor)
473480
//------------------------------------------------------------------------------
474481
bool vtkOpenGLPolyDataMapper::HaveTCoords(vtkPolyData* poly)
475482
{
476-
return (
477-
this->ColorCoordinates || poly->GetPointData()->GetTCoords() || this->ForceTextureCoordinates);
483+
return (poly->GetPointData()->GetTCoords() || this->ForceTextureCoordinates);
478484
}
479485

480486
//------------------------------------------------------------------------------
@@ -736,7 +742,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor(
736742
else if (this->InterpolateScalarsBeforeMapping && this->ColorCoordinates &&
737743
!this->DrawingVertices)
738744
{
739-
colorImpl += " vec4 texColor = texture(colortexture, tcoordVCVSOutput.st);\n"
745+
colorImpl += " vec4 texColor = texture(colortexture, colorTCoordVCVSOutput.st);\n"
740746
" vec3 ambientColor = ambientIntensity * texColor.rgb;\n"
741747
" vec3 diffuseColor = diffuseIntensity * texColor.rgb;\n"
742748
" float opacity = opacityUniform * texColor.a;";
@@ -3899,19 +3905,18 @@ void vtkOpenGLPolyDataMapper::BuildBufferObjects(vtkRenderer* ren, vtkActor* act
38993905
// if we have offsets from the cell map then use them
39003906
this->CellCellMap->BuildPrimitiveOffsetsIfNeeded(prims, representation, poly->GetPoints());
39013907

3902-
// Set the texture if we are going to use texture
3903-
// for coloring with a point attribute.
3908+
// Set the texture coordinate attribute if we are going to use texture for coloring
39043909
vtkDataArray* tcoords = nullptr;
39053910
if (this->HaveTCoords(poly))
39063911
{
3907-
if (this->InterpolateScalarsBeforeMapping && this->ColorCoordinates)
3908-
{
3909-
tcoords = this->ColorCoordinates;
3910-
}
3911-
else
3912-
{
3913-
tcoords = poly->GetPointData()->GetTCoords();
3914-
}
3912+
tcoords = poly->GetPointData()->GetTCoords();
3913+
}
3914+
3915+
// Set specific texture coordinates if we are going to use texture for scalar coloring
3916+
vtkDataArray* colorTCoords = nullptr;
3917+
if (this->InterpolateScalarsBeforeMapping && this->ColorCoordinates)
3918+
{
3919+
colorTCoords = this->ColorCoordinates;
39153920
}
39163921

39173922
vtkOpenGLRenderWindow* renWin = vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow());
@@ -3937,6 +3942,7 @@ void vtkOpenGLPolyDataMapper::BuildBufferObjects(vtkRenderer* ren, vtkActor* act
39373942
this->VBOs->CacheDataArray("normalMC", n, cache, VTK_FLOAT);
39383943
this->VBOs->CacheDataArray("scalarColor", c, cache, VTK_UNSIGNED_CHAR);
39393944
this->VBOs->CacheDataArray("tcoord", tcoords, cache, VTK_FLOAT);
3945+
this->VBOs->CacheDataArray("colorTCoord", colorTCoords, cache, VTK_FLOAT);
39403946

39413947
// Look for tangents attribute
39423948
vtkFloatArray* tangents = vtkFloatArray::SafeDownCast(poly->GetPointData()->GetTangents());

0 commit comments

Comments
 (0)