[692] | 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 | } |
---|
| 141 | |
---|
| 142 | void hardwareMorphAnimation(float3 pos1 : POSITION, |
---|
| 143 | float4 normal : NORMAL, |
---|
| 144 | float2 uv : TEXCOORD0, |
---|
| 145 | float3 pos2 : TEXCOORD1, |
---|
| 146 | |
---|
| 147 | out float4 oPosition : POSITION, |
---|
| 148 | out float2 oUv : TEXCOORD0, |
---|
| 149 | out float4 colour : COLOR, |
---|
| 150 | |
---|
| 151 | uniform float4x4 worldViewProj, |
---|
| 152 | uniform float4 anim_t) |
---|
| 153 | { |
---|
| 154 | // interpolate |
---|
| 155 | float4 interp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); |
---|
| 156 | |
---|
| 157 | oPosition = mul(worldViewProj, interp); |
---|
| 158 | oUv = uv; |
---|
| 159 | colour = float4(1,0,0,1); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | void hardwarePoseAnimation(float3 pos : POSITION, |
---|
| 163 | float4 normal : NORMAL, |
---|
| 164 | float2 uv : TEXCOORD0, |
---|
| 165 | float3 pose1 : TEXCOORD1, |
---|
| 166 | float3 pose2 : TEXCOORD2, |
---|
| 167 | |
---|
| 168 | out float4 oPosition : POSITION, |
---|
| 169 | out float2 oUv : TEXCOORD0, |
---|
| 170 | out float4 colour : COLOR, |
---|
| 171 | |
---|
| 172 | uniform float4x4 worldViewProj, |
---|
| 173 | uniform float4 anim_t) |
---|
| 174 | { |
---|
| 175 | // interpolate |
---|
| 176 | float4 interp = float4(pos + anim_t.x*pose1 + anim_t.y*pose2, 1.0f); |
---|
| 177 | |
---|
| 178 | oPosition = mul(worldViewProj, interp); |
---|
| 179 | oUv = uv; |
---|
| 180 | colour = float4(1,0,0,1); |
---|
| 181 | } |
---|