[vtkusers] Re: Problem with alpha blending

Francisco Jesús Martínez Serrano franjesus at gmail.com
Fri Jul 6 13:40:34 EDT 2007


I found the problem: VTK was using the opaque codepath to render my
geometry. The following quick and dirty hack solved it:

actor->GetProperty()->SetOpacity(0.999999);


2007/7/6, Francisco Jesús Martínez Serrano <franjesus at gmail.com>:
> Dear vtk users,
>
> I'm trying to create an application to visualize the results of
> galaxy-formation simulations
> using particles. The technique that I want to use is the technique
> that was used to make
> these videos:
>
> http://www.aip.de/People/AKhalatyan/COSMOLOGY/STEREO/MW_ANDROMEDA/MW.htm
>
> It is basically a billboarding using a texture for each particle that
> reproduces the density field of each particle.
>
> The billboarding implementation that I have so far consists of adding
> all the particles as
> input of a vtkGlyph3D object and a vtkPlaneSource as source. The
> texture (consisting of a
> white square R=G=B=255 with varying alpha value for transparency) is
> then added to the
> actor of the vtkPolyDataMapper of the glyph. I have set up a callback
> that sets the normal
> vector of each plane in the glyph directed towards the camera:
>
> void OrientNormal( vtkObject* vtkNotUsed(object),unsigned long
> eventId,void* sr,void* vtkNotUsed(calldata))
> {
>         CallbackData* cd = reinterpret_cast<CallbackData*>(sr);
>         vtkCamera* cam = cd->cam;
>         vtkPolyData* pdata = cd->pdata;
>         vtkPointData *PD = pdata->GetPointData();
>         vtkGlyph3D* glyph = cd->glyph;
>
>         double *rz;
>         double rzm[3],rym[3],rxm[3];
>         double *pos;
>         double *cpos = cam->GetPosition();
>         // Vector data for directions
>         vtkFloatArray *FA = vtkFloatArray::New();
>         FA->SetName("directions");
>         FA->SetNumberOfComponents(3);
>         uint n=pdata->GetNumberOfPoints();
>         for (uint i=0; i<n; i++)
>         {
>                 if ( cam->GetParallelProjection() != 0 )
>                 {
>                         rz = cam->GetDirectionOfProjection();
>                         rzm[0] = -rz[0];
>                         rzm[1] = -rz[1];
>                         rzm[2] = -rz[2];
>                 }
>                 else
>                 {
>                         pos=pdata->GetPoint(i);
>                         rzm[0] = -cpos[0] + pos[0];
>                         rzm[1] = -cpos[1] + pos[1];
>                         rzm[2] = -cpos[2] + pos[2];
> //                      vtkMath::Normalize(rzm);
>                 }
>                 FA->InsertNextTuple(rzm);
>         }
>         // Add the data arrays to the point data
>         PD->SetNormals(FA);
>         FA->Delete();
> }
>
>
> The problem comes with some relative postions of particles which don't
> work as supposed.
> An example can be seen at:
>
> http://franjesus.googlepages.com/alphaproblem.png
>
> Here the green particle is on the front (you can tell by the size, all
> particles have the same
> radius) and is partially covering the yellow and cyan particles. For
> the yellow particle the
> desired effect is obtained and there's a blended transition zone. With
> the cyan particle, the
> problem happens and the green particle totally covers it until the
> alpha channel goes to zero
> (ie. like a threshold).
>
> Is there any option of the renderer that I have to set so get it
> working correctly?
> Might it be a problem with the OpenGL implementation? (nvidia linux 9755)
>



More information about the vtkusers mailing list