Index: Rendering/vtkOpenGLProperty.cxx
===================================================================
RCS file: /cvsroot/VTK/VTK/Rendering/vtkOpenGLProperty.cxx,v
retrieving revision 1.34
diff -u -3 -p -r1.34 vtkOpenGLProperty.cxx
--- Rendering/vtkOpenGLProperty.cxx	4 Oct 2005 15:25:52 -0000	1.34
+++ Rendering/vtkOpenGLProperty.cxx	6 Dec 2006 15:11:13 -0000
@@ -98,17 +98,20 @@ void vtkOpenGLProperty::Render(vtkActor 
 
   for (i=0; i < 3; i++) 
     {
-    Info[i] = static_cast<float>(this->Ambient*this->AmbientColor[i]);
+    Info[i] = 
+      static_cast<float>(this->Opacity*this->Ambient*this->AmbientColor[i]);
     }
   glMaterialfv( Face, GL_AMBIENT, Info );
   for (i=0; i < 3; i++) 
     {
-    Info[i] = static_cast<float>(this->Diffuse*this->DiffuseColor[i]);
+    Info[i] = 
+      static_cast<float>(this->Opacity*this->Diffuse*this->DiffuseColor[i]);
     }
   glMaterialfv( Face, GL_DIFFUSE, Info );
   for (i=0; i < 3; i++) 
     {
-    Info[i] = static_cast<float>(this->Specular*this->SpecularColor[i]);
+    Info[i] = 
+      static_cast<float>(this->Opacity*this->Specular*this->SpecularColor[i]);
     }
   glMaterialfv( Face, GL_SPECULAR, Info );
 
@@ -138,7 +141,11 @@ void vtkOpenGLProperty::Render(vtkActor 
   // vtkOpenGLPolyDataMapper::Draw() method if points or lines
   // are encountered without normals. 
   this->GetColor( color );
+  color[0] *= this->Opacity;
+  color[1] *= this->Opacity;
+  color[2] *= this->Opacity;
   color[3] = this->Opacity;
+
   glColor4dv( color );
 
   // Set the PointSize
@@ -189,17 +196,20 @@ void vtkOpenGLProperty::BackfaceRender(v
 
   for (i=0; i < 3; i++) 
     {
-    Info[i] = static_cast<float>(this->Ambient*this->AmbientColor[i]);
+    Info[i] = 
+      static_cast<float>(this->Opacity*this->Ambient*this->AmbientColor[i]);
     }
   glMaterialfv( Face, GL_AMBIENT, Info );
   for (i=0; i < 3; i++) 
     {
-    Info[i] = static_cast<float>(this->Diffuse*this->DiffuseColor[i]);
+    Info[i] = 
+      static_cast<float>(this->Opacity*this->Diffuse*this->DiffuseColor[i]);
     }
   glMaterialfv( Face, GL_DIFFUSE, Info );
   for (i=0; i < 3; i++) 
     {
-    Info[i] = static_cast<float>(this->Specular*this->SpecularColor[i]);
+    Info[i] = 
+      static_cast<float>(this->Opacity*this->Specular*this->SpecularColor[i]);
     }
   glMaterialfv( Face, GL_SPECULAR, Info );
 
Index: Rendering/vtkOpenGLScalarsToColorsPainter.cxx
===================================================================
RCS file: /cvsroot/VTK/VTK/Rendering/vtkOpenGLScalarsToColorsPainter.cxx,v
retrieving revision 1.2
diff -u -3 -p -r1.2 vtkOpenGLScalarsToColorsPainter.cxx
--- Rendering/vtkOpenGLScalarsToColorsPainter.cxx	4 Oct 2005 15:25:52 -0000	1.2
+++ Rendering/vtkOpenGLScalarsToColorsPainter.cxx	6 Dec 2006 15:11:13 -0000
@@ -133,7 +133,26 @@ void vtkOpenGLScalarsToColorsPainter::Re
     {
     this->InternalColorTexture->Load(renderer);
     }
+
+  int pre_mulitiplied_by_alpha =  this->GetPremultiplyColorsWithAlpha(actor);
+
+  GLint old_func[2];
+  // We colors were premultiplied by alpha then we change the blending
+  // function to one that will compute correct blended destination alpha
+  // value, otherwise we stick with the default.
+  if (pre_mulitiplied_by_alpha)
+    {
+    glGetIntegerv(GL_BLEND_SRC, &old_func[0]);
+    glGetIntegerv(GL_BLEND_DST, &old_func[1]);
+    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+    }
+
   this->Superclass::RenderInternal(renderer, actor, typeflags);
+
+  if (pre_mulitiplied_by_alpha)
+    {
+    glBlendFunc(old_func[0], old_func[1]);
+    }
 }
 
 //-----------------------------------------------------------------------------
Index: Rendering/vtkScalarsToColorsPainter.cxx
===================================================================
RCS file: /cvsroot/VTK/VTK/Rendering/vtkScalarsToColorsPainter.cxx,v
retrieving revision 1.4
diff -u -3 -p -r1.4 vtkScalarsToColorsPainter.cxx
--- Rendering/vtkScalarsToColorsPainter.cxx	6 Oct 2005 19:05:28 -0000	1.4
+++ Rendering/vtkScalarsToColorsPainter.cxx	6 Dec 2006 15:11:13 -0000
@@ -21,8 +21,8 @@
 #include "vtkGarbageCollector.h"
 #include "vtkGraphicsFactory.h"
 #include "vtkImageData.h"
-#include "vtkInformation.h"
 #include "vtkInformationDoubleVectorKey.h"
+#include "vtkInformation.h"
 #include "vtkInformationIntegerKey.h"
 #include "vtkInformationObjectBaseKey.h"
 #include "vtkInformationStringKey.h"
@@ -33,6 +33,7 @@
 #include "vtkPolyData.h"
 #include "vtkProperty.h"
 #include "vtkScalarsToColors.h"
+#include "vtkUnsignedCharArray.h"
 
 // Needed when we don't use the vtkStandardNewMacro.
 vtkInstantiatorNewMacro(vtkScalarsToColorsPainter);
@@ -103,6 +104,16 @@ vtkScalarsToColorsPainter* vtkScalarsToC
 }
 
 //-----------------------------------------------------------------------------
+int vtkScalarsToColorsPainter::GetPremultiplyColorsWithAlpha(vtkActor* actor)
+{
+  if (actor && actor->GetTexture())
+    {
+    return 0;
+    }
+  return 1;
+}
+
+//-----------------------------------------------------------------------------
 void vtkScalarsToColorsPainter::PrepareForRendering(vtkRenderer* renderer,
   vtkActor* actor)
 {
@@ -127,7 +138,8 @@ void vtkScalarsToColorsPainter::PrepareF
   // As per the vtkOpenGLPolyDataMapper's claim, this
   // it not a very expensive task, as the colors are cached
   // and hence we do this always.
-  this->MapScalars(actor->GetProperty()->GetOpacity()); 
+  this->MapScalars(actor->GetProperty()->GetOpacity(),
+    this->GetPremultiplyColorsWithAlpha(actor)); 
   this->Superclass::PrepareForRendering(renderer, actor);
 }
 
@@ -202,8 +214,32 @@ void vtkScalarsToColorsPainter::ProcessI
 }
 
 //-----------------------------------------------------------------------------
