1 | //--------------------------------------------------------------------------------------
|
---|
2 | // File: DXUTShared.fx
|
---|
3 | //
|
---|
4 | //
|
---|
5 | //
|
---|
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
---|
7 | //--------------------------------------------------------------------------------------
|
---|
8 |
|
---|
9 |
|
---|
10 | //--------------------------------------------------------------------------------------
|
---|
11 | // Global variables
|
---|
12 | //--------------------------------------------------------------------------------------
|
---|
13 | float4 g_MaterialDiffuseColor; // Material's diffuse color
|
---|
14 | float3 g_LightDir; // Light's direction in world space
|
---|
15 | float4x4 g_mWorld; // World matrix for object
|
---|
16 | float4x4 g_mWorldViewProjection; // World * View * Projection matrix
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 | //--------------------------------------------------------------------------------------
|
---|
21 | // Vertex shader output structure
|
---|
22 | //--------------------------------------------------------------------------------------
|
---|
23 | struct VS_OUTPUT
|
---|
24 | {
|
---|
25 | float4 Position : POSITION; // vertex position
|
---|
26 | float4 Diffuse : COLOR0; // vertex diffuse color
|
---|
27 | };
|
---|
28 |
|
---|
29 |
|
---|
30 | //--------------------------------------------------------------------------------------
|
---|
31 | // This shader computes standard transform and lighting
|
---|
32 | //--------------------------------------------------------------------------------------
|
---|
33 | VS_OUTPUT RenderWith1LightNoTextureVS( float4 vPos : POSITION,
|
---|
34 | float3 vNormal : NORMAL )
|
---|
35 | {
|
---|
36 | VS_OUTPUT Output;
|
---|
37 |
|
---|
38 | // Transform the position from object space to homogeneous projection space
|
---|
39 | Output.Position = mul(vPos, g_mWorldViewProjection);
|
---|
40 |
|
---|
41 | // Transform the normal from object space to world space
|
---|
42 | float3 vNormalWorldSpace;
|
---|
43 | vNormalWorldSpace = normalize(mul(vNormal, (float3x3)g_mWorld)); // normal (world space)
|
---|
44 |
|
---|
45 | // Compute simple directional lighting equation
|
---|
46 | Output.Diffuse.rgb = g_MaterialDiffuseColor * max(0,dot(vNormalWorldSpace, g_LightDir));
|
---|
47 | Output.Diffuse.a = 1.0f;
|
---|
48 |
|
---|
49 | return Output;
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | //--------------------------------------------------------------------------------------
|
---|
54 | float4 RenderWith1LightNoTexturePS( float4 Diffuse : COLOR0 ) : COLOR0
|
---|
55 | {
|
---|
56 | return Diffuse;
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | //--------------------------------------------------------------------------------------
|
---|
61 | technique RenderWith1LightNoTexture
|
---|
62 | {
|
---|
63 | pass P0
|
---|
64 | {
|
---|
65 | VertexShader = compile vs_1_1 RenderWith1LightNoTextureVS();
|
---|
66 | PixelShader = compile ps_1_1 RenderWith1LightNoTexturePS();
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|