[vtkusers] Problem with multitexturing in VTK

Blue Star thunderbird1 at hotmail.fr
Thu Apr 18 08:24:56 EDT 2013




Hello everyone,

I'm using VTK 5.8 and since a few days, I'm facing a big problem : multitexturing.

Let me explain myself :

I'm working on a 3D image rendering software, and the next major version should include multi-textures rendering out of a OBJ file and some JPG images.

The only thing that looks close to what I want to do is at http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/Rendering/Testing/Cxx/TestMultiTexturing.cxx .
This is the code I base myself on, and if I try to run it, it works pretty well, but I can't adapt it to make it work like I'd want.


Currently I have, for an example, an .obj file and 4 .jpg files containing the textures, each to apply on different parts of the polydata.
So I'm retrieving the geometry in a vtkPolyData with the vtkOBJReader class, and no problem here.
To keep the name "MultTCoords" of the example, I even set the name of the polyData's texture coordinates' array to "MultTCoords" by doing:
polyData->GetPointData()->GetArray(0)->SetName("MultTCoords");

(I checked that it is the right array, and actually it is the only one, so I can't be wrong here)

 I then use four vtkJPEGReaders to import the images data, and use it for my vtkTextures, like :

  std::cout << "Creating vtkTextures..." << std::endl;
  vtkTexture * texture1 =  vtkTexture::New();
  vtkTexture * texture2 =  vtkTexture::New();
  vtkTexture * texture3 =  vtkTexture::New();
  vtkTexture * texture4 =  vtkTexture::New();
  texture1->SetInputConnection(jPEGReader1->GetOutputPort());
  texture2->SetInputConnection(jPEGReader2->GetOutputPort());
  texture3->SetInputConnection(jPEGReader3->GetOutputPort());
  texture4->SetInputConnection(jPEGReader4->GetOutputPort());

and setting their blending mode :

 texture1->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_REPLACE);
  texture2->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_ADD);
  texture3->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_ADD);
  texture4->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_ADD);

(I also tried a whole lot of different blending modes, in a whole lot of different ways, yet nothing seems to work...)

The remaining code is pretty like the example : checking for hardware support (multitexturing is supported and it shows enough texture units support: 4 ),  MapDataArrayToMultiTextureAttribute with the mapper and actor->GetProperty()->SetTexture four times with each texture unit ("VTK_TEXTURE_UNIT_" from 0 to 3...).

But it doesn't work, and I can't seem to know why.

Actually, from the result it gives, it seems like VTK only applies the texture with the "REPLACE" blending mode, and ignores the others. It results in one part of the polyData correctly textured (the part that this texture originally covers), and the rest seems to be ""textured"" with a extremely ugly stretch of this same image.

Could it be the fact that the OBJ Reader duplicates vertices ? My obj file states 409372 vertices, but the output polyData is made of 2 456 640 vertices. I tried with and without passing it into a vtkCleanPolyData (which gives us back the correct number of points, 409372), but with no success. The only problem I can think of is the way the OBJReader puts the texture coordinates in the polyData, but I can't figure out how it should be done to work properly, since there is close to no documentation of that feature in all the examples and archives I could find googling.



If you have any idea of what could be wrong, or if someone already had the same problem in here, please let me know. And sorry for the long message !

Alexandre


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130418/54fe3201/attachment.htm>


More information about the vtkusers mailing list