1 | /* |
---|
2 | Basic ambient lighting vertex program |
---|
3 | */ |
---|
4 | void ambientOneTexture_vp(float4 position : POSITION, |
---|
5 | float3 normal : NORMAL, |
---|
6 | float2 uv : TEXCOORD0, |
---|
7 | float3 tangent : TANGENT, |
---|
8 | |
---|
9 | |
---|
10 | out float4 oPosition : SV_POSITION, |
---|
11 | out float2 oUv : TEXCOORD0, |
---|
12 | out float4 colour : COLOR, |
---|
13 | |
---|
14 | uniform float4x4 worldViewProj, |
---|
15 | uniform float4 ambient) |
---|
16 | { |
---|
17 | oPosition = mul(worldViewProj, position); |
---|
18 | oUv = uv; |
---|
19 | colour = ambient; |
---|
20 | } |
---|
21 | |
---|
22 | /* |
---|
23 | Basic fragment program using texture and diffuse colour. |
---|
24 | */ |
---|
25 | void diffuseOneTexture_fp(float4 position : SV_POSITION, |
---|
26 | float2 uv : TEXCOORD0, |
---|
27 | float4 diffuse : COLOR, |
---|
28 | out float4 colour : COLOR, |
---|
29 | uniform sampler2D texMap : register(s0)) |
---|
30 | { |
---|
31 | colour = tex2D(texMap,uv) * diffuse; |
---|
32 | } |
---|
33 | |
---|
34 | /* |
---|
35 | Single-weight-per-vertex hardware skinning, 2 lights |
---|
36 | The trouble with vertex programs is they're not general purpose, but |
---|
37 | fixed function hardware skinning is very poorly supported |
---|
38 | */ |
---|
39 | void hardwareSkinningOneWeight_vp( |
---|
40 | float4 position : POSITION, |
---|
41 | float3 normal : NORMAL, |
---|
42 | float2 uv : TEXCOORD0, |
---|
43 | float blendIdx : BLENDINDICES, |
---|
44 | |
---|
45 | |
---|
46 | out float4 oPosition : SV_POSITION, |
---|
47 | out float2 oUv : TEXCOORD0, |
---|
48 | out float4 colour : COLOR, |
---|
49 | // Support up to 24 bones of float3x4 |
---|
50 | // vs_1_1 only supports 96 params so more than this is not feasible |
---|
51 | uniform float3x4 worldMatrix3x4Array[24], |
---|
52 | uniform float4x4 viewProjectionMatrix, |
---|
53 | uniform float4 lightPos[2], |
---|
54 | uniform float4 lightDiffuseColour[2], |
---|
55 | uniform float4 ambient) |
---|
56 | { |
---|
57 | // transform by indexed matrix |
---|
58 | float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); |
---|
59 | // view / projection |
---|
60 | oPosition = mul(viewProjectionMatrix, blendPos); |
---|
61 | // transform normal |
---|
62 | float3 norm = mul((float3x3)worldMatrix3x4Array[blendIdx], normal); |
---|
63 | // Lighting - support point and directional |
---|
64 | float3 lightDir0 = normalize( |
---|
65 | lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); |
---|
66 | float3 lightDir1 = normalize( |
---|
67 | lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); |
---|
68 | |
---|
69 | oUv = uv; |
---|
70 | colour = ambient + |
---|
71 | (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + |
---|
72 | (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); |
---|
73 | |
---|
74 | } |
---|
75 | |
---|
76 | /* |
---|
77 | Single-weight-per-vertex hardware skinning, shadow-caster pass |
---|
78 | */ |
---|
79 | void hardwareSkinningOneWeightCaster_vp( |
---|
80 | float4 position : POSITION, |
---|
81 | float3 normal : NORMAL, |
---|
82 | float blendIdx : BLENDINDICES, |
---|
83 | |
---|
84 | |
---|
85 | out float4 oPosition : SV_POSITION, |
---|
86 | out float4 colour : COLOR, |
---|
87 | // Support up to 24 bones of float3x4 |
---|
88 | // vs_1_1 only supports 96 params so more than this is not feasible |
---|
89 | uniform float3x4 worldMatrix3x4Array[24], |
---|
90 | uniform float4x4 viewProjectionMatrix, |
---|
91 | uniform float4 ambient) |
---|
92 | { |
---|
93 | // transform by indexed matrix |
---|
94 | float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); |
---|
95 | // view / projection |
---|
96 | oPosition = mul(viewProjectionMatrix, blendPos); |
---|
97 | |
---|
98 | colour = ambient; |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | /* |
---|
103 | Two-weight-per-vertex hardware skinning, 2 lights |
---|
104 | The trouble with vertex programs is they're not general purpose, but |
---|
105 | fixed function hardware skinning is very poorly supported |
---|
106 | */ |
---|
107 | void hardwareSkinningTwoWeights_vp( |
---|
108 | float4 position : POSITION, |
---|
109 | float3 normal : NORMAL, |
---|
110 | float2 uv : TEXCOORD0, |
---|
111 | float4 blendIdx : BLENDINDICES, |
---|
112 | float4 blendWgt : BLENDWEIGHT, |
---|
113 | |
---|
114 | |
---|
115 | out float4 oPosition : SV_POSITION, |
---|
116 | out float2 oUv : TEXCOORD0, |
---|
117 | out float4 colour : COLOR, |
---|
118 | // Support up to 24 bones of float3x4 |
---|
119 | // vs_1_1 only supports 96 params so more than this is not feasible |
---|
120 | uniform float3x4 worldMatrix3x4Array[24], |
---|
121 | uniform float4x4 viewProjectionMatrix, |
---|
122 | uniform float4 lightPos[2], |
---|
123 | uniform float4 lightDiffuseColour[2], |
---|
124 | uniform float4 ambient, |
---|
125 | uniform float4 diffuse) |
---|
126 | { |
---|
127 | // transform by indexed matrix |
---|
128 | float4 blendPos = float4(0,0,0,0); |
---|
129 | int i; |
---|
130 | for (i = 0; i < 2; ++i) |
---|
131 | { |
---|
132 | blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; |
---|
133 | } |
---|
134 | // view / projection |
---|
135 | oPosition = mul(viewProjectionMatrix, blendPos); |
---|
136 | // transform normal |
---|
137 | float3 norm = float3(0,0,0); |
---|
138 | for (i = 0; i < 2; ++i) |
---|
139 | { |
---|
140 | norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * |
---|
141 | blendWgt[i]; |
---|
142 | } |
---|
143 | norm = normalize(norm); |
---|
144 | // Lighting - support point and directional |
---|
145 | float3 lightDir0 = normalize( |
---|
146 | lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); |
---|
147 | float3 lightDir1 = normalize( |
---|
148 | lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); |
---|
149 | |
---|
150 | |
---|
151 | oUv = uv; |
---|
152 | colour = diffuse * (ambient + |
---|
153 | (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + |
---|
154 | (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1])); |
---|
155 | |
---|
156 | } |
---|
157 | |
---|
158 | /* |
---|
159 | Two-weight-per-vertex hardware skinning, shadow caster pass |
---|
160 | */ |
---|
161 | void hardwareSkinningTwoWeightsCaster_vp( |
---|
162 | float4 position : POSITION, |
---|
163 | float3 normal : NORMAL, |
---|
164 | float2 uv : TEXCOORD0, |
---|
165 | float4 blendIdx : BLENDINDICES, |
---|
166 | float4 blendWgt : BLENDWEIGHT, |
---|
167 | |
---|
168 | |
---|
169 | out float4 oPosition : SV_POSITION, |
---|
170 | out float4 colour : COLOR, |
---|
171 | // Support up to 24 bones of float3x4 |
---|
172 | // vs_1_1 only supports 96 params so more than this is not feasible |
---|
173 | uniform float3x4 worldMatrix3x4Array[24], |
---|
174 | uniform float4x4 viewProjectionMatrix, |
---|
175 | uniform float4 ambient) |
---|
176 | { |
---|
177 | // transform by indexed matrix |
---|
178 | float4 blendPos = float4(0,0,0,0); |
---|
179 | int i; |
---|
180 | for (i = 0; i < 2; ++i) |
---|
181 | { |
---|
182 | blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; |
---|
183 | } |
---|
184 | // view / projection |
---|
185 | oPosition = mul(viewProjectionMatrix, blendPos); |
---|
186 | |
---|
187 | |
---|
188 | colour = ambient; |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | /* |
---|
193 | Four-weight-per-vertex hardware skinning, 2 lights |
---|
194 | The trouble with vertex programs is they're not general purpose, but |
---|
195 | fixed function hardware skinning is very poorly supported |
---|
196 | */ |
---|
197 | void hardwareSkinningFourWeights_vp( |
---|
198 | float4 position : POSITION, |
---|
199 | float3 normal : NORMAL, |
---|
200 | float2 uv : TEXCOORD0, |
---|
201 | float4 blendIdx : BLENDINDICES, |
---|
202 | float4 blendWgt : BLENDWEIGHT, |
---|
203 | |
---|
204 | |
---|
205 | out float4 oPosition : SV_POSITION, |
---|
206 | out float2 oUv : TEXCOORD0, |
---|
207 | out float4 colour : COLOR, |
---|
208 | // Support up to 24 bones of float3x4 |
---|
209 | // vs_1_1 only supports 96 params so more than this is not feasible |
---|
210 | uniform float3x4 worldMatrix3x4Array[24], |
---|
211 | uniform float4x4 viewProjectionMatrix, |
---|
212 | uniform float4 lightPos[2], |
---|
213 | uniform float4 lightDiffuseColour[2], |
---|
214 | uniform float4 ambient) |
---|
215 | { |
---|
216 | // transform by indexed matrix |
---|
217 | float4 blendPos = float4(0,0,0,0); |
---|
218 | int i; |
---|
219 | for (i = 0; i < 4; ++i) |
---|
220 | { |
---|
221 | blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; |
---|
222 | } |
---|
223 | // view / projection |
---|
224 | oPosition = mul(viewProjectionMatrix, blendPos); |
---|
225 | // transform normal |
---|
226 | float3 norm = float3(0,0,0); |
---|
227 | for (i = 0; i < 4; ++i) |
---|
228 | { |
---|
229 | float3x3 d = (float3x3)worldMatrix3x4Array[blendIdx[i]]; |
---|
230 | norm += mul(d, normal) * |
---|
231 | blendWgt[i]; |
---|
232 | } |
---|
233 | norm = normalize(norm); |
---|
234 | // Lighting - support point and directional |
---|
235 | float3 lightDir0 = normalize( |
---|
236 | lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); |
---|
237 | float3 lightDir1 = normalize( |
---|
238 | lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); |
---|
239 | |
---|
240 | |
---|
241 | oUv = uv; |
---|
242 | colour = ambient + |
---|
243 | (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + |
---|
244 | (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); |
---|
245 | |
---|
246 | } |
---|
247 | |
---|
248 | // hardware morph animation (no normals) |
---|
249 | void hardwareMorphAnimation(float3 pos1 : POSITION, |
---|
250 | float4 normal : NORMAL, |
---|
251 | float2 uv : TEXCOORD0, |
---|
252 | float3 pos2 : TEXCOORD1, |
---|
253 | |
---|
254 | out float4 oPosition : SV_POSITION, |
---|
255 | out float2 oUv : TEXCOORD0, |
---|
256 | out float4 colour : COLOR, |
---|
257 | |
---|
258 | uniform float4x4 worldViewProj, |
---|
259 | uniform float4 anim_t) |
---|
260 | { |
---|
261 | // interpolate |
---|
262 | float4 interp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); |
---|
263 | |
---|
264 | oPosition = mul(worldViewProj, interp); |
---|
265 | oUv = uv; |
---|
266 | colour = float4(1,0,0,1); |
---|
267 | } |
---|
268 | |
---|
269 | // hardware pose animation (no normals) |
---|
270 | void hardwarePoseAnimation(float3 pos : POSITION, |
---|
271 | float4 normal : NORMAL, |
---|
272 | float2 uv : TEXCOORD0, |
---|
273 | float3 pose1 : TEXCOORD1, |
---|
274 | float3 pose2 : TEXCOORD2, |
---|
275 | |
---|
276 | out float4 oPosition : SV_POSITION, |
---|
277 | out float2 oUv : TEXCOORD0, |
---|
278 | out float4 colour : COLOR, |
---|
279 | |
---|
280 | uniform float4x4 worldViewProj, |
---|
281 | uniform float4 anim_t) |
---|
282 | { |
---|
283 | // interpolate |
---|
284 | float4 interp = float4(pos + anim_t.x*pose1 + anim_t.y*pose2, 1.0f); |
---|
285 | |
---|
286 | oPosition = mul(worldViewProj, interp); |
---|
287 | oUv = uv; |
---|
288 | colour = float4(1,0,0,1); |
---|
289 | } |
---|
290 | |
---|
291 | // hardware morph animation (with normals) |
---|
292 | void hardwareMorphAnimationWithNormals(float3 pos1 : POSITION, |
---|
293 | float3 normal1 : NORMAL, |
---|
294 | float2 uv : TEXCOORD0, |
---|
295 | float3 pos2 : TEXCOORD1, |
---|
296 | float3 normal2 : TEXCOORD2, |
---|
297 | |
---|
298 | out float4 oPosition : SV_POSITION, |
---|
299 | out float2 oUv : TEXCOORD0, |
---|
300 | out float4 colour : COLOR, |
---|
301 | |
---|
302 | uniform float4x4 worldViewProj, |
---|
303 | uniform float4 objSpaceLightPos, |
---|
304 | uniform float4 ambient, |
---|
305 | uniform float4 anim_t) |
---|
306 | { |
---|
307 | // interpolate position |
---|
308 | float4 posinterp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); |
---|
309 | |
---|
310 | // nlerp normal |
---|
311 | float3 ninterp = normal1 + anim_t.x*(normal2 - normal1); |
---|
312 | ninterp = normalize(ninterp); |
---|
313 | |
---|
314 | oPosition = mul(worldViewProj, posinterp); |
---|
315 | oUv = uv; |
---|
316 | |
---|
317 | float3 lightDir = normalize( |
---|
318 | objSpaceLightPos.xyz - (posinterp.xyz * objSpaceLightPos.w)); |
---|
319 | |
---|
320 | // Colour it red to make it easy to identify |
---|
321 | float lit = saturate(dot(lightDir, ninterp)); |
---|
322 | colour = float4((ambient.rgb + float3(lit,lit,lit)) * float3(1,0,0), 1); |
---|
323 | } |
---|
324 | |
---|
325 | // hardware pose animation (with normals) |
---|
326 | void hardwarePoseAnimationWithNormals(float3 pos : POSITION, |
---|
327 | float3 normal : NORMAL, |
---|
328 | float2 uv : TEXCOORD0, |
---|
329 | float3 pose1pos : TEXCOORD1, |
---|
330 | float3 pose1norm : TEXCOORD2, |
---|
331 | float3 pose2pos : TEXCOORD3, |
---|
332 | float3 pose2norm : TEXCOORD4, |
---|
333 | |
---|
334 | out float4 oPosition : SV_POSITION, |
---|
335 | out float2 oUv : TEXCOORD0, |
---|
336 | out float4 colour : COLOR, |
---|
337 | |
---|
338 | uniform float4x4 worldViewProj, |
---|
339 | uniform float4 objSpaceLightPos, |
---|
340 | uniform float4 ambient, |
---|
341 | uniform float4 anim_t) |
---|
342 | { |
---|
343 | // interpolate |
---|
344 | float4 posinterp = float4(pos + anim_t.x*pose1pos + anim_t.y*pose2pos, 1.0f); |
---|
345 | |
---|
346 | // nlerp normal |
---|
347 | // First apply the pose normals (these are actual normals, not offsets) |
---|
348 | float3 ninterp = anim_t.x*pose1norm + anim_t.y*pose2norm; |
---|
349 | |
---|
350 | // Now add back any influence of the original normal |
---|
351 | // This depends on what the cumulative weighting left the normal at, if it's lacking or cancelled out |
---|
352 | //float remainder = 1.0 - min(anim_t.x + anim_t.y, 1.0); |
---|
353 | float remainder = 1.0 - min(length(ninterp), 1.0); |
---|
354 | ninterp = ninterp + (normal * remainder); |
---|
355 | ninterp = normalize(ninterp); |
---|
356 | |
---|
357 | oPosition = mul(worldViewProj, posinterp); |
---|
358 | oUv = uv; |
---|
359 | |
---|
360 | float3 lightDir = normalize( |
---|
361 | objSpaceLightPos.xyz - (posinterp.xyz * objSpaceLightPos.w)); |
---|
362 | |
---|
363 | // Colour it red to make it easy to identify |
---|
364 | float lit = saturate(dot(lightDir, ninterp)); |
---|
365 | colour = float4((ambient.rgb + float3(lit,lit,lit)) * float3(1,0,0), 1); |
---|
366 | } |
---|
367 | |
---|
368 | void basicPassthroughTangent_v( float4 position : POSITION, |
---|
369 | float3 normal : NORMAL, |
---|
370 | float2 texcord : TEXCOORD0, |
---|
371 | float3 tangent : TANGENT, |
---|
372 | out float4 oPosition : SV_POSITION, |
---|
373 | out float3 oTangent : TEXCOORD0, |
---|
374 | |
---|
375 | uniform float4x4 worldViewProj) |
---|
376 | { |
---|
377 | oPosition = mul(worldViewProj, position); |
---|
378 | oTangent = tangent; |
---|
379 | } |
---|
380 | void basicPassthroughNormal_v(float4 position : POSITION, |
---|
381 | float3 normal : NORMAL, |
---|
382 | float2 texcord : TEXCOORD0, |
---|
383 | float3 tangent : TANGENT, |
---|
384 | out float4 oPosition : SV_POSITION, |
---|
385 | out float3 oNormal : TEXCOORD0, |
---|
386 | uniform float4x4 worldViewProj) |
---|
387 | { |
---|
388 | oPosition = mul(worldViewProj, position); |
---|
389 | oNormal = normal; |
---|
390 | } |
---|
391 | // Basic fragment program to display UV |
---|
392 | float4 showuv_p (float4 position : SV_POSITION, float2 uv : TEXCOORD0, float4 colour : COLOR) : COLOR |
---|
393 | { |
---|
394 | // wrap values using frac |
---|
395 | return float4(frac(uv.x), frac(uv.y), 0, 1); |
---|
396 | } |
---|
397 | // Basic fragment program to display 3d uv |
---|
398 | float4 showuvdir3d_p (float4 position : SV_POSITION, float3 uv : TEXCOORD0) : COLOR |
---|
399 | { |
---|
400 | float3 n = normalize(uv); |
---|
401 | return float4(n.x, n.y, n.z, 1); |
---|
402 | } |
---|
403 | |
---|
404 | |
---|