+static inline void vtkMulitplyColorsWithAlpha(vtkDataArray* array)
+{
+  vtkUnsignedCharArray* colors = vtkUnsignedCharArray::SafeDownCast(array);
+  if (!colors || colors->GetNumberOfComponents() != 4)
+    {
+    return;
+    }
+  unsigned char* ptr = colors->GetPointer(0);
+  vtkIdType numValues = colors->GetNumberOfTuples() *
+    colors->GetNumberOfComponents();
+  if (numValues <= 4)
+    {
+    return;
+    }
+  for (vtkIdType cc=0; cc < numValues; cc+=4, ptr+=4)
+    {
+    double alpha = (0x0ff & ptr[3])/255.0;
+    ptr[0] = static_cast<unsigned char>(0x0ff & static_cast<int>((0x0ff&ptr[0])*alpha));
+    ptr[1] = static_cast<unsigned char>(0x0ff & static_cast<int>((0x0ff&ptr[1])*alpha));
+    ptr[2] = static_cast<unsigned char>(0x0ff & static_cast<int>((0x0ff&ptr[2])*alpha));
+    }
+}
+
+//-----------------------------------------------------------------------------
 // This method has the same functionality as the old vtkMapper::MapScalars.
-void vtkScalarsToColorsPainter::MapScalars(double alpha)
+void vtkScalarsToColorsPainter::MapScalars(double alpha, int multiply_with_alpha)
 {
   int cellFlag;
   vtkDataArray* scalars = vtkAbstractMapper::GetScalars(this->GetPolyData(),
@@ -266,7 +302,7 @@ void vtkScalarsToColorsPainter::MapScala
     if ( this->ColorMode != VTK_COLOR_MODE_DEFAULT || 
          (vtkUnsignedCharArray::SafeDownCast(scalars)) == 0 )
       { // Texture color option.
-      this->MapScalarsToTexture(scalars, alpha);
+      this->MapScalarsToTexture(scalars, alpha, multiply_with_alpha);
       return;
       }
     }
@@ -317,6 +353,21 @@ void vtkScalarsToColorsPainter::MapScala
   this->LookupTable->SetAlpha(alpha);
   colors = this->LookupTable->
     MapScalars(scalars, this->ColorMode, this->ArrayComponent);
+  if (multiply_with_alpha)
+    {
+    // It is possible that the LUT simply returns the scalars as the
+    // colors. In which case, we allocate a new array to ensure
+    // that we don't modify the array in the input.
+    if (scalars == colors)
+      {
+      // Since we will be changing the colors array
+      // we create a copy.
+      colors->Delete();
+      colors = scalars->NewInstance();
+      colors->DeepCopy(scalars);
+      }
+    vtkMulitplyColorsWithAlpha(colors);
+    }
   if (cellFlag == 0)
     {
     oppd->SetScalars(colors);
@@ -438,7 +489,7 @@ void vtkMapperCreateColorTextureCoordina
 #define ColorTextureMapSize 256
 
 void vtkScalarsToColorsPainter::MapScalarsToTexture(vtkDataArray* scalars,
-  double alpha)
+  double alpha, int multiply_with_alpha)
 {
   vtkPolyData* input = this->GetPolyData();
   
@@ -477,10 +528,15 @@ void vtkScalarsToColorsPainter::MapScala
       0,0, 0,0);
     this->ColorTextureMap->SetNumberOfScalarComponents(4);
     this->ColorTextureMap->SetScalarTypeToUnsignedChar();
-    this->ColorTextureMap->GetPointData()->SetScalars(
-      this->LookupTable->MapScalars(tmp, this->ColorMode, 0));
-    // Do we need to delete the scalars?
-    this->ColorTextureMap->GetPointData()->GetScalars()->Delete();
+    vtkDataArray* colors = 
+      this->LookupTable->MapScalars(tmp, this->ColorMode, 0);
+    if (multiply_with_alpha)
+      {
+      vtkMulitplyColorsWithAlpha(colors);
+      }
+
+    this->ColorTextureMap->GetPointData()->SetScalars(colors);
+    colors->Delete();
     // Consistent register and unregisters
     this->ColorTextureMap->Register(this);
     this->ColorTextureMap->Delete();
Index: Rendering/vtkScalarsToColorsPainter.h
===================================================================
RCS file: /cvsroot/VTK/VTK/Rendering/vtkScalarsToColorsPainter.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 vtkScalarsToColorsPainter.h
--- Rendering/vtkScalarsToColorsPainter.h	4 Oct 2005 15:25:52 -0000	1.2
+++ Rendering/vtkScalarsToColorsPainter.h	6 Dec 2006 15:11:13 -0000
@@ -105,15 +105,18 @@ protected:
   vtkScalarsToColorsPainter();
   virtual ~vtkScalarsToColorsPainter(); 
  
-  void MapScalarsToTexture(vtkDataArray* scalars, double alpha);
+  void MapScalarsToTexture(vtkDataArray* scalars, double alpha,
+    int multiply_with_alpha);
 
   // Description:
   // Called just before RenderInternal(). We build the Color array here.
   virtual void PrepareForRendering(vtkRenderer* renderer, vtkActor* actor);
 
   // Description:
-  // Generates the colors, if needed.
-  virtual void MapScalars(double alpha);
+  // Generates the colors, if needed. 
+  // If multiply_with_alpha is set, the colors are multiplied with 
+  // alpha.
+  virtual void MapScalars(double alpha, int multiply_with_alpha);
 
   // Description:
   // Called before RenderInternal() if the Information has been changed
@@ -127,6 +130,19 @@ protected:
   // Description:
   // Take part in garbage collection.
   virtual void ReportReferences(vtkGarbageCollector *collector);
+
+  // Description:
+  // For alpha blending, we sometime premultiply the colors
+  // with alpha and change the alpha blending function.
+  // This call returns whether we are premultiplying or using
+  // the default blending function.
+  // Currently this checks if the actor has a texture, if not
+  // it returns true. 
+  // TODO: It is possible to make this decision
+  // dependent on key passed down from a painter upstream
+  // that makes a more informed decision for alpha blending
+  // depending on extensions available, for example.
+  int GetPremultiplyColorsWithAlpha(vtkActor* actor);
   
   // Methods to set the ivars. These are purposefully protected.
   // The only means of affecting these should be using teh vtkInformation 
