1 | /*
|
---|
2 | Basic ambient lighting vertex program
|
---|
3 | */
|
---|
4 | void ambientOneTexture_vp(float4 position : POSITION,
|
---|
5 | float2 uv : TEXCOORD0,
|
---|
6 |
|
---|
7 | out float4 oPosition : POSITION,
|
---|
8 | out float2 oUv : TEXCOORD0,
|
---|
9 | out float4 colour : COLOR,
|
---|
10 |
|
---|
11 | uniform float4x4 worldViewProj,
|
---|
12 | uniform float4 ambient)
|
---|
13 | {
|
---|
14 | oPosition = mul(worldViewProj, position);
|
---|
15 | oUv = uv;
|
---|
16 | colour = ambient;
|
---|
17 | }
|
---|
18 |
|
---|
19 | /*
|
---|
20 | Single-weight-per-vertex hardware skinning, 2 lights
|
---|
21 | The trouble with vertex programs is they're not general purpose, but
|
---|
22 | fixed function hardware skinning is very poorly supported
|
---|
23 | */
|
---|
24 | void hardwareSkinningOneWeight_vp(
|
---|
25 | float4 position : POSITION,
|
---|
26 | float3 normal : NORMAL,
|
---|
27 | float2 uv : TEXCOORD0,
|
---|
28 | float blendIdx : BLENDINDICES,
|
---|
29 |
|
---|
30 |
|
---|
31 | out float4 oPosition : POSITION,
|
---|
32 | out float2 oUv : TEXCOORD0,
|
---|
33 | out float4 colour : COLOR,
|
---|
34 | // Support up to 24 bones of float3x4
|
---|
35 | // vs_1_1 only supports 96 params so more than this is not feasible
|
---|
36 | uniform float3x4 worldMatrix3x4Array[24],
|
---|
37 | uniform float4x4 viewProjectionMatrix,
|
---|
38 | uniform float4 lightPos[2],
|
---|
39 | uniform float4 lightDiffuseColour[2],
|
---|
40 | uniform float4 ambient)
|
---|
41 | {
|
---|
42 | // transform by indexed matrix
|
---|
43 | float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0);
|
---|
44 | // view / projection
|
---|
45 | oPosition = mul(viewProjectionMatrix, blendPos);
|
---|
46 | // transform normal
|
---|
47 | float3 norm = mul((float3x3)worldMatrix3x4Array[blendIdx], normal);
|
---|
48 | // Lighting - support point and directional
|
---|
49 | float3 lightDir0 = normalize(
|
---|
50 | lightPos[0].xyz - (blendPos.xyz * lightPos[0].w));
|
---|
51 | float3 lightDir1 = normalize(
|
---|
52 | lightPos[1].xyz - (blendPos.xyz * lightPos[1].w));
|
---|
53 |
|
---|
54 | oUv = uv;
|
---|
55 | colour = ambient +
|
---|
56 | (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) +
|
---|
57 | (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]);
|
---|
58 |
|
---|
59 | }
|
---|
60 |
|
---|
61 | /*
|
---|
62 | Single-weight-per-vertex hardware skinning, shadow-caster pass
|
---|
63 | */
|
---|
64 | void hardwareSkinningOneWeightCaster_vp(
|
---|
65 | float4 position : POSITION,
|
---|
66 | float3 normal : NORMAL,
|
---|
67 | float blendIdx : BLENDINDICES,
|
---|
68 |
|
---|
69 |
|
---|
70 | out float4 oPosition : POSITION,
|
---|
71 | out float4 colour : COLOR,
|
---|
72 | // Support up to 24 bones of float3x4
|
---|
73 | // vs_1_1 only supports 96 params so more than this is not feasible
|
---|
74 | uniform float3x4 worldMatrix3x4Array[24],
|
---|
75 | uniform float4x4 viewProjectionMatrix,
|
---|
76 | uniform float4 ambient)
|
---|
77 | {
|
---|
78 | // transform by indexed matrix
|
---|
79 | float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0);
|
---|
80 | // view / projection
|
---|
81 | oPosition = mul(viewProjectionMatrix, blendPos);
|
---|
82 |
|
---|
83 | colour = ambient;
|
---|
84 |
|
---|
85 | }
|
---|
86 |
|
---|
87 | /*
|
---|
88 | Four-weight-per-vertex hardware skinning, 2 lights
|
---|
89 | The trouble with vertex programs is they're not general purpose, but
|
---|
90 | fixed function hardware skinning is very poorly supported
|
---|
91 | */
|
---|
92 | void hardwareSkinningFourWeights_vp(
|
---|
93 | float4 position : POSITION,
|
---|
94 | float3 normal : NORMAL,
|
---|
95 | float2 uv : TEXCOORD0,
|
---|
96 | float4 blendIdx : BLENDINDICES,
|
---|
97 | float4 blendWgt : BLENDWEIGHT,
|
---|
98 |
|
---|
99 |
|
---|
100 | out float4 oPosition : POSITION,
|
---|
101 | out float2 oUv : TEXCOORD0,
|
---|
102 | out float4 colour : COLOR,
|
---|
103 | // Support up to 24 bones of float3x4
|
---|
104 | // vs_1_1 only supports 96 params so more than this is not feasible
|
---|
105 | uniform float3x4 worldMatrix3x4Array[24],
|
---|
106 | uniform float4x4 viewProjectionMatrix,
|
---|
107 | uniform float4 lightPos[2],
|
---|
108 | uniform float4 lightDiffuseColour[2],
|
---|
109 | uniform float4 ambient)
|
---|
110 | {
|
---|
111 | // transform by indexed matrix
|
---|
112 | float4 blendPos = float4(0,0,0,0);
|
---|
113 | int i;
|
---|
114 | for (i = 0; i < 4; ++i)
|
---|
115 | {
|
---|
116 | blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i];
|
---|
117 | }
|
---|
118 | // view / projection
|
---|
119 | oPosition = mul(viewProjectionMatrix, blendPos);
|
---|
120 | // transform normal
|
---|
121 | float3 norm = float3(0,0,0);
|
---|
122 | for (i = 0; i < 4; ++i)
|
---|
123 | {
|
---|
124 | norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) *
|
---|
125 | blendWgt[i];
|
---|
126 | }
|
---|
127 | norm = normalize(norm);
|
---|
128 | // Lighting - support point and directional
|
---|
129 | float3 lightDir0 = normalize(
|
---|
130 | lightPos[0].xyz - (blendPos.xyz * lightPos[0].w));
|
---|
131 | float3 lightDir1 = normalize(
|
---|
132 | lightPos[1].xyz - (blendPos.xyz * lightPos[1].w));
|
---|
133 |
|
---|
134 |
|
---|
135 | oUv = uv;
|
---|
136 | colour = ambient +
|
---|
137 | (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) +
|
---|
138 | (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]);
|
---|
139 |
|
---|
140 | }
|
---|