Graphics Reference
In-Depth Information
Material properties. The material properties of an object determine how it looks at a
basic level. Typical material properties include things like the base color of an object,
some coefficients to describe how reflective the surface is, and perhaps a texture map that
represents the fine surface color variations. We will assume that the pixel shader receives
the vertex normal vector and texture coordinates as interpolated input attributes. The pixel
shader program will calculate the color of the object's material with the function shown in
Listing 3.23.
float4 PSMAIN( in VS_OUTPUT input ) : SV_Target
{
// Determine the color properties of the surface from a texture
float4 SurfaceColor = ColorTexture.Sample( LinearSampler, input.tex );
II Return the surface color
return( SurfaceColor * input.color );
}
Listing 3.23. A sample pixel shader to calculate the color of an object's material.
In a typical scene, many different objects need to be rendered, and each one will
require at least partially different properties from the others. For this example, we will
assume that the pixel shader is common among each of the objects being rendered. With
this in mind, we can step through a few object rendering sequences and consider what is
different between each one with respect to the pixel shader. We will assume there are three
objects in the scene, called objects A, B, and C. For each of these objects to be rendered,
the pipeline must be configured with the object properties prior to execution of the pipeline
with one of the draw calls.
When the pipeline is configured to render object A, the object's texture is bound to
the pipeline with a shader resource view, and its color is specified by binding a constant
buffer to the pixel shader stage containing the appropriate color. Each of the generated
fragments is passed to the pixel shader, where the texture is sampled and multiplied by the
color supplied in the constant buffer, as shown in Listing 3.23. After this pipeline execu-
tion completes, the application would configure the pipeline for rendering object B. This
would require binding a different texture and color constant buffer, followed by pipeline
execution. Object C would follow the same pattern, but in this case, it would use the same
texture as object B, and only a new color constant buffer would be needed.
This short sequence demonstrates that an object's material properties are typically
supplied as resources external to the shader program itself. Both the color and texture of a
model are controlled by the application manipulating the pixel shader stage's states, rather
than by swapping the pixel shader program in and out. In addition, the geometry that is
passed through the pipeline doesn't really matter to the material properties. In all three
Search WWH ::




Custom Search