D3DBook:(Lighting) Strauss

From GDWiki
Jump to: navigation, search

Contents

Strauss

Despite being published in 1990, Paul Strauss’s model ([Strauss90]) only seemed to come to the foreground with the advent of Futuremark’s 3DMark 2006 software. When such benchmarking software uses (or invents) a new ‘buzzword’ for an algorithm that generates better image quality or performance people tend to sit up and pay attention. This is particularly interesting as the model proposed by Strauss doesn’t introduce any novel new features not seen in other lighting models; instead it is intended to match the realism of existing models and focus on the usability for artists.

When used effectively the other models discussed in this section can represent a wide range of materials very accurately but the key word is “effective.” Each of the models have a variety of inputs (although given time a certain commonality can be seen between most of them) each of which are defined in similar but subtly different ways. For software authors who often have scientific and mathematical backgrounds this rarely causes a problem yet in most cases it is not the author of the implementation that becomes the primary user of the functionality.

Not only is each individual parameter a potential for confusion the number of parameters can also be a usability concern. Each additional parameter into a lighting model increases the number of possible combinations and makes it increasingly difficult for an artist to remember all combinations and their relationships. Many lighting models expose coefficients to control each and every aspect of the model under the pretence that it makes the model more expressive and thus capable of representing a larger class of materials – too much control can be a bad thing!

A particularly bad characteristic of many parameters with arbitrary ranges of inputs is that they often allow for completely incorrect materials to be represented. Unless the application checks and constrains illegal values it becomes all too easy to generate a completely unrealistic material.

Strauss’ model therefore aims to simplify the interface to lighting models by providing an intuitive and well-defined set of inputs that can be grasped without a deep understanding of the underlying mathematics. This should allow an artist to be more productive without diminishing the quality. Given that real-time graphics applications, especially games, are focussing more and more on artwork this can only be a good thing.

Parameters to the Strauss Model

All parameters into Strauss’ lighting model, except one, are defined in the 0.0 to 1.0 range and any vectors are all normalized to unit length. This immediately gets around the problem of other lighting models having arbitrary ranges for parameters.

Five parameters are used to control the model:

c The basic colour of the surface, an RGB triplet each of which defined between 0.0 and 1.0.
s Smoothness of the surface. A value of 0.0 defines a rough diffuse surface and 1.0 generates a perfectly specular mirror.
m ‘Metalness’ of the surface; A value of 0.0 indicates completely non-metallic and 1.0 is completely metallic.
t Transparency of the surface; A value of 0.0 defines a completely opaque surface and 1.0 is completely transparent. Note that this simulates how light energy works and doesn’t actually control traditional alpha-blending transparency used in rendering (but both values should be the same)
n Index of refraction; this is the one input parameter that is not bound to the 0.0 – 1.0 range due to it being a ratio. Refer to the first chapter of this section for more details on determining this value.

Whilst the index of refraction is referred to as one of the five key descriptors of a surface’s characteristics it doesn’t actually feature in the lighting equation implemented later in this chapter. Strauss utilizes the index of refraction in the context of ray-tracing and global illumination – neither of which is covered by this section of the book.

Consequently the Strauss mode implemented in HLSL requires only four parameters, all of which are defined in the 0.0 to 1.0 range.

As with other lighting models, the Strauss model still relies on normal, light and view direction vectors. However it is unlikely that an artist would have to explicitly work with these vectors – they are more likely to be provided by the application.

The Strauss Lighting Model

The previous section introduced the five inputs into the model and this section describes how they are actually put together in mathematical form before the next section showing how this model is implemented as a pixel shader.

Output = Light \times (Diffuse + Specular)

The resultant colour for the given material and lighting conditions is defined by the product of the diffuse and specular components scaled by the intensity of the light from the current source.

Breaking down the diffuse term gives:

Diffuse = (Normal \bullet Light) \times (1 - m \times s) \times (1 - s^3) \times (1 - t) \times c

Part of the above equation is standard – the dot-product of Normal and Light directions scaled by the colour of the material. The middle three terms are new though – the model determines that the diffuse component is essentially a product of its transparency and smoothness but that its ‘metalness’ is also a contributing factor. The Oren-Nayar model from the previous chapter shows how a rough surface has a very matt diffuse appearance with limited to no specular highlights, whereas a well balanced Cook-Torrance metal has limited diffuse but substantial specular.

As with other models discussed in this section of the book the specular term is more involved than the diffuse term.

Specular = (-(Highlight \bullet View))^{\frac{3}{1 - s}} \times Reflect \times C_s

Reflect = min\left \lbrack 1, r + j \times (r + k) \right \rbrack

r = (1 - t) - (1 - s^3) \times (1 - t)

j = fresnel\left \lbrack Normal \bullet Light \right \rbrack \times shadow\left \lbrack Normal \bullet Light \right \rbrack \times shadow\left \lbrack Normal \bullet View \right \rbrack

The k term in the preceding equation is a constant used to provide a small off-specular peak for very rough surfaces. It is noted that a value of 0.1 yields good results – but this can legitimately be left as an implementation detail rather than exposed to the artist.

As introduced in the Cook-Torrance model, the colour of reflected specular light energy is non-constant (as it was approximated in Phong’s model) and is actually a very important factor in creating realistic looking lighting.

The specular equation includes the Cs term that evaluates the colour of the specular highlight using the following evaluation:

C_s = C_1 + m \times (1 - fresnel\left \lbrack Normal \bullet Light \right \rbrack) \times (c - C_1)

