A texture is a function from a 2D texture coordinate in (0,0) - (1,1) space to a color. Textures are often created from images; consider any image brush in WPF:

Texture Normals0 = new ImageBrushBl("Resources/3977-normal0.jpg".ImageFor(typeof(Shaders)));
Texture Heights0 = new ImageBrushBl("Resources/3977-height0.jpg".ImageFor(typeof(Shaders)));
Texture Autumn = new ImageBrushBl("Resources/Autumn.jpg".ImageFor(typeof(TransitionsTest)));
Texture ImageBrushBl Dock = new ImageBrushBl("Resources/Dock.jpg".ImageFor(typeof(TransitionsTest)));

Image textures in DirectX are created a bit differently via a rendering device:

Texture Autumn = Device.TextureFromUri("Resources/Autumn.jpg".MakePackUri(typeof(D3DTest)));

A texture can also be formed directly from a in-code function, e.g., consider the following method that creates a meta-ball texture:

public Texture MetaBalls(IListBl<PointBl> Points, IListBl<ColorBl> BallColors) {
 return new Texture(UV => {
  ColorBl color = Colors.Black;
  DoubleBl metaball = 0;
  for (int i = 0; i < Points.Count; i++) {
   PointBl p = Points[i];
   PointBl v = (UV - Points[i]);
   v = v * v;
   DoubleBl at = 3d / (v.X + v.Y);
   color += BallColors[i] * at;
   metaball += at;
  }
  ColorBl useColor = color / metaball;
  return (metaball > .0016).Condition(useColor, Colors.White);
 });
}

The texture abstraction itself supports color-based operations and combinations. Consider lerping between two textures t0 and t1 as slider.Value.Lerp(t0 , t1), which forms a texture that implements a basic fade transition from t0 to t1. As with other Bling graphic functions, operations on textures are merely syntactic sugar for expanding out the functions and applying the operation directly to the resulting colors; e.g., the lerp above can be written out as:
new Texture(p => slider.Value.Lerp(t0(p), t1(p)))
Other useful texture operations include max, min, clamp, multiplication, and so on, and are often referred to as filtering. Textures also support distortions re-arrange its pixels by texture coordinate transformations. Example:
input.Distort(UV => UV + (UV - 0.5).Perpendicular.Normalize * 0.1)
This distort will cause a 10% swirl about the center of the texture.

Related

  • Textures can be explicitly converted into normal maps or height fields by explicit casts. These conversions are based on standard normal map and height field texture encodings produced by popular bump mapping tools, and are meant as a bump mapping convenience.
  • Pixel effects map textures to new textures and are basically the core of a pixel shader.

Last edited Jul 20, 2009 at 2:43 PM by mcdirmid, version 4

Comments

No comments yet.