- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
2: Multilayered Textures in .NET framework
Example 2: Multilayered Textures QR-Code Printer In VS .NET Using Barcode maker for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications. www.OnBarcode.comBarcode Encoder In Visual Studio .NET Using Barcode generation for ASP.NET Control to generate, create bar code image in ASP.NET applications. www.OnBarcode.comThe second example illustrates multitexture blending with a pixel shader. Recall from 4 that the fixed function pipeline uses a texture sampler and the multitexture blender to accomplish the tasks in pixel processing part 1, including blending the diffuse color, specular color, and up to eight texture colors. When you replace the fixed function pipeline with a programmable pixel shader, you implement all the texture blending in the shader. A programmable pixel shader still relies on the texture samplers to sample textures. This example blends two textures in the pixel shader. A ps_2_0 shader (or higher) supports 16 samplers, so you can support up to a 16-layer blend. The first texture layer provides the foundation (See Color Plate 8.) The second texture layer adds a layer on top. (See Color Plate 11.) The blending equation is a mathematical combination of the pixel color components. Here s the pixel shader that blends the two texture layers: QR Code JIS X 0510 Generation In C# Using Barcode generator for .NET framework Control to generate, create Denso QR Bar Code image in VS .NET applications. www.OnBarcode.comQR Code Drawer In .NET Using Barcode drawer for Visual Studio .NET Control to generate, create QR Code image in VS .NET applications. www.OnBarcode.comps_2_x def def def def c0, c1, c2, c3, // version instruction 0,0,0,0 1,1,1,1 1.0,0.5,0.25,0 0.2,0.2,0.2,0.2 QR Drawer In VB.NET Using Barcode encoder for .NET framework Control to generate, create Denso QR Bar Code image in .NET framework applications. www.OnBarcode.comPainting Bar Code In Visual Studio .NET Using Barcode generator for ASP.NET Control to generate, create barcode image in ASP.NET applications. www.OnBarcode.comdcl_2d s0 dcl t0
Bar Code Drawer In VS .NET Using Barcode generator for ASP.NET Control to generate, create bar code image in ASP.NET applications. www.OnBarcode.comGS1 - 13 Encoder In Visual Studio .NET Using Barcode maker for ASP.NET Control to generate, create EAN13 image in ASP.NET applications. www.OnBarcode.comPart I Programming Assembly-Language Shaders
Code 128C Printer In VS .NET Using Barcode generation for ASP.NET Control to generate, create USS Code 128 image in ASP.NET applications. www.OnBarcode.comData Matrix Creation In Visual Studio .NET Using Barcode drawer for ASP.NET Control to generate, create Data Matrix 2d barcode image in ASP.NET applications. www.OnBarcode.comdcl_2d s1 dcl t1 texld r0, t0, s0 texld r1, t0, s1 lrp r2, c2, r0, r1 mov oC0, r2
UPC-A Supplement 2 Generation In VS .NET Using Barcode maker for ASP.NET Control to generate, create UPC A image in ASP.NET applications. www.OnBarcode.comBritish Royal Mail 4-State Customer Code Drawer In Visual Studio .NET Using Barcode drawer for ASP.NET Control to generate, create British Royal Mail 4-State Customer Code image in ASP.NET applications. www.OnBarcode.comLike all pixel shaders, this one starts with a version instruction and some constant definitions. This pixel shader uses version ps_2_x, which has a few changes from ps_1_1. In ps_2_x, texture registers and sampler registers have to be declared before they re used. A sampler declaration looks like this: Decode Code 39 In Visual C# Using Barcode scanner for .NET Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comRead Barcode In Java Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comdcl_2d s0
Scanning ANSI/AIM Code 128 In Java Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comCode 128B Drawer In Java Using Barcode creation for Android Control to generate, create Code 128 Code Set A image in Android applications. www.OnBarcode.comThis register declaration uses the dcl_samplerType instruction, where the samplerType is a 2-D texture (2d). Therefore, when a texture gets sampled, the sampler s0 requires a 2-D texture coordinate. ps_2_x supports 1-D, 2-D, and 3-D texture coordinates. The sampler declaration has the following texture coordinate register declaration that goes with it: Draw USS Code 128 In Visual Studio .NET Using Barcode generation for Reporting Service Control to generate, create USS Code 128 image in Reporting Service applications. www.OnBarcode.comBar Code Generator In Java Using Barcode creation for Eclipse BIRT Control to generate, create barcode image in BIRT applications. www.OnBarcode.comdcl t0
Bar Code Creator In None Using Barcode creator for Office Excel Control to generate, create barcode image in Office Excel applications. www.OnBarcode.comUPC - 13 Creator In None Using Barcode maker for Font Control to generate, create UPC - 13 image in Font applications. www.OnBarcode.comThis register declaration uses the dcl instruction to identify the data type that will be streamed into the t0 register. The data streamed into a pixel shader input register is interpolated vertex data from primitive processing, which in this case is texture coordinate data. This shader has two texture registers and two samplers declared because the shader will be using two textures. Don t forget that the textures still need to be set to the texture samplers and that the sampler state still needs to be set. Here s the code to finish setting up the samplers and the sampler state: // texture sampler 0 m_pd3dDevice->SetTexture( 0, m_pTexture0 ); m_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); m_pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); m_pd3dDevice->SetTexture( 1, m_pTexture1 ); m_pd3dDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pd3dDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); m_pd3dDevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); m_pd3dDevice->SetTexture( 2, NULL ); 5 Pixel Shader Examples
Now that the texture coordinate register and the sampler are declared, the textures are set to the texture stages, and the sampler state is initialized, the shader is ready for the texture sampling instructions. texld r0, t0, s0 texld r1, t0, s1
ps_2_x uses the texld instruction to perform the texture sampling. It takes the texture coordinate register and the sample registers we just defined and returns the texture color in the r0 or r1 destination register. The last two shader instructions blend the two textures together using the linear interpolate instruction, lrp. This instruction combines the two texture colors together using the per-component scale factor in the c2 constant register. Because c2 contains (1,0.5, 0.25,0), the results are as follows: All the red from image 1 and none of the red from image 2 Half of the green from image 1 and half of the green from image 2 Twenty-five percent of the blue from image 1 and 75 percent of the blue from image 2 None of the alpha from image 1 and all the alpha from image 2 The blended result combines the two images. (See Color Plate 12.) Not only does the result clearly show both layers, but the earth is missing most of its blue component, which is why it appears more red and green than the original layer was. As usual, the rest of the resource creation code is in RestoreDeviceObjects. This code can be seen in the application on the enclosed CD. Instead of going through that again, let s take a look at what this example would have looked like if we had not used a programmable shader. Here s the programmable shader code that blends the two texture samples together: def c2, 1.0,0.5,0.25,0 lrp r2, c2, r0, r1 mov oC0, r2 // per-component blend factors // per-component linear interpolate function // output result In contrast, here s the API calls that you would make in the fixed function pipeline to initialize the multitexture blender to blend the same two textures together: // Fixed function multitexture blender set up that // is no longer needed m_pd3dDevice->SetTexture(0, m_pTexture0); m_pd3dDevice->SetTexture(1, m_pTexture1);
|
|