summaryrefslogtreecommitdiff
path: root/media/test/UI/DXUTShared.fx
blob: f6d590b6953e1a6768cf27034e95cf6c1800ddfa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//--------------------------------------------------------------------------------------
// File: DXUTShared.fx
//
// 
// 
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
float4 g_MaterialDiffuseColor;      // Material's diffuse color
float3 g_LightDir;                  // Light's direction in world space
float4x4 g_mWorld;                  // World matrix for object
float4x4 g_mWorldViewProjection;    // World * View * Projection matrix



//--------------------------------------------------------------------------------------
// Vertex shader output structure
//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
    float4 Position   : POSITION;   // vertex position 
    float4 Diffuse    : COLOR0;     // vertex diffuse color 
};


//--------------------------------------------------------------------------------------
// This shader computes standard transform and lighting
//--------------------------------------------------------------------------------------
VS_OUTPUT RenderWith1LightNoTextureVS( float4 vPos : POSITION, 
                                       float3 vNormal : NORMAL )
{
    VS_OUTPUT Output;
  
    // Transform the position from object space to homogeneous projection space
    Output.Position = mul(vPos, g_mWorldViewProjection);
    
    // Transform the normal from object space to world space    
    float3 vNormalWorldSpace;
    vNormalWorldSpace = normalize(mul(vNormal, (float3x3)g_mWorld)); // normal (world space)
    
    // Compute simple directional lighting equation
    Output.Diffuse.rgb = g_MaterialDiffuseColor * max(0,dot(vNormalWorldSpace, g_LightDir));   
    Output.Diffuse.a = 1.0f; 
    
    return Output;    
}


//--------------------------------------------------------------------------------------
float4 RenderWith1LightNoTexturePS( float4 Diffuse : COLOR0 ) : COLOR0
{ 
    return Diffuse;
}


//--------------------------------------------------------------------------------------
technique RenderWith1LightNoTexture
{
    pass P0
    {          
        VertexShader = compile vs_1_1 RenderWith1LightNoTextureVS();
        PixelShader  = compile ps_1_1 RenderWith1LightNoTexturePS(); 
    }
}