qcycp

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Cg - The Cg Tutorial Ch5. Lighting 筆記

1.  In the past, fixed-function graphics pipelines were limited to one lighting model, which we call
     the fixed-function lighting model. With the advent of Cg and programmable hardware, you can
     now express complicated lighting models concisely using a high-level language.

 

2.  OpenGL and Direct3D perform the lighting computations in eye space rather than object space. 
     Eye space is more efficient than object space when there are multiple lights, but object space
     is easier to implement.

 

3. Swizzling allows you to rearrange the components of a vector to create a new vector—in any way
    that you choose. For example,
    float4 a = float4(1.0, 2.0, 3.0, 4.0);
    float3 b = a.zzx; // b = (3.0, 3.0, 1.0)
    float2 scalar = myMatrix._m23_m13; // set scalar to (myMatrix[2][3], myMatrix[1][3])

 

4.  Write masking allows only specified components of a vector to be updated by an assignment.
     Fpr example, 
     // Assume that initially vec1 = (4.0, -2.0, 5.0, 3.0) and vec2 = (-2.0, 4.0);
     vec1.xw = vec2;  // Now vec1 = (-2.0, -2.0, 5.0, 4.0)
     On
 the modern GPUs, swizzling and write masking are operations that have no performance penality.

 

5.  With per-vertex lighting, lighting is calculated only at each vertex of each triangle. The lighting is then
     interpolated for each fragment that is generated for the triangle. This approach, called smooth color
     interpolation or Gouraud shading, can miss details because the lighting equation is not actually evaluated
     for each fragment.

     p.s. triangle mesh切割的越細,則效果越近似phong shading.

6.  Instead of interpolating the final lit color, the surface normals are interpolated. Then, the fragment
     program uses the interpolated surface normals to calculate the lighting at each pixel. This technique
     is called Phong shading.

 

7.  Per-fragment calculations aren't free. In most cases, there will be more fragments in the frame
     than there are vertices, which means that the fragment program needs to run many more times
     than the vertex program. Therefore, longer fragment programs tend to have a more significant
     impact on performance than longer vertex programs.

 

8.  Unlike functions in C or C++, functions in Cg are typically inlined (though this may depend on the profile
     —advanced profiles such as vp30 can support function calls in addition to inlining). Inlining functions
     means that they have no associated function-call overhead. Therefore, you should use functions whenever
     possible, because they improve readability, simplify debugging, encourage reuse, and make future optimization easier.

 

9.  Cg supports arrays much as C does. An important difference from C is that arrays are first-class
     types in Cg. This means that array assignments actually copy the entire array, and arrays that are
     passed as parameters are passed by value (the entire array is copied before making any changes),
     rather than by reference.

 

10. Consider rays from the Sun that light objects on Earth. All the rays seem to come from the same 
     direction because the Sun is so far away. In such a situation, it does not make sense to calculate a
     spotlight effect or to add attenuation, because all objects receive essentially the same amount of light.
     A light with this property is called a directional light. Directional lights do not exist in reality, but in
     computer graphics, it is often worthwhile to identify situations in which a directional light is sufficient.

posted on 2009-02-11 22:33  qcycp  阅读(253)  评论(0)    收藏  举报