Any value large enough to separate adjacent cells a distance of more than one texel should suffice. They map the integral cell name to somewhere within the random texture and should have the property of mapping nearby cells to uncorrelated values. There's nothing magic about the scale factors used to compute randomUV. float2 randomUV = cell * float2(0.037, 0.119) fixed4 random = tex2D(randomTex, randomUV) The coordinates for the sample are derived from the cell's coordinates, scaled by small values. We use a two-dimensional texture filled with pseudo-random numbers for this task. Finding our location within the cell simply requires a subtraction: float2 offset = scaledUV - cell 20.1.2 Sampling the Imageīefore we can sample the image, we need to determine its location. The scale factor allows us to vary the size as needed. Adjacent cells differ by 1 in either cell.x or cell.y. Note that the cell's coordinates are integral. The cell's coordinates are computed simply, using a floor function of the pixel's UV parameters: float2 scaledUV = UV * scale int2 cell = floor(scaledUV) We can reduce the number of required samples to four by introducing a few minor restrictions on the images. If we limit the image size to be no bigger than a cell, then we need to sample only nine cells: both side cells, those above and below, and the four cells at the corners. Large cell images would require that we sample many adjacent images.
Therefore, we need to consider neighboring cells' images as well. If a cell's image is located close to the edge of its cell, or if it is larger than a cell, it will cross into adjacent cells. We assume here that a sample is either 100 percent opaque or transparent, to simplify the compositing step. Finally, we sample the image at its location within the cell and combine it with a default background color. We'll use these coordinates to access all of the cell's unique parameters, such as the image's location within that cell. We need to compute each cell's coordinates in a way that lets us quickly locate neighbor cells, as you will see later on. The first step is to find the cell containing the pixel. To start, let's view things from a pixel's perspective and try to pare down the work. We'll discuss both techniques in this chapter. We may also want to compute the image procedurally, which is somewhat incompatible with compositing. It's not very efficient to actually composite images in this manner, because we may have hundreds of images to combine. The final result is the composite of these images over the background. We then place an image within each cell at a random location, using a noise or pseudo-random number function. The basic idea behind texture bombing is to divide UV space into a regular grid of cells. Texture bombing is a procedural technique that places small images at irregular intervals to help reduce such pattern artifacts. Such uses require either a very large amount of texture data or repetition of the same pattern, resulting in an undesirable, regular look.
NVIDIA BOOK SHADER FULL
Textures are useful for adding visual detail to geometry, but they don't work as well when extended to cover large areas such as a field of flowers, or many similar objects such as a city full of buildings. Please visit our Recent Documents page to see all the latest whitepapers and conference presentations that can help you with your projects. You can purchase a beautifully printed version of this book, and others in the series, at a 30% discount courtesy of InformIT and Addison-Wesley. GPU Gems GPU Gems is now available, right here, online.