- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Add HLSL Per-Pixel Lighting in Office Word
6-7. Add HLSL Per-Pixel Lighting DataMatrix Generation In None Using Barcode creation for Word Control to generate, create ECC200 image in Word applications. www.OnBarcode.comPaint UPC Code In None Using Barcode generation for Microsoft Word Control to generate, create UPC Code image in Office Word applications. www.OnBarcode.comThe Problem
QR Creation In None Using Barcode printer for Microsoft Word Control to generate, create QR Code JIS X 0510 image in Word applications. www.OnBarcode.comEncode Barcode In None Using Barcode encoder for Microsoft Word Control to generate, create Barcode image in Word applications. www.OnBarcode.comAs shown in recipe 6-3, the best lighting results are obtained using per-pixel lighting, especially for curvy surfaces made out of large triangles. You want to add per-pixel lighting to your own effects. Encoding Code-128 In None Using Barcode generation for Word Control to generate, create Code 128 Code Set B image in Office Word applications. www.OnBarcode.comGenerate EAN / UCC - 14 In None Using Barcode generation for Office Word Control to generate, create GS1 128 image in Office Word applications. www.OnBarcode.comThe Solution
Barcode Maker In None Using Barcode creator for Microsoft Word Control to generate, create Barcode image in Word applications. www.OnBarcode.comUSPS Intelligent Mail Generation In None Using Barcode creation for Microsoft Word Control to generate, create USPS Intelligent Mail image in Word applications. www.OnBarcode.comIn the previous two recipes, you calculated the shading value in each vertex. The shading values of the three vertices of a triangle were linearly interpolated to obtain the shading value for each pixel. Printing Data Matrix ECC200 In VS .NET Using Barcode maker for Reporting Service Control to generate, create Data Matrix ECC200 image in Reporting Service applications. www.OnBarcode.comDataMatrix Creator In None Using Barcode drawer for Online Control to generate, create ECC200 image in Online applications. www.OnBarcode.comCH A PT ER 6 A DD I NG LI GHT T O YOUR SC ENE I N XN A 2.0
Painting Barcode In .NET Framework Using Barcode creation for Reporting Service Control to generate, create Barcode image in Reporting Service applications. www.OnBarcode.comEAN / UCC - 13 Decoder In Visual Studio .NET Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comIn the case of per-pixel lighting, you want to interpolate the normal of the three vertices to obtain the normal in each pixel so that in each pixel you can calculate the lighting factor based on the correct normal. However, as with interpolated shading, you will get faulty results when interpolating the normal from vertex to vertex. This is shown on the left side of Figure 6-9. The flat line indicates a triangle, of which the vertices contain the normal. When you interpolate these two normals over the pixels in the triangle, the interpolated normal will always follow the dotted line. In the center of the triangle, although the interpolated normal will have the correct direction, it will be smaller than the exact normal in that pixel, which is shown in the image. Code 128 Code Set B Drawer In Objective-C Using Barcode generation for iPad Control to generate, create Code-128 image in iPad applications. www.OnBarcode.comLinear 1D Barcode Maker In Java Using Barcode creator for Java Control to generate, create 1D Barcode image in Java applications. www.OnBarcode.comFigure 6-9. Linear interpolation from vertex to pixel shader fails The solution is in receiving this interpolated normal in the pixel shader. Because its direction is correct, you can normalize it to make the resulting normal of unity length. Because this scaling factor is different for each pixel, you need to do this in the pixel shader. PDF417 Reader In .NET Using Barcode recognizer for .NET framework Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comEAN / UCC - 13 Encoder In .NET Using Barcode generation for Reporting Service Control to generate, create EAN13 image in Reporting Service applications. www.OnBarcode.com Note To see why you want to make the length of your normal equal 1, read the Normalize Your Normals section in recipe 6-1. Smaller normals will lead to smaller lighting intensities, while you want the lighting intensity to depend only on the angle between the normal and the incoming light. Barcode Drawer In Visual C# Using Barcode creation for .NET Control to generate, create Barcode image in .NET framework applications. www.OnBarcode.comGS1-128 Printer In Java Using Barcode generation for BIRT reports Control to generate, create USS-128 image in Eclipse BIRT applications. www.OnBarcode.comThe direction of the light has an identical problem, as shown in the right part of Figure 6-9. The length of the interpolated light direction will follow the dotted curve, which will lead to vectors that are shorter than they should be. Again, you can solve this by normalizing the interpolated light direction in the pixel shader. Generating UPC-A Supplement 5 In VS .NET Using Barcode creation for Reporting Service Control to generate, create UPC A image in Reporting Service applications. www.OnBarcode.comGenerating Code 128 In Visual C# Using Barcode drawer for .NET framework Control to generate, create USS Code 128 image in Visual Studio .NET applications. www.OnBarcode.comHow It Works
As with all recipes in this chapter, your XNA project must interact with your graphics card to render triangles from some vertices that contain at least the 3D position and normal. You want to design your effect so your XNA code can set the World, View, and Projection matrices, as well as the 3D position of the point light and ambient light in your scene: float4x4 xWorld; float4x4 xView; float4x4 xProjection; float3 xLightPosition; float xAmbient; CHAPTER 6 ADDIN G LIGHT TO Y OUR SCE NE IN XNA 2.0
struct PPSVertexToPixel { float4 Position float3 Normal float3 LightDirection }; struct PPSPixelToFrame { float4 Color }; : POSITION; : TEXCOORD0; : TEXCOORD1; : COLOR0; As explained earlier, your vertex shader will output the normal, which will be interpolated over all pixels of the triangle as well as the direction of the light going from your point light to the vertex. The pixel shader has to calculate only the final color of each pixel. Note In the simpler case of a directional light, the direction of the light will be an XNA-to-HLSL variable, which is constant for all vertices and pixels. Therefore, the vertex shader will not need to calculate this. Vertex Shader
The vertex shader receives the normal from the vertex, rotates it with the rotation contained in the World matrix (see recipe 6-5), and passes it on to the pixel shader. It also calculates the light direction by subtracting the position of the point light from the position of the vertex (see recipe 6-5). You take into account that the final 3D position of the vertex depends on the current World matrix. PPSVertexToPixel PPSVertexShader(float4 inPos: POSITION0, float3 inNormal: NORMAL0) { PPSVertexToPixel Output = (PPSVertexToPixel)0; float4x4 preViewProjection = mul(xView, xProjection); float4x4 preWorldViewProjection = mul(xWorld, preViewProjection); Output.Position = mul(inPos, preWorldViewProjection); float3 final3DPos = mul(inPos, xWorld); Output.LightDirection = final3DPos - xLightPosition; float3x3 rotMatrix = (float3x3)xWorld; float3 rotNormal = mul(inNormal, rotMatrix); Output.Normal = rotNormal; return Output; }
|
|