home *** CD-ROM | disk | FTP | other *** search
- // v2fConnector.HPOS is set to be the homogenous space coordinate
- // v2f.diffCol is set to be the texture coordinate
- // v2f.worldEyeDir is set to be the eye direction (from eye) in world space
- // v2f.worldTanMatrixX is set to be the tangentMatrix X-row in world space
- // v2f.worldTanMatrixY is set to be the tangentMatrix Y-row in world space
- // v2f.worldTanMatrixZ is set to be the tangentMatrix Z-row in world space
- // v2f.SkinSilouetteVec is set to be the skin silouette vector
- // InverseTransposes not used, as we assume no nonuniform scales.
-
-
- // vecMul(matrix, float3) multiplies like a vector instead of point (no translate)
- float3 vecMul(const float4x4 matrix, const float3 vec){
- return(float3(dot(vec, matrix._11_12_13),
- dot(vec, matrix._21_22_23),
- dot(vec, matrix._31_32_33)));
- }
-
- struct a2vConnector : application2vertex {
- float4 coord;
- float4 normal;
- float4 tangent;
- float3 boneWeight0_2;
- float3 boneIndex0_2;
- float4 diffCol;
- };
-
- struct v2fConnector : vertex2fragment {
- float4 HPOS :HPOS;
- float4 diffCol :TEX0;
- float3 worldEyeDir :TEX1;
- float3 worldTanMatrixX :TEX5;
- float3 worldTanMatrixY :TEX6;
- float3 worldTanMatrixZ :TEX7;
- float4 SkinSilouetteVec :TEX2;
- };
-
- v2fConnector main(a2vConnector a2v,
- const uniform float4x4 model[3],
- const uniform float4 globalCamPos,
- const uniform float4x4 viewProj){
- v2fConnector v2f;
-
- v2f.diffCol = a2v.diffCol;
-
- float4 objectCoord = a2v.coord;
- float4x4 worldSkinMatrix;
- worldSkinMatrix[0] = a2v.boneWeight0_2.x * model[a2v.boneIndex0_2.x][0];
- worldSkinMatrix[1] = a2v.boneWeight0_2.x * model[a2v.boneIndex0_2.x][1];
- worldSkinMatrix[2] = a2v.boneWeight0_2.x * model[a2v.boneIndex0_2.x][2];
- worldSkinMatrix[3] = a2v.boneWeight0_2.x * model[a2v.boneIndex0_2.x][3];
- worldSkinMatrix[0] = worldSkinMatrix[0] + a2v.boneWeight0_2.y * model[a2v.boneIndex0_2.y][0];
- worldSkinMatrix[1] = worldSkinMatrix[1] + a2v.boneWeight0_2.y * model[a2v.boneIndex0_2.y][1];
- worldSkinMatrix[2] = worldSkinMatrix[2] + a2v.boneWeight0_2.y * model[a2v.boneIndex0_2.y][2];
- worldSkinMatrix[3] = worldSkinMatrix[3] + a2v.boneWeight0_2.y * model[a2v.boneIndex0_2.y][3];
- worldSkinMatrix[0] = worldSkinMatrix[0] + a2v.boneWeight0_2.z * model[a2v.boneIndex0_2.z][0];
- worldSkinMatrix[1] = worldSkinMatrix[1] + a2v.boneWeight0_2.z * model[a2v.boneIndex0_2.z][1];
- worldSkinMatrix[2] = worldSkinMatrix[2] + a2v.boneWeight0_2.z * model[a2v.boneIndex0_2.z][2];
- worldSkinMatrix[3] = worldSkinMatrix[3] + a2v.boneWeight0_2.z * model[a2v.boneIndex0_2.z][3];
- float4 worldCoord = mul(worldSkinMatrix, objectCoord);
- float4 worldEyePos = globalCamPos;
- float3 worldEyeDir = normalize(worldCoord.xyz - worldEyePos.xyz);
- v2f.worldEyeDir = worldEyeDir;
-
- float4 objectNormal = a2v.normal;
- float3 worldNormal = vecMul(worldSkinMatrix, objectNormal);
- worldNormal = normalize(worldNormal);
- float3 objectTangent = a2v.tangent.xyz;
- float3 worldTangent = vecMul(worldSkinMatrix, objectTangent);
- worldTangent = normalize(worldTangent);
- float3 worldBinormal = a2v.tangent.w * normalize(cross(worldNormal, worldTangent));
- float3 worldTanMatrixX = float3(worldTangent.x, worldBinormal.x, worldNormal.x);
- v2f.worldTanMatrixX = worldTanMatrixX;
-
- float3 worldTanMatrixY = float3(worldTangent.y, worldBinormal.y, worldNormal.y);
- v2f.worldTanMatrixY = worldTanMatrixY;
-
- float3 worldTanMatrixZ = float3(worldTangent.z, worldBinormal.z, worldNormal.z);
- v2f.worldTanMatrixZ = worldTanMatrixZ;
-
- float4 skinSilouetteVec;
- skinSilouetteVec.x = 1.0-dot(worldNormal, -worldEyeDir);
- skinSilouetteVec.y = skinSilouetteVec.x*skinSilouetteVec.x;
- v2f.SkinSilouetteVec = skinSilouetteVec;
-
- float4 hpos = mul(viewProj, worldCoord);
- v2f.HPOS = hpos;
-
- return v2f;
- }