HLSL in Word

Encode DataMatrix in Word HLSL

HLSL
Make DataMatrix In None
Using Barcode creator for Word Control to generate, create ECC200 image in Office Word applications.
www.OnBarcode.com
Creating QR Code JIS X 0510 In None
Using Barcode encoder for Microsoft Word Control to generate, create QR image in Microsoft Word applications.
www.OnBarcode.com
Now that you have your vertices ready, it s time to start coding your vertex and pixel shader. As usual, you start with the variables passed from XNA to your HLSL code, the texture samplers, and the output structures of your vertex shader and pixel shader: //------- XNA interface -------float4x4 xView; float4x4 xProjection; float4x4 xWorld; float3 xCamPos; float3 xCamUp; float xTime; //------- Texture Samplers -------Texture xExplosionTexture; sampler textureSampler = sampler_state { texture = <xExplosionTexture>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = CLAMP; AddressV = CLAMP;}; struct ExpVertexToPixel { float4 Position : POSITION; float2 TexCoord : TEXCOORD0; float4 Color : COLOR0; }; struct ExpPixelToFrame { float4 Color : COLOR0; }; Because you will billboard each particle of your explosion, you will need the same variables as in the recipe on billboarding. This time, you will also need your XNA application to store the current time in the xTime variable so your vertex shader can calculate how long each particle has been alive. As in recipe 3-11, your vertex shader will pass the 2D screen coordinate of the vertex, together with the texture coordinate to the pixel shader. Because you ll want the particles to fade away after some time, you ll also want to pass some color information from your vertex shader to your pixel shader. As usual, your pixel shader will calculate only the color of each pixel.
GS1 - 12 Generation In None
Using Barcode generation for Word Control to generate, create UPC-A Supplement 5 image in Microsoft Word applications.
www.OnBarcode.com
PDF-417 2d Barcode Maker In None
Using Barcode creator for Word Control to generate, create PDF 417 image in Word applications.
www.OnBarcode.com
C HA PTER 3 WORKING WITH 2D IMA GES/TEXTU RES IN XN A 2.0
Drawing Barcode In None
Using Barcode generator for Microsoft Word Control to generate, create Barcode image in Word applications.
www.OnBarcode.com
Draw Code 3/9 In None
Using Barcode maker for Word Control to generate, create ANSI/AIM Code 39 image in Microsoft Word applications.
www.OnBarcode.com
Vertex Shader
Generate Code 128 Code Set B In None
Using Barcode drawer for Word Control to generate, create Code128 image in Microsoft Word applications.
www.OnBarcode.com
Paint UPC Case Code In None
Using Barcode printer for Office Word Control to generate, create DUN - 14 image in Office Word applications.
www.OnBarcode.com
Your vertex shader will need to billboard the vertices, so you can use this method, which contains the useful spherical billboarding code of recipe 3-11: //------- Technique: Explosion -------float3 BillboardVertex(float3 billboardCenter, float2 cornerID, float size) { float3 eyeVector = billboardCenter - xCamPos; float3 sideVector = cross(eyeVector,xCamUp); sideVector = normalize(sideVector); float3 upVector = cross(sideVector,eyeVector); upVector = normalize(upVector); float3 finalPosition = billboardCenter; finalPosition += (cornerID.x-0.5f)*sideVector*size; finalPosition += (0.5f-cornerID.y)*upVector*size; return finalPosition; } In a nutshell, you pass the center of the billboard to this method, together with the texture coordinate (required to identify the current vertex) and how big you want the billboard to be. The method returns the billboarded 3D position of the vertex. For more information, see recipe 3-11. Now it s time for the vertex shader, which will make use of the method defined previously: ExpVertexToPixel ExplosionVS(float3 inPos: POSITION0, float4 inTexCoord: TEXCOORD0, float4 inExtra: TEXCOORD1) { ExpVertexToPixel Output = (ExpVertexToPixel)0; float3 startingPosition = mul(inPos, xWorld); float2 texCoords = inTexCoord.xy; float birthTime = inTexCoord.z; float maxAge = inTexCoord.w; float3 moveDirection = inExtra.xyz; float random = inExtra.w; } This vertex shader receives the Vector3 and the two Vector4s you stored for each vertex. First, the content of this data is stored in some more meaningful variables. The position of the center of the billboard was stored in the Vector3. You defined the x and y components of the first Vector4 to contain the texture coordinate, and the third and fourth components stored the time at which the particle was created and how long it should be visible. The last Vector4 contained the direction in which you want the particle to move and an extra random float. At this moment, you can find how long the particle has been alive by subtracting the birthTime from the current time, stored in the xTime variable. However, when working with time spans,
Data Matrix Creator In Java
Using Barcode maker for Java Control to generate, create ECC200 image in Java applications.
www.OnBarcode.com
ECC200 Printer In None
Using Barcode creation for Office Word Control to generate, create Data Matrix ECC200 image in Microsoft Word applications.
www.OnBarcode.com
CHAPTER 3 WORKING WITH 2D IMAGES /TEXTURES IN XNA 2.0
2D Drawer In Visual Studio .NET
Using Barcode encoder for ASP.NET Control to generate, create 2D image in ASP.NET applications.
www.OnBarcode.com
Code 128 Code Set C Maker In Visual C#
Using Barcode maker for .NET Control to generate, create Code 128 Code Set B image in Visual Studio .NET applications.
www.OnBarcode.com
you always want to work with relative values between 0 and 1, where 0 means the beginning of the time span and 1 means the end of the time span. So, you ll want to divide the age by the maximum age at which the particle should die : float age = xTime - birthTime; float relAge = age/maxAge; Always check stuff like this for yourself: when the particle is really new, xTime will be the same as birthTime, and relAge will be 0. When the particle is nearing its end, the age will almost equal maxAge, and the relAge variable will almost equal 1. Let s first adjust the size of the particle according to its age. You want each particle of the explosion to start big and then get smaller as it gets older. However, you don t want it to completely shrink away, so for example you can use this code: float size = 1-relAge*relAge/2.0f; This looks a bit scary, but it s more understandable if you visualize it, as is done in the left part of Figure 3-23. For each relAge of the particle on the horizontal axis, you can find the corresponding size on the vertical axis. For example, at relAge = 0, the size will be 1, and at relAge = 1, the size will be 0.5f.
Barcode Decoder In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Generating Barcode In Visual Studio .NET
Using Barcode generation for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
Figure 3-23. Size in function of relAge; displacement in function of relAge However, relAge continues to increase after it has become 1. This means size will become negative (as you can see in the following code, this will cause the image to stretch in the opposite direction). So, you will want to saturate this value between 0 and 1. Because particles of size 1 are too small in your application, simply scale them up by multiplying them by a number, 5 in this case. To make each particle unique, you ll also multiply the size by the random value of the particle, so each particle has its own starting (and this ending) size: float sizer = saturate(1-relAge*relAge/2.0f); float size = 5.0f*random*sizer; Now that you have the size decreasing as the particle gets older, the next thing to calculate is the 3D location of the center of the particle. You know the original 3D location (the center of the explosion), as well as the direction in which the particle has to move. All you need to know is how far the particle has been moved into this direction. Of course, this also corresponds to the age of the particle. An easy approach would be to assume the particle keeps on moving at a constant speed, but in reality this speed decreases after a while. Take a look at the right part of Figure 3-23. The horizontal axis again represents the age of your particle, while the vertical axis indicates how far the particle has moved from the center of the explosion. You see that first the distance increases linearly, but after a while, the distance
Creating Linear 1D Barcode In Java
Using Barcode encoder for Java Control to generate, create Linear Barcode image in Java applications.
www.OnBarcode.com
Code 128A Reader In C#
Using Barcode reader for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Creating Barcode In VS .NET
Using Barcode encoder for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
Drawing Barcode In None
Using Barcode printer for Software Control to generate, create Barcode image in Software applications.
www.OnBarcode.com
PDF-417 2d Barcode Recognizer In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Barcode Drawer In Java
Using Barcode generation for BIRT reports Control to generate, create Barcode image in BIRT applications.
www.OnBarcode.com
Copyright © OnBarcode.com . All rights reserved.