[5026] | 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 | Two-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 hardwareSkinningTwoWeights_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 < 2; ++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 < 2; ++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 = float4(0.5, 0.5, 0.5, 1) + |
---|
| 137 | (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + |
---|
| 138 | (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); |
---|
| 139 | |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | Two-weight-per-vertex hardware skinning, shadow caster pass |
---|
| 144 | */ |
---|
| 145 | void hardwareSkinningTwoWeightsCaster_vp( |
---|
| 146 | float4 position : POSITION, |
---|
| 147 | float3 normal : NORMAL, |
---|
| 148 | float2 uv : TEXCOORD0, |
---|
| 149 | float4 blendIdx : BLENDINDICES, |
---|
| 150 | float4 blendWgt : BLENDWEIGHT, |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | out float4 oPosition : POSITION, |
---|
| 154 | out float4 colour : COLOR, |
---|
| 155 | // Support up to 24 bones of float3x4 |
---|
| 156 | // vs_1_1 only supports 96 params so more than this is not feasible |
---|
| 157 | uniform float3x4 worldMatrix3x4Array[24], |
---|
| 158 | uniform float4x4 viewProjectionMatrix, |
---|
| 159 | uniform float4 ambient) |
---|
| 160 | { |
---|
| 161 | // transform by indexed matrix |
---|
| 162 | float4 blendPos = float4(0,0,0,0); |
---|
| 163 | int i; |
---|
| 164 | for (i = 0; i < 2; ++i) |
---|
| 165 | { |
---|
| 166 | blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; |
---|
| 167 | } |
---|
| 168 | // view / projection |
---|
| 169 | oPosition = mul(viewProjectionMatrix, blendPos); |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | colour = ambient; |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | /* |
---|
| 179 | Four-weight-per-vertex hardware skinning, 2 lights |
---|
| 180 | The trouble with vertex programs is they're not general purpose, but |
---|
| 181 | fixed function hardware skinning is very poorly supported |
---|
| 182 | */ |
---|
| 183 | void hardwareSkinningFourWeights_vp( |
---|
| 184 | float4 position : POSITION, |
---|
| 185 | float3 normal : NORMAL, |
---|
| 186 | float2 uv : TEXCOORD0, |
---|
| 187 | float4 blendIdx : BLENDINDICES, |
---|
| 188 | float4 blendWgt : BLENDWEIGHT, |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | out float4 oPosition : POSITION, |
---|
| 192 | out float2 oUv : TEXCOORD0, |
---|
| 193 | out float4 colour : COLOR, |
---|
| 194 | // Support up to 24 bones of float3x4 |
---|
| 195 | // vs_1_1 only supports 96 params so more than this is not feasible |
---|
| 196 | uniform float3x4 worldMatrix3x4Array[24], |
---|
| 197 | uniform float4x4 viewProjectionMatrix, |
---|
| 198 | uniform float4 lightPos[2], |
---|
| 199 | uniform float4 lightDiffuseColour[2], |
---|
| 200 | uniform float4 ambient) |
---|
| 201 | { |
---|
| 202 | // transform by indexed matrix |
---|
| 203 | float4 blendPos = float4(0,0,0,0); |
---|
| 204 | int i; |
---|
| 205 | for (i = 0; i < 4; ++i) |
---|
| 206 | { |
---|
| 207 | blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; |
---|
| 208 | } |
---|
| 209 | // view / projection |
---|
| 210 | oPosition = mul(viewProjectionMatrix, blendPos); |
---|
| 211 | // transform normal |
---|
| 212 | float3 norm = float3(0,0,0); |
---|
| 213 | for (i = 0; i < 4; ++i) |
---|
| 214 | { |
---|
| 215 | norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * |
---|
| 216 | blendWgt[i]; |
---|
| 217 | } |
---|
| 218 | norm = normalize(norm); |
---|
| 219 | // Lighting - support point and directional |
---|
| 220 | float3 lightDir0 = normalize( |
---|
| 221 | lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); |
---|
| 222 | float3 lightDir1 = normalize( |
---|
| 223 | lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | oUv = uv; |
---|
| 227 | colour = ambient + |
---|
| 228 | (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + |
---|
| 229 | (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); |
---|
| 230 | |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | void hardwareMorphAnimation(float3 pos1 : POSITION, |
---|
| 234 | float4 normal : NORMAL, |
---|
| 235 | float2 uv : TEXCOORD0, |
---|
| 236 | float3 pos2 : TEXCOORD1, |
---|
| 237 | |
---|
| 238 | out float4 oPosition : POSITION, |
---|
| 239 | out float2 oUv : TEXCOORD0, |
---|
| 240 | out float4 colour : COLOR, |
---|
| 241 | |
---|
| 242 | uniform float4x4 worldViewProj, |
---|
| 243 | uniform float4 anim_t) |
---|
| 244 | { |
---|
| 245 | // interpolate |
---|
| 246 | float4 interp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); |
---|
| 247 | |
---|
| 248 | oPosition = mul(worldViewProj, interp); |
---|
| 249 | oUv = uv; |
---|
| 250 | colour = float4(1,0,0,1); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | void hardwarePoseAnimation(float3 pos : POSITION, |
---|
| 254 | float4 normal : NORMAL, |
---|
| 255 | float2 uv : TEXCOORD0, |
---|
| 256 | float3 pose1 : TEXCOORD1, |
---|
| 257 | float3 pose2 : TEXCOORD2, |
---|
| 258 | |
---|
| 259 | out float4 oPosition : POSITION, |
---|
| 260 | out float2 oUv : TEXCOORD0, |
---|
| 261 | out float4 colour : COLOR, |
---|
| 262 | |
---|
| 263 | uniform float4x4 worldViewProj, |
---|
| 264 | uniform float4 anim_t) |
---|
| 265 | { |
---|
| 266 | // interpolate |
---|
| 267 | float4 interp = float4(pos + anim_t.x*pose1 + anim_t.y*pose2, 1.0f); |
---|
| 268 | |
---|
| 269 | oPosition = mul(worldViewProj, interp); |
---|
| 270 | oUv = uv; |
---|
| 271 | colour = float4(1,0,0,1); |
---|
| 272 | } |
---|