1: #include <xsi_include9.hlsl>
2:
3: //**********************************************************************
4: // Tweakables
5: //**********************************************************************
6:
7: float3 AmbientColor
8: <
9: string SasUiControl = "ColorPicker";
10: string SasUiLabel = "Ambient";
11: > = {0.3f, 0.3f, 0.3f};
12:
13: float3 DiffuseColor
14: <
15: string SasUiControl = "ColorPicker";
16: string SasUiLabel = "Diffuse";
17: > = {0.7f, 0.7f, 0.7f};
18:
19: float3 SpecularColor
20: <
21: string SasUiControl = "ColorPicker";
22: string SasUiLabel = "Specular";
23: > = {1.0f, 1.0f, 1.0f};
24:
25: float SpecularPower
26: <
27: string SasUiControl = "Slider";
28: string SasUiLabel = "Specular Power";
29: float SasUiMin = 1;
30: float SasUiMax = 200;
31: > = 20.0f;
32:
33: texture2D AmbientMap
34: <
35: string ResourceName = "default_ambocc_map.png";
36: string ResourceType = "2D";
37: >;
38:
39: texture2D AlbedoMap
40: <
41: string ResourceName = "default_surface_map.png";
42: string ResourceType = "2D";
43: >;
44:
45: texture2D NormalMap
46: <
47: string ResourceName = "default_normal_map.png";
48: string ResourceType = "2D";
49: >;
50:
51: sampler2D AmbientSampler = sampler_state
52: {
53: Texture = <AmbientMap>;
54: MipFilter = LINEAR;
55: MinFilter = LINEAR;
56: MagFilter = LINEAR;
57: };
58:
59: sampler2D AlbedoSampler = sampler_state
60: {
61: Texture = <AlbedoMap>;
62: MipFilter = LINEAR;
63: MinFilter = LINEAR;
64: MagFilter = LINEAR;
65: };
66:
67: sampler2D NormalSampler = sampler_state
68: {
69: Texture = <NormalMap>;
70: MipFilter = LINEAR;
71: MinFilter = LINEAR;
72: MagFilter = LINEAR;
73: };
74:
75: //**********************************************************************
76: // Runtime bound
77: //**********************************************************************
78:
79:
80: float4 sieye
81: <
82: string SasBindAddress = "Sas.Camera.Position";
83: >;
84:
85:
86: // lights
87: #include <xsi_lightlist9.hlsl>
88:
89:
90: //**********************************************************************
91: // Vertex Shaders
92: //**********************************************************************
93:
94: #include <xsi_defaultvs.hlsl>
95:
96:
97: //**********************************************************************
98: // Pixel Shaders
99: //**********************************************************************
100:
101: float4 Phong_2
102: (
103: XSI_VertexToPixel IN
104: ) : COLOR
105: {
106: #include<xsi_lightdef9.hlsl>
107:
108: float3 globalpos = IN.texcoord4;
109: float3x3 TangentToWorldSpace;
110:
111: float3 lightcolor = 0.0f;
112:
113: //*************************************************
114: // sample our textures
115: //*************************************************
116: float3 normaltex = tex2D(NormalSampler, IN.texcoord0) * 2 - 1;
117: float3 ambienttex = tex2D(AmbientSampler, IN.texcoord0);
118: float3 albedotex = tex2D(AlbedoSampler, IN.texcoord0);
119:
120: AmbientColor = AmbientColor * ambienttex;
121: DiffuseColor = DiffuseColor * albedotex;
122:
123: TangentToWorldSpace[0] = IN.texcoord5.xyz;
124: TangentToWorldSpace[1] = IN.texcoord6.xyz;
125: TangentToWorldSpace[2] = IN.texcoord7.xyz;
126:
127: //*************************************************
128: // convert normal in world space
129: //*************************************************
130: float3 normal = normalize(mul(normaltex,TangentToWorldSpace));
131:
132: //*************************************************
133: // eye to vertex
134: //*************************************************
135: float3 eyetovert = normalize(sieye.xyz - globalpos);
136:
137: //*************************************************
138: // light up
139: //*************************************************
140:
141: float3 ts_lightdir;
142: float3 ts_hvec;
143:
144: int loop;
145: for(loop = 0; loop < NUM_LIGHTS; loop++)
146: {
147:
148: // light direction
149: ts_lightdir = LightPos[loop].xyz - globalpos;
150:
151: float lightdistance = length(ts_lightdir);
152: ts_lightdir = normalize(ts_lightdir);
153:
154: // half vector
155: ts_hvec = normalize(eyetovert + ts_lightdir);
156:
157: float3 currentcolor = LightCol[loop] * (
158: (DiffuseColor * clamp(dot(normal, ts_lightdir), 0, 1)) + // diffuse
159: (SpecularColor * LightCol[loop] * pow(clamp(dot(normal, ts_hvec),0,1), SpecularPower))); // specular
160:
161: lightcolor += currentcolor;
162: }
163:
164:
165: float4 result;
166: result.xyz = AmbientColor + lightcolor ;
167: result.w = 1;
168:
169:
170: return result;
171: }
172:
173: //**********************************************************************
174: // Techniques
175: //**********************************************************************
176:
177:
178: technique Static
179: {
180: pass p0
181: {
182: VertexShader = compile vs_2_0 VSStatic();
183: PixelShader = compile ps_2_0 Phong_2();
184: }
185: }
186:
187: technique Skinned
188: {
189: pass p0
190: {
191: VertexShader = compile vs_2_0 VSSkinned();
192: PixelShader = compile ps_2_0 Phong_2();
193: }
194: }
195: