[vtk-developers] Bug in scalar color mapping?
David Gobbi
david.gobbi at gmail.com
Thu Sep 25 12:09:08 EDT 2014
Thanks, Ken. That makes it very clear.
Now I know we need backwards compatibility, so maybe I should bite
my tongue, but it would be nice if the code would _combine_ the property's
color with the scalar color, e.g.
if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT)
{
FSSource = replace(FSSource,"//VTK::Color::Impl",
"vec3 ambientColor = vertexColor.rgb*ambientColorUniform.rbg;\n"
"vec3 diffuseColor = diffuseColorUniform.rgb;\n"
"float opacity = vertexColor.a*opacityUniform;");
}
etcetera. If the mode is VTK_MATERIALMODE_AMBIENT the scalars would
combine with the property's ambient color, if VTK_MATERIALMODE_DIFFUSE
the scalars would combine with the property's diffuse color, and if the mode is
AMBIENT_AND_DIFFUSE the scalar color would combine with both. As for
DEFAULT, my preference would be for it to be same as AMBIENT_AND_DIFFUSE.
- David
On Thu, Sep 25, 2014 at 9:27 AM, Ken Martin <ken.martin at kitware.com> wrote:
> Depending on various settings, phase of the moon etc, scalar colors
> sometimes end up setting the ambient color and sometimes they set the
> diffuse color of a vertex and sometimes they set both IIRC. Sometimes
> lighting is applied to the result and sometimes it isn't.
>
> The following snippet of code is what I am using for the OpenGL backend,
> which is very close to that VTK currently does. Textured scalars coloring
> is another beast. Hope that helps
>
> if ( we have scalar colors)
> {
> if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT ||
> (this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT &&
> actor->GetProperty()->GetAmbient() > actor->GetProperty()->GetDiffuse()))
> {
> FSSource = replace(FSSource,"//VTK::Color::Impl",
> "vec3 ambientColor = vertexColor.rgb;\n"
> "vec3 diffuseColor =
> diffuseColorUniform.rgb;\n"
> "float opacity = vertexColor.a;");
> }
> else if (this->ScalarMaterialMode == VTK_MATERIALMODE_DIFFUSE ||
> (this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT &&
> actor->GetProperty()->GetAmbient() <= actor->GetProperty()->GetDiffuse()))
> {
> FSSource = replace(FSSource,"//VTK::Color::Impl",
> "vec3 diffuseColor = vertexColor.rgb;\n"
> "vec3 ambientColor =
> ambientColorUniform;\n"
> "float opacity = vertexColor.a;");
> }
> Else // I believe this case is something like
> VTK_MATERIALMODE_AMBIENT_AND_DIFFUSE
> {
> FSSource = replace(FSSource,"//VTK::Color::Impl",
> "vec3 diffuseColor = vertexColor.rgb;\n"
> "vec3 ambientColor = vertexColor.rgb;\n"
> "float opacity = vertexColor.a;");
> }
> }
> Else // no scalars, just use material property colors
> {
> FSSource = replace(FSSource,"//VTK::Color::Impl",
> "vec3 ambientColor =
> ambientColorUniform;\n"
> "vec3 diffuseColor =
> diffuseColorUniform;\n"
> "float opacity = opacityUniform;");
> }
>
> Ken Martin PhD
> Chairman & CFO
> Kitware Inc.
> 28 Corporate Drive
> Clifton Park NY 12065
> ken.martin at kitware.com
> 518 881-4901 (w)
> 518 371-4573 (f)
>
> This communication, including all attachments, contains confidential and
> legally privileged information, and it is intended only for the use of the
> addressee. Access to this email by anyone else is unauthorized. If you
> are not the intended recipient, any disclosure, copying, distribution or
> any action taken in reliance on it is prohibited and may be unlawful. If
> you received this communication in error please notify us immediately and
> destroy the original message. Thank you.
>
>
> -----Original Message-----
> From: vtk-developers [mailto:vtk-developers-bounces at vtk.org] On Behalf Of
> David Gobbi
> Sent: Thursday, September 4, 2014 7:33 PM
> To: VTK Developers
> Subject: [vtk-developers] Bug in scalar color mapping?
>
> I've run into very odd behavior when I use Ambient and Diffuse
> coefficients in combination with vtkDataSetMapper. This is with VTK
> master.
>
> My property is set up like this, with AmbientColor="red" and
> DiffuseColor="green".
>
> property->SetAmbient(0.51);
> property->SetDiffuse(0.49);
> property->SetAmbientColor(1.0, 0.0, 0.0);
> property->SetDiffuseColor(0.0, 1.0, 0.0);
>
> My mapper, however, is set to MapScalars, so it should ignore the
> AmbientColor and the DiffuseColor, and use the scalars instead:
>
> mapper->SetColorModeToMapScalars();
> mapper->SetLookupTable(table);
> mapper->UseLookupTableScalarRangeOn();
>
> The lookup table is a simple greyscale lookup table, and my polydata has
> scalars. So I would expect my data to be rendered in greyscale.
> But it's not, it's rendered mint green! See the left side of the attached
> image.
>
> I tried a different scalar mapping pathway:
>
> mapper->InterpolateScalarsBeforeMappingOn();
>
> The result was totally different, now it's greyscale with ambient
> lighting, instead of the mix of ambient and diffuse lighting that I
> requested (see right of attached image).
>
>
> If I slightly modify the ambient and diffuse coefficients, the result is,
> once again, completely unexpected:
>
> property->SetAmbient(0.49); // was 0.51
> property->SetDiffuse(0.51); // was 0.49
>
> Now everything is red. In the second attached image, the left shows
> InterpolateScalarsBeforeMappingOff() and the right shows On().
>
>
> Anyone know what is going on here? Everything behaves just find if I set
> either the Ambient or the Diffuse coefficient to zero. But when I use
> them together, VTK goes crazy.
>
> - David
More information about the vtk-developers
mailing list