Translucent texture for texture coordinates outside [0,1]

I have a 3D geological model. I would now like to project a 2D map onto its surface; however the map only covers some parts of the 3D model surface. Currently I have set repetition off; but the effect is that parts of the 3D surface which are not covered by the map get colour assigned from the map border. The effect is quite ugly - see the right hand part of the image below.

Is there a way to make a texture translucent when the texture coordinates fall outside the [0,1] range? Or alternatively, could I assign a constant colour in this case?

Thanks for your help!

Hi,
You can try to set the color you want using SetBorderColor and SetWrapS/SetWrapT to ClampToBorder

Hi, thanks for the hint. However I can’t figure out how to use this - I assume you are talking about vtkTextureObject?
I currently use vtkOpenGLPolyDataMapper and vtkTexture.

Assuming myTexture is your vtkTexture:

vtkTextureObject* texObject = vtkOpenGLTexture::SafeDownCast(myTexture)->GetTextureObject();

Nope, that doesn’t work, it returns a NULL pointer for texObject.

I have got something working; I manually set the border pixels of my image to have 0 as alpha value. But still if somebody can find a more elegant solution I’d be grateful.

You have to load it before getting the texture object:
myTexture->Load(renderer);

Tried it but now now after using m_Texture->Load(m_Renderer) the texture is no longer visible.

Assigning values above 1 in the texture coordinates where you don’t have textures with setting repeat on the vtkTexture to False should do the trick. Here is an example using PyVista to show what this would look like:

from pyvista import examples

texture = examples.download_puppy_texture()
texture.SetRepeat(False)

mesh = examples.load_random_hills()
mesh.texture_map_to_plane(inplace=True)

# Now turn off a region of the texture mapping
idx = mesh.points[:,0] > 5
mesh.t_coords[idx] = [1.1, 1.1]

mesh.plot(texture=texture, cpos='xy', 
          show_grid=True, color='white')

Hi Bane,
thanks, but setting vtkTexture::SetRepeat(false) is exactly what I had done and I get the picture shown above; the stripes on the right hand side all have texture values > 1.
But it’s interesting to see that it works for the pyvista example. Makes me think if there’s an additional setting I need to change, or if it is a bug in VTK which has been fixed in your version but not mine. What version is your pvyista built on? I am using VTK 8.2 here.

I am also using VTK 8.2 - I don’t think this is a VTK issue. Maybe quickly pip install PyVista and run that example to see?

That’s really strange that it isn’t working for you though… perhaps you are setting other options on the vtkTexture that conflict with the Repeat option? what values above 1 are you using? Because if I use NaN, this doesn’t work

Your pyvista example works alright here, but I am not using system-built libraries for VTK when using C+++.

All I do with vtkTexture is to

  • load an image via SetInputData()
  • set InterpolateOn() [but I also tried InterpolateOff()]
  • SetRepeat(false)

That’s all.

Oh, and the values > 1.0 are calculated values from a transformation, but they are not NAN.

Hm… make me suspect a graphics library/ OpenGL difference

Here are my CMAKE settings when searching for OpenGL:

image

Do you think that I would need vtkImagingOpenGL2 to be set to true?

Never mind, I just tried it and it doesn’t make a difference.

I’m wondering it vtk.vtkTexture.SetEdgeClamp is the method to control this? It’s docs:

Turn on/off the clamping of the texture map when the texture
coords extend beyond the [0,1] range. Only used when Repeat is
off, and edge clamping is supported by the graphics card.

I’m having trouble with this, so I wonder if its a GPU dependent thing?