source: GTP/trunk/App/Demos/Illum/EnvMap/Media/UI/Annotated Hemisphere.fx @ 1488

Revision 1488, 5.0 KB checked in by szirmay, 18 years ago (diff)
Line 
1//
2// Hemisphere Lighting Model
3// Copyright (c) Microsoft Corporation. All rights reserved.
4//
5// Note: This effect file works with EffectEdit.
6//
7
8
9string XFile = "SkullOcc.x";                // model
10int    BCLR  = 0xff202080;                  // background
11
12// light directions (view space)
13float3 DirFromLight < string UIName = "Light Direction"; > = {0.577, -0.577, 0.577};
14
15// direction of light from sky (view space)
16float3 DirFromSky < string UIName = "Direction from Sky"; > = { 0.0f, -1.0f, 0.0f };           
17
18// light intensity
19float4 I_a < string UIName = "Ambient Intensity";
20             string UIWidget = "Color";
21             float UIStep = 0.05;
22             string UIHelp = "The light intensity of the ambient lights";     
23        > = { 0.5f, 0.5f, 0.5f, 1.0f };    // ambient
24float4 I_b < string UIName = "Ground color";
25             string UIWidget = "Color";
26             float UIStep = 0.05;
27             string UIHelp = "The color of the ground";     
28        > = { 0.1f, 0.0f, 0.0f, 1.0f };    // ground
29float4 I_c < string UIName = "Sky Color";
30             string UIWidget = "Color";
31             float UIStep = 0.05;
32             string UIHelp = "The color of the sky";     
33        > = { 0.9f, 0.9f, 1.0f, 1.0f };    // sky
34float4 I_d < string UIName = "Diffuse Intensity";
35             string UIWidget = "Color";
36             float UIStep = 0.05;
37             string UIHelp = "The light intensity of the diffuse lights";     
38        > = { 1.0f, 0.9f, 0.8f, 1.0f };    // diffuse
39float4 I_s < string UIName = "Specular Intensity";
40             string UIWidget = "Color";
41             float UIStep = 0.05;
42             string UIHelp = "The light intensity of the specular lights";     
43        > = { 1.0f, 1.0f, 1.0f, 1.0f };    // specular
44
45// material reflectivity
46float4 k_a < string UIName = "Ambient Color";
47             string UIWidget = "Color";
48             float UIStep = 0.05;
49             string UIHelp = "Material Ambient Color";     
50        > = { 0.8f, 0.8f, 0.8f, 1.0f };    // ambient
51float4 k_d < string UIName = "Diffuse Color";
52             string UIWidget = "Color";
53             float UIStep = 0.05;
54             string UIHelp = "Material Diffuse Color";     
55        > = { 0.4f, 0.4f, 0.4f, 1.0f };    // diffuse
56float4 k_s < string UIName = "Specular Color";
57             string UIWidget = "Color";
58             float UIStep = 0.05;
59             string UIHelp = "Material Specular Color";     
60        > = { 0.1f, 0.1f, 0.1f, 1.0f };    // specular
61float  n  < string UIName = "Specular Power";
62             string UIWidget = "Numeric";
63             float UIStep = 1;
64             string UIHelp = "Specular Power";     
65        > = 32.0f;                         // power
66
67
68// transformations
69float4x4 WorldView  : WORLDVIEW;
70float4x4 Projection : PROJECTION;
71
72struct VS_OUTPUT
73{
74    float4 Pos  : POSITION;
75    float4 Diff : COLOR0;
76    float4 Spec : COLOR1;
77};
78
79VS_OUTPUT VS(
80    float3 Pos  : POSITION,
81    float3 Norm : NORMAL,
82    float  Occ  : TEXCOORD0,
83    uniform bool bHemi,
84    uniform bool bDiff,
85    uniform bool bSpec)
86{
87    VS_OUTPUT Out = (VS_OUTPUT)0;
88
89    float3 L = -DirFromLight;                               // diffuse direction
90    float3 Y = -DirFromSky;                                 // hemisphere up axis
91    float3 P = mul(float4(Pos, 1), (float4x3)WorldView);    // position (view space)
92    float3 N = normalize(mul(Norm, (float3x3)WorldView));   // normal (view space)
93    float3 R = normalize(2 * dot(N, L) * N - L);            // reflection vector (view space)
94    float3 V = -normalize(P);                               // view direction (view space)
95
96    float4 Amb  = k_a * I_a;
97    float4 Hemi = k_a * lerp(I_b, I_c, (dot(N, Y) + 1) / 2) * (1 - Occ);
98    float  temp = 1 - max(0, dot(N, L));
99    float4 Diff = k_d * I_d * (1 - temp * temp);
100    float4 Spec = k_s * I_s * pow(max(0, dot(R, V)), n/4);
101    float4 Zero = 0;
102
103    Out.Pos  = mul(float4(P, 1), Projection);               // position (projected)
104    Out.Diff = (bDiff ? Diff : 0)
105             + (bHemi ? Hemi : Amb);                        // diffuse + ambient/hemisphere
106    Out.Spec = (bSpec ? Spec : 0);                          // specular
107
108    return Out;
109}
110
111technique THemisphereDiffuseSpecular
112{
113    pass P0
114    {
115        VertexShader = compile vs_1_1 VS(true, true, true);
116
117        SpecularEnable = TRUE;
118    }
119}
120
121technique THemisphereDiffuse
122{
123    pass P0
124    {
125        VertexShader = compile vs_1_1 VS(true, true, false);
126    }
127}
128
129
130technique THemisphere
131{
132    pass P0
133    {
134        VertexShader = compile vs_1_1 VS(true, false, false);
135    }
136}
137
138
139technique TAmbient
140{
141    pass P0
142    {
143        VertexShader = compile vs_1_1 VS(false, false, false);
144    }
145}
146
147technique TAmbientDiffuse
148{
149    pass P0
150    {
151        VertexShader = compile vs_1_1 VS(false, true, false);
152    }
153}
154
155technique TAmbientDiffuseSpecular
156{
157    pass P0
158    {
159        VertexShader = compile vs_1_1 VS(false, true, true);
160
161        SpecularEnable = TRUE;
162    }
163}
164
Note: See TracBrowser for help on using the repository browser.