Character Animation with Direct3D- P16

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:20

0
36
lượt xem
3

Character Animation with Direct3D- P16

Mô tả tài liệu

Character Animation with Direct3D- P16:This book is primarily aimed at teaching indie and hobby game developers how to create character animation with Direct3D. Also, the seasoned professional game developer may find some interesting things in this book. You will need a solid understanding of the C++ programming language as well as general object-oriented programming skills.

Chủ đề:

Bình luận(0)

Lưu

Nội dung Text: Character Animation with Direct3D- P16

1. 286 Character Animation with Direct3D //Calculating the binormal and setting //the tangent binormal and normal matrix float3x3 TBNMatrix = float3x3(tangent, binormal, normal); //Setting the lightVector OUT.lightVec = mul(TBNMatrix, lightDir); OUT.lightHalf = mul(TBNMatrix, vHalf); OUT.tex0 = IN.tex0; return OUT; } //Pixel Shader float4 morphNormalMapPS(VS_OUTPUT IN) : COLOR0 { //Calculate the color and the normal float4 color = tex2D(DiffuseSampler, IN.tex0); //This is how you uncompress a normal map float3 normal = 2.0f * tex2D(NormalSampler, IN.tex0).rgb - 1.0f; //Get specular float4 specularColor = tex2D(SpecularSampler, IN.tex0); //Set the output color float diffuse = max(saturate( dot(normal, normalize(IN.lightVec))), 0.2f); float specular = max(saturate( dot(normal, normalize(IN.lightHalf))), 0.0f); specular = pow(specular, 85.0f) * 0.4f; return color * diffuse + specularColor * specular; } Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
2. Chapter 12 Wrinkle Maps 287 EXAMPLE 12.2 Example 12.2 contains all the code for implementing specular highlights. Play around with the shininess value in the pixel shader, and if you have good image-editing software, play around with the specular map as well. This example also implements specular highlights for the old diffuse lighting model (used for the eyes in the example, which are not normal mapped). Figure 12.13 shows another screenshot of the Soldier’s face using somewhat “exaggerated” highlights. Note that this isn’t the kind of result you’d actually want for skin. The examples and images in this chapter are a bit exaggerated to emphasize the effect of the specular highlights. ease purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
3. 288 Character Animation with Direct3D FIGURE 12.13 Exaggerated highlights. W RINKLE M APS You’ve now arrived at the goal of this chapter: the wrinkle maps. These maps are basically an animated or weighted normal map that is connected to the move- ment of the face. For example, smiling may reveal the dimples in the cheeks of the characters. These small deformations occur as a result of the underlying muscles in the face moving. Another example of this phenomenon is wrinkles that appear (or disappear) on the forehead as a person raises or lowers his or her eyebrows. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
4. Chapter 12 Wrinkle Maps 289 The use of wrinkle maps in games is still a recent addition, and most games today don’t bother with it unless the characters are shown in close-up. Figure 12.14 shows a grayscale image of a normal map containing wrinkles for the forehead and dimples. FIGURE 12.14 Wrinkle normal map. Note that the wrinkles in Figure 12.14 have been made somewhat extreme to stand out a bit better (for educational purposes). Normally, wrinkle maps are something you don’t want sticking out like a sore thumb. Rather, they should be a background effect that doesn’t steal too much of the focus. Next, you need to encode which regions of the wrinkle map should be affected by which facial movements. In the upcoming wrinkle map example, I’ve used a separate texture to store masking of the wrinkle map regions. You could, however, also store this data in the vertex color, for example. Figure 12.15 shows the mask used to define the three different regions of the wrinkle map. ease purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
6. Chapter 12 Wrinkle Maps 291 w = min( w, 1.0f ); normal.x *= w; normal.y *= w; //Re-normalize normal = normalize( normal ); //Normalize the light float3 light = normalize(IN.lightVec); //Set the output color float diffuse = max(saturate(dot(normal, light)), 0.2f); return color * diffuse; } EXAMPLE 12.3 Example 12.3 has the full implementation for the wrinkle maps. You can find how the weights for the forehead and dimples are set in the render method of the Face class. ease purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
7. 292 Character Animation with Direct3D Figure 12.16 shows the wrinkle maps in action. FIGURE 12.16 Wrinkle maps in action. Thanks to Henrik Enqvist at Remedy Entertainment for the idea of covering wrinkle maps. He also graciously supplied the example code for the wrinkle map example. C ONCLUSIONS This chapter covered all aspects of normal mapping, from the theory of normal maps to how to create them and how to apply them on a real-time character. This base knowledge then allows you to implement the more advanced wrinkle maps as an animated extension to normal maps. I hope you managed to understand all the steps of this somewhat complex process so that you’ll be able to use it in your own projects. The DirectX SDK also has skinned characters with high-quality normal maps, which are excellent to play around with. I also touched briefly on implementing a specular lighting model—something that, together with normal maps, really makes your character “shine.” After the slight sidetrack this chapter has taken, I’ll return to more mainstream character animation again. Next up is how to create crowd simulations. C HAPTER 12 E XERCISES Implement normal mapping for the SkinnedMesh class using the code in the Face class as a base. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
8. Chapter 12 Wrinkle Maps 293 Implement normal mapping without supplying the binormal from the mesh, but calculate it on-the-fly in the vertex shader. Implement support for multiple lights (for both normal mapping and specular highlights). F URTHER R EADING [Cloward] Cloward, Ben, “Creating and Using Normal Maps.” Available online at http://www.bencloward.com/tutorials_normal_maps1.shtml. [Gath06] Gath, Jakob, “Derivation of the Tangent Space Matrix.” Available online at http://www.blacksmith-studios.dk/projects/downloads/tangent_ matrix_derivation.php, 2006. [Green07] Green, Chris, “Efficient Self-Shadowed Radiosity Normal Mapping.” Available online at http://www.valvesoftware.com/publications/2007/SIGGRAPH 2007_EfficientSelfShadowedRadiosityNormalMapping.pdf, 2007. [Hess02] Hess, Josh, “Object Space Normal Mapping with Skeletal Animation Tutorial.” Available online at: http://www.3dkingdoms.com/tutorial.htm, 2002. [Lengyel01] Lengyel, Eric. “Computing Tangent Space Basis Vectors for an Arbitrary Mesh.” Terathon Software 3D Graphics Library. Available online at http://www.terathon.com/code/tangent.html, 2001. ease purchase PDF Split-Merge on www.verypdf.com to remove this watermark.