Graphics Reference
In-Depth Information
are implemented in hardware for speed. The values passed into the sampler
should be the number of the texture unit to be used to access the texture and
the texture coordinates. The type of the sampler defines the kind of texture
map that will be accessed. The available types are
sampler1D , sampler2D , and sampler3D are used to access standard 1D,
2D, and 3D textures, respectively.
samplerCube is used to access textures in a cube map.
sampler1DShadow or sampler2DShadow are used to access 1D or 2D
shadow textures when depth comparisons are enabled.
Samplers should be considered an opaque data type within a shader. The
suffix on the sampler type indicates the texture type to be accessed: 1D, 2D,
3D, cube map, 1D shadow, or 2D shadow. In OpenGL, a texture object of each
of the first four texture types can be bound to a single texture unit. This suffix
allows the desired texture object to be chosen. A 1D shadow sampler is used to
access the 1D texture when depth comparisons are enabled, and a 2D shadow
sampler is used to access the 2D texture when depth comparisons are enabled,
but we do not discuss shadow textures here. If two uniform variables of differ-
ent sampler types contain the same value, an error is generated when the next
rendering command is issued.
The function glUniform1i loads a uniform variable defined as a sampler
type with a texture unit number. Atempting to load a sampler with any other
function is an error. All shader types (vertex, tessellation, geometry, and frag-
ment) can use texture samplers.
Procedural Textures
We can use the term procedural texture for any process of developing textures
by programming rather than by geting textures as data arrays, and is a stan-
dard computer graphics technique. In the fixed-function OpenGL graphics
API, texture techniques are limited to computing data arrays to be used as
textures. With the advent of fragment shaders, however, we can compute color
values for each pixel during the fragment processing stage.
Computing the color value for each pixel has several advantages. One
advantage is resolution. When you use fixed-size data arrays for textures, the
texture dimensions are limited to the size of the data array. If you zoom into
your geometry enough, the fixed-size texture runs out of resolution and starts
looking “blocky.” However, if you compute the texture values for each pixel
in the fragment processor, you compute as much resolution as your equations
can create, and you avoid any blockiness. Another advantage of computing
Search WWH ::




Custom Search