home *** CD-ROM | disk | FTP | other *** search
- // v2fConnector.HPOS is set to be the homogenous space coordinate
- // v2f.skinColor_frontSpec is set to be the texture coordinate
- // v2f.worldNormal is set to be the normal in world space
- // v2f.worldReflect is set to be the reflection in world space
- // v2f.worldEyeDir is set to be the eye direction (from eye) 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;
- float3 boneWeight0_2;
- float3 boneIndex0_2;
- float2 skinColor_frontSpec;
- };
-
- struct v2fConnector : vertex2fragment {
- float4 HPOS :HPOS;
- float2 skinColor_frontSpec :TEX0;
- float3 worldNormal :TEX1;
- float3 worldReflect :TEX2;
- float3 worldEyeDir :TEX3;
- float4 skinSilouetteVec :TEX4;
- };
-
- v2fConnector main(a2vConnector a2v,
- const uniform float4x4 model[7],
- const uniform float4 globalCamPos,
- const uniform float4x4 viewProj){
- v2fConnector v2f;
-
- v2f.skinColor_frontSpec = a2v.skinColor_frontSpec;
-
- float4 objectNormal = a2v.normal;
- 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];
- float3 worldNormal = vecMul(worldSkinMatrix, objectNormal);
- worldNormal = normalize(worldNormal);
- v2f.worldNormal = worldNormal;
-
- float4 objectCoord = a2v.coord;
- float4 worldCoord = mul(worldSkinMatrix, objectCoord);
- float4 worldEyePos = globalCamPos;
- float3 worldEyeDir = normalize(worldCoord.xyz - worldEyePos.xyz);
- float3 worldReflection = reflect(worldEyeDir, worldNormal);
- v2f.worldReflect = worldReflection;
-
- v2f.worldEyeDir = worldEyeDir;
-
- 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;
- }