create barcode c#.net hposition uv1_2 uv3_4 uv5_6 eyeVec lightVec1 in Font

Encode Data Matrix ECC200 in Font hposition uv1_2 uv3_4 uv5_6 eyeVec lightVec1

hposition uv1_2 uv3_4 uv5_6 eyeVec lightVec1
Painting Data Matrix 2d Barcode In None
Using Barcode drawer for Font Control to generate, create Data Matrix image in Font applications.
www.OnBarcode.com
Paint UPC Symbol In None
Using Barcode generation for Font Control to generate, create GTIN - 12 image in Font applications.
www.OnBarcode.com
: POSITION; : TEXCOORD0; : TEXCOORD1; : TEXCOORD2; : TEXCOORD4; : TEXCOORD5; : TEXCOORD6;
Encoding PDF-417 2d Barcode In None
Using Barcode drawer for Font Control to generate, create PDF-417 2d barcode image in Font applications.
www.OnBarcode.com
Encoding Barcode In None
Using Barcode creation for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
float3 lightVec2
Barcode Creator In None
Using Barcode generator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Generating European Article Number 13 In None
Using Barcode creation for Font Control to generate, create GTIN - 13 image in Font applications.
www.OnBarcode.com
Inside the vertex processing, the first thing you should do is calculate the final position of every vertex, transforming it by combining the world, view, and projection matrices:
Generating QR Code In None
Using Barcode encoder for Font Control to generate, create Quick Response Code image in Font applications.
www.OnBarcode.com
Create ISSN - 10 In None
Using Barcode creator for Font Control to generate, create ISSN image in Font applications.
www.OnBarcode.com
OUT.hposition = mul(IN.position, matWVP); // Vertex position in homogeneous space
Decode Data Matrix In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Make Data Matrix 2d Barcode In Objective-C
Using Barcode maker for iPhone Control to generate, create DataMatrix image in iPhone applications.
www.OnBarcode.com
Then you calculate the tangent base, combine it with the world matrix, and calculate its inverse matrix (in this case, the inverse matrix is equal to the transpose matrix). You use the tangentSpace matrix to transform a vector from the world space to the tangent space:
Generating Barcode In Java
Using Barcode generator for BIRT Control to generate, create Barcode image in BIRT reports applications.
www.OnBarcode.com
Data Matrix ECC200 Encoder In None
Using Barcode maker for Word Control to generate, create Data Matrix ECC200 image in Office Word applications.
www.OnBarcode.com
CHAPTER 10 s GENERATING A TERRAIN
Generate Code 128 Code Set B In Java
Using Barcode creator for Android Control to generate, create Code 128B image in Android applications.
www.OnBarcode.com
Scanning Barcode In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
float3x3 tangentSpace = float3x3(IN.tangent, IN.binormal, IN.normal); tangentSpace = mul(tangentSpace, matW); tangentSpace = transpose(tangentSpace);
Drawing Barcode In Java
Using Barcode maker for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
Encode Barcode In Objective-C
Using Barcode printer for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Now you should calculate the view vector and the two lighting vectors and transform their coordinate to the tangent space (transforming them using the tangentSpace matrix):
Generate EAN-13 Supplement 5 In .NET Framework
Using Barcode creator for Reporting Service Control to generate, create EAN-13 image in Reporting Service applications.
www.OnBarcode.com
QR Code Maker In Objective-C
Using Barcode drawer for iPad Control to generate, create QR Code ISO/IEC18004 image in iPad applications.
www.OnBarcode.com
float3 worldPosition = mul(IN.position, matW).xyz; OUT.eyeVec = mul(matVI[3].xyz - worldPosition, tangentSpace); OUT.lightVec1 = mul(light1Position - worldPosition, tangentSpace); OUT.lightVec2 = mul(light2Position - worldPosition, tangentSpace);
Code 128 Code Set C Drawer In Visual Studio .NET
Using Barcode generation for ASP.NET Control to generate, create Code-128 image in ASP.NET applications.
www.OnBarcode.com
Code 128A Printer In C#.NET
Using Barcode creation for Visual Studio .NET Control to generate, create Code 128 Code Set C image in Visual Studio .NET applications.
www.OnBarcode.com
Last, calculate all the texture coordinates using the default texture coordinate of the surface and some tile factors:
OUT.uv1_2 = float4(IN.uv0 * uv1Tile, IN.uv0 * uv2Tile); OUT.uv3_4 = float4(IN.uv0 * uv3Tile, IN.uv0 * uv4Tile); OUT.uv5_6 = float4(IN.uv0 * uvBumpTile, IN.uv0);
Next, the complete vertex processing code is shown:
v2f TerrainVS(a2v IN) { v2f OUT; OUT.hposition = mul(IN.position, matWVP); // Vertex position in homogeneous space // Calculate the tangent basis float3x3 tangentSpace = float3x3(IN.tangent, IN.binormal, IN.normal); tangentSpace = mul(tangentSpace, matW); tangentSpace = transpose(tangentSpace); // Calculate eye and light vector in tangent space float3 worldPosition = mul(IN.position, matW).xyz; OUT.eyeVec = mul(matVI[3].xyz - worldPosition, tangentSpace); OUT.lightVec1 = mul(light1Position - worldPosition, tangentSpace); OUT.lightVec2 = mul(light2Position - worldPosition, tangentSpace); // Multitexturing OUT.uv1_2 = float4(IN.uv0 * uv1Tile, IN.uv0 * uv2Tile); OUT.uv3_4 = float4(IN.uv0 * uv3Tile, IN.uv0 * uv4Tile); OUT.uv5_6 = float4(IN.uv0 * uvBumpTile, IN.uv0); return OUT; }
CHAPTER 10 s GENERATING A TERRAIN
Terrain Effect Pixel Processing
All the data received in the pixel shader is interpolated values output from the vertex shader. The first thing you re going to do in the pixel shader is normalize all the vectors, making sure that they remain unitary. Remember that all these vectors must be unitary to yield correct lighting.
float3 float3 float3 float3 float3 eyeVec = normalize(IN.eyeVec); lightVec1 = normalize(IN.lightVec1); lightVec2 = normalize(IN.lightVec2); halfwayVec1 = normalize(lightVec1 + eyeVec); halfwayVec2 = normalize(lightVec2 + eyeVec);
Next, read the normal map and normalize its value to the -1 to 1 interval. This is needed because the values stored in the texture are in the 0.0 to 1.0 range, but they are used to represent negative and positive values:
float3 normal = tex2D(normalSampler, IN.uv5_6.xy); normal.xy = normal.xy * 2.0 - 1.0; normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
At this point you have all the necessary vectors for the lighting calculation. You ll do the lighting calculation using the Phong equation, which is usually implemented in the graphics APIs. The created phongShading function implements the Phong equation and returns a diffuse and specular component for each specified light source.
float3 diffuseColor1, diffuseColor2, specularColor1, specularColor2; phongShading(normal, lightVec1, halfwayVec1, light1Color, diffuseColor1, specularColor1); phongShading(normal, lightVec2, halfwayVec2, light2Color, diffuseColor2, specularColor2);
Besides the lighting, you should calculate the texture color for each pixel. You calculate this color by sampling and combining the four diffuse textures that are applied to the terrain according to the alpha map texture. Each component of the alpha map stores a value used to linearly interpolate between the colors of the diffuse textures:
float3 color1 = tex2D(diffuseSampler1, IN.uv1_2.xy); float3 color2 = tex2D(diffuseSampler2, IN.uv1_2.zw); float3 color3 = tex2D(diffuseSampler3, IN.uv3_4.xy); float3 color4 = tex2D(diffuseSampler4, IN.uv3_4.zw); float4 alpha = tex2D(alphaSampler, IN.uv5_6.zw); // Combine using the alpha map float3 combinedColor = lerp(color1, color2, alpha.x);
CHAPTER 10 s GENERATING A TERRAIN
combinedColor = lerp(combinedColor , color3, alpha.y); combinedColor = lerp(combinedColor , color4, alpha.z);
Finally, you calculate the final color of each pixel, combining its texture color with the diffuse and specular light that is reflected from the pixel according to its material:
float4 finalColor; finalColor.a = 1.0f; finalColor.rgb = combinedColor * ( (diffuseColor1 + diffuseColor2) * materialDiffuseColor + ambientLightColor) + (specularColor1 + specularColor2) * materialSpecularColor;
The final pixel shader code and the Phong method are shown next. The book RealTime Rendering, 2nd ed., by Tomas Akenine-M ller and Eric Haines (AK Peters, Ltd., 2002) is a good reference for a deep understading of the Phong algorithm and the normal mapping technique.
void phongShading(in float3 normal, in float3 lightVec, in float3 halfwayVec, in float3 lightColor, out float3 diffuseColor, out float3 specularColor) { float diffuseInt = saturate(dot(normal, lightVec)); diffuseColor = diffuseInt * lightColor; float specularInt = saturate(dot(normal, halfwayVec)); specularInt = pow(specularInt, specularPower); specularColor = specularInt * lightColor; } float4 TerrainPS(v2f IN) : COLOR0 { float3 eyeVec = normalize(IN.eyeVec); float3 lightVec1 = normalize(IN.lightVec1); float3 lightVec2 = normalize(IN.lightVec2); float3 halfwayVec1 = normalize(lightVec1 + eyeVec); float3 halfwayVec2 = normalize(lightVec2 + eyeVec); // Normal mapping float3 normal = tex2D(normalSampler, IN.uv5_6.xy); normal.xy = normal.xy * 2.0 - 1.0; normal.z = sqrt(1.0 - dot(normal.xy, normal.xy)); // Calculate diffuse and specular color for each light float3 diffuseColor1, diffuseColor2, specularColor1, specularColor2; phongShading(normal, lightVec1, halfwayVec1, light1Color,
Copyright © OnBarcode.com . All rights reserved.