C_1 = rgb\left \lbrack 1, 1, 1 \right \rbrack = white

Evaluation of the specular term sees the return of the Fresnel and shadow functions first introduced as part of the Cook-Torrance models. There is no reason why the Cook-Torrance distributions could not be plugged into the Strauss model – both papers comment on how various distributions were tested and can be more or less appropriate for specific situations.

Strauss’ paper proposes the use of the distributions used by the Brown Animation Generation System ([Strauss88]):

fresnel\left \lbrack x \right \rbrack = \frac{\frac{1}{(x - k_f)^2} - \frac{1}{k_f^2}}{\frac{1}{(1 - k_f)^2} - \frac{1}{k_f^2}}

shadow\left \lbrack x \right \rbrack = \frac{\frac{1}{(1 - k_s)^2} - \frac{1}{(x - k_s)^2}}{\frac{1}{(1 - k_s)^2} - \frac{1}{k_s^2}}

The constants of Kf and Ks are arbitrary and should really be left as implementation details rather than pushed up to the artist. Strauss notes that values of 1.12 for Kf and 1.01 for Ks produce good results.

Implementation

The model described in this chapter can be implemented by using the following code and controlled by a diffuse texture and four per-material constants. If desirable, the m and s inputs could be mapped to a texture to allow per-pixel variations and the t value could be mapped to the alpha channel of the diffuse texture if present.

float4 psStrauss( in VS_OUTPUT f ) : SV_TARGET
{
    // Make sure the interpolated inputs and
    // constant parameters are normalized
    float3 n = normalize( f.normal );
    float3 l = normalize( -vLightDirection );
    float3 v = normalize( pCameraPosition - f.world );
    float3 h = reflect( l, n );
 
    // Declare any aliases:
    float NdotL   = dot( n, l );
    float NdotV   = dot( n, v );
    float HdotV   = dot( h, v );
    float fNdotL  = fresnel( NdotL );
    float s_cubed = fSmoothness * fSmoothness * fSmoothness;
 
    // Evaluate the diffuse term
    float d  = ( 1.0f - fMetalness * fSmoothness );
    float Rd = ( 1.0f - s_cubed ) * ( 1.0f - fTransparency );
    float3 diffuse = NdotL * d * Rd * cDiffuse;
 
    // Compute the inputs into the specular term
    float r = ( 1.0f - fTransparency ) - Rd;
 
    float j = fNdotL * shadow( NdotL ) * shadow( NdotV );
 
    // 'k' is used to provide small off-specular
    // peak for very rough surfaces. Can be changed
    // to suit desired results...
    const float k = 0.1f;
    float reflect = min( 1.0f, r + j * ( r + k ) );
 
    float3 C1 = float3( 1.0f, 1.0f, 1.0f );
    float3 Cs = C1 + fMetalness * (1.0f - fNdotL) * (cDiffuse - C1);
 
    // Evaluate the specular term
    float3 specular = Cs * reflect;
    specular *= pow( -HdotV, 3.0f / (1.0f - fSmoothness) );
 
    // Composite the final result, ensuring
    // the values are >= 0.0f yields better results. Some
    // combinations of inputs generate negative values which
    // looks wrong when rendered...
    diffuse  = max( 0.0f, diffuse );
    specular = max( 0.0f, specular );
    return float4( diffuse + specular, 1.0f );
}

Due to Strauss defining the inputs to his model in the 0.0 to 1.0 range it is trivial to replace many terms with look-up textures. As has been shown in previous chapters it is also straight-forward to re-map dot products from -1.0-1.0 to 0.0-1.0 ranges. The evaluation of ‘j’ from the preceding HLSL code is a good candidate for a look-up texture. If it is possible to eliminate the transparency parameter (a lot of materials will always be opaque such that this can be set to a constant 1.0) then many other terms of Strauss’ model can be factored out into a 2D texture.

Results

Of the four main inputs into Strauss’ model the most significant are metalness and smoothness. Transparency has an important effect, but is only really noticeable when combined with standard frame-buffer blending algorithms. The following image shows the relationship between the two significant inputs:

image:Image_7.1.png
Image 7.1

The flexibility of this model is immediately apparent by the wide range of materials that can be represented. The top-left shows a very diffuse image similar to those produced by the Oren-Nayar lighting model, and whilst it might seem odd the bottom-right is a perfectly reflective metal.

The reflective metal being mostly black is a by-product of homogenous materials and the way that no light is absorbed by the material (which results in a 0 diffuse contribution) and all of it is reflected – but this is very view dependent. In reality it is unlikely to see such a perfect material, and the more complex lighting environments would result in more visible reflected light.

Despite combining qualities of many other lighting models the assembly output for the Strauss lighting model is very favourable. Weighing in at only 46 instructions it isn’t quite the cheapest model but it is definitely not the most expensive. All aspects considered – especially the usability of its inputs – the Strauss model is a prime candidate for any lighting engine.

References

[Strauss90] “A Realistic Lighting Model for Computer Animators”, Paul S. Strauss, IEEE Computer Graphics and Applications, Volume 10, Issue 6 (November 1990), Pages 56-64. [Strauss88] “BAGS: The Brown Animation Generation System”, Paul S. Strauss, Brown University 1988.

Navigate to other chapters in this section:

Foundation & Theory Direct Light Sources Techniques For Dynamic Per-Pixel Lighting Phong and Blinn-Phong Cook-Torrance Oren-Nayar Strauss Ward Ashikhmin-Shirley Comparison and Summary
Personal tools