HLSL Effect Examples in Visual Studio .NET

Generating QR in Visual Studio .NET HLSL Effect Examples

11
QR-Code Printer In Visual Studio .NET
Using Barcode maker for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
www.OnBarcode.com
Bar Code Maker In VS .NET
Using Barcode generator for ASP.NET Control to generate, create barcode image in ASP.NET applications.
www.OnBarcode.com
HLSL Effect Examples
Printing QR Code In C#.NET
Using Barcode generation for .NET Control to generate, create QR Code 2d barcode image in .NET framework applications.
www.OnBarcode.com
QR Code 2d Barcode Generation In .NET
Using Barcode creator for .NET framework Control to generate, create Denso QR Bar Code image in .NET framework applications.
www.OnBarcode.com
float4 float4 float4 float4 float4
Print QR Code ISO/IEC18004 In VB.NET
Using Barcode printer for Visual Studio .NET Control to generate, create Quick Response Code image in .NET framework applications.
www.OnBarcode.com
Print PDF417 In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create PDF 417 image in ASP.NET applications.
www.OnBarcode.com
I_a I_b I_c I_d I_s
EAN / UCC - 13 Generation In .NET Framework
Using Barcode printer for ASP.NET Control to generate, create EAN 13 image in ASP.NET applications.
www.OnBarcode.com
2D Barcode Creator In VS .NET
Using Barcode creator for ASP.NET Control to generate, create Matrix Barcode image in ASP.NET applications.
www.OnBarcode.com
= = = = =
Draw QR Code ISO/IEC18004 In .NET
Using Barcode printer for ASP.NET Control to generate, create QR Code image in ASP.NET applications.
www.OnBarcode.com
GS1-128 Generator In Visual Studio .NET
Using Barcode maker for ASP.NET Control to generate, create EAN / UCC - 13 image in ASP.NET applications.
www.OnBarcode.com
{ { { { {
Bar Code Generation In .NET
Using Barcode maker for ASP.NET Control to generate, create barcode image in ASP.NET applications.
www.OnBarcode.com
EAN - 14 Drawer In Visual Studio .NET
Using Barcode generation for ASP.NET Control to generate, create ITF14 image in ASP.NET applications.
www.OnBarcode.com
0.5f, 0.1f, 0.9f, 1.0f, 1.0f,
Scanning PDF-417 2d Barcode In .NET Framework
Using Barcode reader for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
QR Code Generation In None
Using Barcode creation for Software Control to generate, create Quick Response Code image in Software applications.
www.OnBarcode.com
0.5f, 0.0f, 0.9f, 0.9f, 1.0f,
GTIN - 12 Creation In Java
Using Barcode generation for Java Control to generate, create UCC - 12 image in Java applications.
www.OnBarcode.com
Decode Bar Code In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
0.5f, 0.0f, 1.0f, 0.8f, 1.0f,
Generating GS1 DataBar Expanded In .NET
Using Barcode encoder for VS .NET Control to generate, create GS1 DataBar-14 image in .NET framework applications.
www.OnBarcode.com
Make DataMatrix In Objective-C
Using Barcode encoder for iPad Control to generate, create Data Matrix 2d barcode image in iPad applications.
www.OnBarcode.com
1.0f 1.0f 1.0f 1.0f 1.0f
Paint Code-39 In Objective-C
Using Barcode encoder for iPad Control to generate, create ANSI/AIM Code 39 image in iPad applications.
www.OnBarcode.com
QR-Code Creation In Java
Using Barcode drawer for Android Control to generate, create QR-Code image in Android applications.
www.OnBarcode.com
}; }; }; }; };
// // // // //
ambient ground sky diffuse specular
// material reflectivity float4 k_a = { 0.8f, 0.8f, 0.8f, 1.0f }; float4 k_d = { 0.4f, 0.4f, 0.4f, 1.0f }; float4 k_s = { 0.1f, 0.1f, 0.1f, 1.0f }; int n = 32; // transformations float4x3 WorldView : WORLDVIEW; float4x4 Projection : PROJECTION;
// // // //
ambient diffuse specular power
struct VS_OUTPUT { float4 Pos : POSITION; float4 Diff : COLOR0; float4 Spec : COLOR1; }; VS_OUTPUT VS( float3 Pos : POSITION, float3 Norm : NORMAL, float Occ : TEXCOORD0, uniform bool bHemi, uniform bool bDiff, uniform bool bSpec) { VS_OUTPUT Out = (VS_OUTPUT)0; // diffuse direction float3 L = -DirFromLight; // hemisphere up axis float3 Y = -DirFromSky; // position (view space) float3 P = mul(float4(Pos, 1), (float4x3)WorldView); // normal (view space) float3 N = normalize(mul(Norm, (float3x3)WorldView)); // reflection vector (view space) float3 R = normalize(2 * dot(N, L) * N - L); // view direction (view space) float3 V = -normalize(P); float4 Amb = k_a * I_a; float4 Hemi = k_a * lerp(I_b, I_c, (dot(N, Y) + 1) / 2) * (1 - Occ); float temp = 1 - max(0, dot(N, L)); float4 Diff = k_d * I_d * (1 - temp * temp); float4 Spec = k_s * I_s * pow(max(0, dot , V)), n/4); float4 Zero = 0;
(continued)
Part III
Programming Effects
// position (projected) Out.Pos = mul(float4(P, 1), Projection); // diffuse + ambient/hemisphere Out.Diff = (bDiff Diff : 0) + (bHemi Hemi : Amb); // specular Out.Spec = (bSpec Spec : 0); } return Out; } technique THemisphere { pass P0 { VertexShader = compile vs_1_1 } } technique THemisphereDiffuse { pass P0 { VertexShader = compile vs_1_1 } } technique THemisphereDiffuseSpecular { pass P0 { VertexShader = compile vs_1_1 SpecularEnable = TRUE; } } technique TAmbient { pass P0 { VertexShader = compile vs_1_1 } } technique TAmbientDiffuse { pass P0 { VertexShader = compile vs_1_1 } } technique TAmbientDiffuseSpecular {
VS(true, false, false);
VS(true, true, false);
VS(true, true, true);
VS(false, false, false);
VS(false, true, false);
11
HLSL Effect Examples
pass P0 { VertexShader = compile vs_1_1 VS(false, true, true); SpecularEnable = TRUE; } }
The effect contains
Several global variables A vertex shader function named VS Several single pass techniques
We learned earlier that an effect can declare certain variables with specific names, semantics, or annotations to work well with EffectEdit. Here are the specific variables that the hemisphere effect uses so that EffectEdit will recognize them:
string XFile = "SkullOcc.x"; int BCLR = 0xff202080; // transformations float4x3 WorldView : WORLDVIEW; float4x4 Projection : PROJECTION; // model // background
These variables provide the model name in XFile, the background color in BCLR, the world-view transform in WorldView, and the projection transform in Projection. The rest of the global variables and the shader function can be named anything. Now let s see how the shader actually works. Here s the shader:
struct VS_OUTPUT { float4 Pos : POSITION; float4 Diff : COLOR0; float4 Spec : COLOR1; }; VS_OUTPUT VS( float3 Pos : POSITION, float3 Norm : NORMAL, float Occ : TEXCOORD0, uniform bool bHemi, uniform bool bDiff, uniform bool bSpec) {
(continued)
Part III
Programming Effects
VS_OUTPUT Out = (VS_OUTPUT)0; // diffuse direction float3 L = -DirFromLight; // hemisphere up axis float3 Y = -DirFromSky; // position (view space) float3 P = mul(float4(Pos, 1), (float4x3)WorldView); // normal (view space) float3 N = normalize(mul(Norm, (float3x3)WorldView)); // reflection vector (view space) float3 R = normalize(2 * dot(N, L) * N - L); // view direction (view space) float3 V = -normalize(P); float4 Amb = k_a * I_a; float4 Hemi = k_a * lerp(I_b, I_c, (dot(N, Y) + 1) / 2) * (1 - Occ); float temp = 1 - max(0, dot(N, L)); float4 Diff = k_d * I_d * (1 - temp * temp); float4 Spec = k_s * I_s * pow(max(0, dot , V)), n/4); float4 Zero = 0; // position (projected) Out.Pos = mul(float4(P, 1), Projection); // diffuse + ambient/hemisphere Out.Diff = (bDiff Diff : 0) + (bHemi Hemi : Amb); // specular Out.Spec = (bSpec Spec : 0); return Out; }
The shader takes several input arguments and returns the outputs using the VS_OUTPUT structure. Three of the input arguments come from the vertex buffer, including the position, the normal, and an occlusion factor. It s obvious that these parameters come from the vertex buffer because they have semantics.
float3 Pos : POSITION, float3 Norm : NORMAL, float Occ : TEXCOORD0,
Copyright © OnBarcode.com . All rights reserved.