Share via


Texture Coordinates in WPF3D

If you've never encountered texture coordinates before, DanLehen has a detailed introduction that you can find here.

If you have used texture coordinates before in another API you may have noticed that we are a little different. Here's what you need to know:

  • Traditionally, the vertical texture coordinate axis (v) points up but in WPF3D it points down. This is for consistency with 2D. If you're trying to dispay a mesh from a system where v points up, you can either convert the texture coordinates by hand or use a Transform on the Brush to flip it.
  • If you don't set TileBrush.ViewportUnits to BrushMappingMode.Absolute, your texture coordinates will be relative to the bounding box of your geometry. For example, let's say you only want half of your texture in v to be mapped to the mesh. In other APIs, you would just range your coordinate from 0.0 -> 0.5. If you do that in WPF3D without setting ViewportUnits to Absolute, it'll still map the entire thing. Essentially any time you don't want one copy of the entire texture you'll want to set Absolute.
  • We do not generate texture coordinates if you do not specify them. The only Brush that doesn't need texture coordinates is SolidColorBrush.
  • Tiling is controlled by TileBrush.TileMode which defaults to None. If you want to tile your texture, set Absolute, set TileMode to Tile, and then use texture coordinates that go past 1.0 (e.g. 0.0 -> 3.0 would tile it three times). Check out the TileMode docs for more options.

If you're having trouble coming up with texture coordinates, 3DTools has some basic texture coordinate generators. 

-- Jordan

Comments

  • Anonymous
    January 16, 2007
    I have been looking for how to create one-dimensional texture with either WPF or DirectX for a long time. It is pretty straightforward with OpenGL. Anyone knows if Microsoft provided this capability?

  • Anonymous
    January 16, 2007
    You can create a 1 x n image in WPF, but the common use for one dimensional textures is gradients, in which case you would want to use LinearGradientBrush.

  • Anonymous
    January 17, 2007
    If you're looking for OpenGL-style glTexCoord1, we don't have it. But like the first reply said, you can make a n x 1 image and then specify coordinates like (u, 0) -- Jordan