Finishing Off the Billboarding Technique: Pixel Shader and Technique Definition in Office Word

Generate DataMatrix in Office Word Finishing Off the Billboarding Technique: Pixel Shader and Technique Definition

Finishing Off the Billboarding Technique: Pixel Shader and Technique Definition
Data Matrix Maker In None
Using Barcode generator for Microsoft Word Control to generate, create Data Matrix image in Microsoft Word applications.
www.OnBarcode.com
Create Data Matrix In None
Using Barcode drawer for Microsoft Word Control to generate, create Data Matrix image in Word applications.
www.OnBarcode.com
Now that your vertex shader is capable of calculating the correct 3D coordinates for the vertices, all you need to do is put the texture over the triangles in the pixel shader: BBPixelToFrame BillboardPS(BBVertexToPixel PSIn) : COLOR0 { BBPixelToFrame Output = (BBPixelToFrame)0; Output.Color = tex2D(textureSampler, PSIn.TexCoord); return Output; }
Generate USS Code 39 In None
Using Barcode maker for Microsoft Word Control to generate, create Code 3 of 9 image in Microsoft Word applications.
www.OnBarcode.com
Encode Barcode In None
Using Barcode creation for Microsoft Word Control to generate, create Barcode image in Microsoft Word applications.
www.OnBarcode.com
CHAPTER 3 WORKING WITH 2D IMAGES /TEXTURES IN XNA 2.0
Make EAN13 In None
Using Barcode generation for Microsoft Word Control to generate, create EAN13 image in Word applications.
www.OnBarcode.com
QR Maker In None
Using Barcode creation for Word Control to generate, create QR Code ISO/IEC18004 image in Microsoft Word applications.
www.OnBarcode.com
And of course here is the definition of the technique: technique CylBillboard { pass Pass0 { VertexShader = compile vs_1_1 CylBillboardVS(); PixelShader = compile ps_1_1 BillboardPS(); } } That will be all for the moment. All you need to do is import this HLSL file (which I called bbEffect.fx) into your project and load it into a variable in your LoadContent method: bbEffect = content.Load<Effect>("bbEffect"); Now in your Draw method, you can set the required XNA-to-HLSL variables and finally render the billboards! bbEffect.CurrentTechnique = bbEffect.Techniques["CylBillboard"]; bbEffect.Parameters["xWorld"].SetValue(Matrix.Identity); bbEffect.Parameters["xProjection"].SetValue(quatMousCam.ProjectionMatrix); bbEffect.Parameters["xView"].SetValue(quatMousCam.ViewMatrix); bbEffect.Parameters["xCamPos"].SetValue(quatMousCam.Position); bbEffect.Parameters["xAllowedRotDir"].SetValue(new Vector3(0,1,0)); bbEffect.Parameters["xBillboardTexture"].SetValue(myTexture); bbEffect.Begin(); foreach (EffectPass pass in bbEffect.CurrentTechnique.Passes) { pass.Begin(); device.VertexDeclaration = new VertexDeclaration(device, VertexPositionTexture.VertexElements); device.DrawUserPrimitives<VertexPositionTexture> (PrimitiveType.TriangleList, billboardVertices, 0, billboardList.Count*2); pass.End(); } bbEffect.End(); Note where you indicate, for example, the (0,1,0) Up direction as the rotational direction for your billboards. If your PC is equipped with a separate graphics card, you should be able to render many more billboards now than with the XNA-only version.
EAN / UCC - 13 Printer In None
Using Barcode creation for Word Control to generate, create EAN 128 image in Office Word applications.
www.OnBarcode.com
Create International Standard Serial Number In None
Using Barcode generator for Office Word Control to generate, create ISSN - 13 image in Office Word applications.
www.OnBarcode.com
C HA PTER 3 WORKING WITH 2D IMA GES/TEXTU RES IN XN A 2.0
DataMatrix Creation In Objective-C
Using Barcode generator for iPhone Control to generate, create DataMatrix image in iPhone applications.
www.OnBarcode.com
Reading ECC200 In C#
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Vertex Shader for Spherical Billboarding
Painting UCC-128 In Java
Using Barcode encoder for BIRT Control to generate, create UCC - 12 image in Eclipse BIRT applications.
www.OnBarcode.com
ECC200 Reader In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
The difference between cylindrical and spherical billboarding is that in spherical billboarding each billboard has to completely face the camera. In the words of your vertex shader code, both the Up and the Side vector have to be perfectly perpendicular to the Eye vector (in Cylindrical billboarding, only the Side vector was perpendicular to the Eye vector). The challenge in spherical billboarding is that you also need to find the Up vector, because this no longer is known a priori as was the case in cylindrical billboarding. To help you out, you will need to know the Up vector of the camera. Since you want the billboard to completely face the camera, you can say that the Side vector of the billboard will need to be perpendicular to the Eye vector and also to the Up vector of the camera. To demonstrate this, I ve colored the plane of the Eye and CamUp vectors in the left part of Figure 3-21 so you can see that the Side vector is perpendicular to this plane. Since they are perpendicular, you already know how to find the Side vector: it s the cross product between the Eye vector and the CamUp vectors: float3 sideVector = cross(eyeVector,xCamUp); sideVector = normalize(sideVector);
UPC-A Scanner In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Print Barcode In Java
Using Barcode maker for Eclipse BIRT Control to generate, create Barcode image in Eclipse BIRT applications.
www.OnBarcode.com
Cam Up Up Eye Eye
Decode EAN / UCC - 13 In Visual Basic .NET
Using Barcode scanner for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Data Matrix 2d Barcode Recognizer In Visual Basic .NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Side
ECC200 Scanner In VS .NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Barcode Decoder In Visual C#.NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Side
Decode Code 39 Extended In VB.NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
EAN13 Recognizer In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Figure 3-21. Finding Side and Up vectors for spherical billboarding Now that you know the Side vector, you can also find the Up vector of the billboard: it is the vector that is perpendicular to the Side vector and the Eye vector. I ve colored the plane of the Side and Eye vectors in the right part of Figure 3-21, so you can again try to visualize this. This means that the Up vector of the billboard is nothing more than the cross product of the Eye and Side vectors: float3 upVector = cross(sideVector,eyeVector); upVector = normalize(upVector); This is all that needs to be changed when going from cylindrical to spherical billboarding! Just make sure you ve defined the xCamUp variable . . . float3 xCamUp;
CHAPTER 3 WORKING WITH 2D IMAGES /TEXTURES IN XNA 2.0
. . . and a new technique: technique SpheBillboard { pass Pass0 { VertexShader = compile vs_1_1 SpheBillboardVS(); PixelShader = compile ps_1_1 BillboardPS(); } } . . . and since you can use the same pixel shader, you re ready to go! Be sure to call the correct technique from within your XNA project and to set the xCamUp parameter: bbEffect.CurrentTechnique = bbEffect.Techniques["SpheBillboard"]; bbEffect.Parameters["xWorld"].SetValue(Matrix.Identity); bbEffect.Parameters["xProjection"].SetValue(quatCam.ProjectionMatrix); bbEffect.Parameters["xView"].SetValue(quatCam.ViewMatrix); bbEffect.Parameters["xCamPos"].SetValue(quatCam.Position); bbEffect.Parameters["xCamUp"].SetValue(quatCam.UpVector); bbEffect.Parameters["xBillboardTexture"].SetValue(myTexture);
Copyright © OnBarcode.com . All rights reserved.