| #define MaxBones 59 |
| |
| float4x4 Bones[MaxBones]; |
| float4x4 View; |
| float4x4 Projection; |
| |
| float specPow = 30; |
| float Kdiffuse = 1; |
| float Kspecular = 2; |
| float Kreflection = 1; |
| |
| texture Diffuse_Texture; |
| sampler diffuse_Sampler = sampler_state |
| { |
| Texture = <Diffuse_Texture>; |
| MinFilter = Linear; |
| MagFilter = Linear; |
| MipFilter = Linear; |
| AddressU = Wrap; |
| AddressV = Wrap; |
| }; |
| |
| texture Specular_Texture; |
| sampler specular_Sampler = sampler_state |
| { |
| Texture = (Specular_Texture); |
| MagFilter = LINEAR; |
| MinFilter = LINEAR; |
| Mipfilter = LINEAR; |
| AddressU = Wrap; |
| AddressV = Wrap; |
| }; |
| |
| texture Normal_Texture; |
| sampler normal_Sampler = sampler_state |
| { |
| Texture = (Normal_Texture); |
| MagFilter = LINEAR; |
| MinFilter = LINEAR; |
| Mipfilter = LINEAR; |
| AddressU = Wrap; |
| AddressV = Wrap; |
| }; |
| |
| texture Env_Texture; |
| sampler env_Sampler = sampler_state |
| { |
| Texture = <Env_Texture>; |
| MinFilter = Linear; |
| MagFilter = Linear; |
| MipFilter = Linear; |
| AddressU = Wrap; |
| AddressV = Wrap; |
| }; |
| |
| struct VS_INPUT |
| { |
| float4 Position : POSITION0; |
| float3 Normal : NORMAL0; |
| float2 TexCoord : TEXCOORD0; |
| //float3 Binormal : BINORMAL0; |
| float3 Tangent : TANGENT0; |
| float4 BoneIndices : BLENDINDICES0; |
| float4 BoneWeights : BLENDWEIGHT0; |
| }; |
| |
| struct VS_OUTPUT |
| { |
| float4 Position : POSITION0; |
| float2 TexCoord : TEXCOORD0; |
| float2 Depth : TEXCOORD1; |
| float3x3 TangentToWorld : TEXCOORD2; |
| //float3 Data1 : TEXCOORD3; |
| }; |
| |
| VS_OUTPUT VS_Function(VS_INPUT input) |
| { |
| VS_OUTPUT output; |
| float4x4 skinTransform = 0; |
| |
| skinTransform += Bones[input.BoneIndices.x] * input.BoneWeights.x; |
| skinTransform += Bones[input.BoneIndices.y] * input.BoneWeights.y; |
| skinTransform += Bones[input.BoneIndices.z] * input.BoneWeights.z; |
| skinTransform += Bones[input.BoneIndices.w] * input.BoneWeights.w; |
| |
| float4 pos = mul(input.Position, skinTransform); |
| float3 eyeLoc = mul(View._m30_m31_m32, transpose(View)); |
| float3 eyeDir = eyeLoc - pos; |
| pos = mul(pos, View); |
| pos = mul(pos, Projection); |
| |
| float3x3 tangentSpace; |
| tangentSpace[0] = mul(input.Tangent, skinTransform); |
| tangentSpace[1] = mul(cross(input.Tangent, input.Normal), skinTransform); |
| //tangentSpace[1] = mul(input.Binormal, skinTransform); |
| tangentSpace[2] = mul(input.Normal, skinTransform); |
| |
| output.Position = pos; |
| output.TangentToWorld = tangentSpace; |
| output.TexCoord = input.TexCoord; |
| output.Depth.x = output.Position.z; |
| output.Depth.y = output.Position.w; |
| //output.Data1 = normalize(mul(tangentSpace, eyeDir)); |
| |
| return output; |
| } |
| |
| struct PS_Output |
| { |
| half4 Color : COLOR0; |
| half4 Normal : COLOR1; |
| half4 Depth : COLOR2; |
| }; |
| |
| PS_Output PS_Function(VS_OUTPUT input) |
| { |
| PS_Output output; |
| float4 outColor = tex2D(diffuse_Sampler, input.TexCoord); |
| |
| float4 specularAttributes = tex2D(specular_Sampler, input.TexCoord); |
| //specular Intensity |
| outColor.a = specularAttributes.r; |
| |
| // read the normal from the normal map |
| float3 normalFromMap = tex2D(normal_Sampler, input.TexCoord); |
| |
| //tranform to [-1,1] |
| normalFromMap = 2.0f * normalFromMap - 1.0f; |
| //transform into world space |
| normalFromMap = mul(normalFromMap, input.TangentToWorld); |
| //normalize the result |
| normalFromMap = normalize(normalFromMap); |
| //output the normal, in [0,1] space |
| output.Normal.rgb = 0.5f * (normalFromMap + 1.0f); |
| |
| //specular Power |
| output.Normal.a = specularAttributes.a; |
| |
| output.Depth = input.Depth.x / input.Depth.y; |
| |
| output.Color = outColor; |
| |
| return output; |
| } |
| |
| technique Technique1 |
| { |
| pass Pass1 |
| { |
| VertexShader = compile vs_2_0 VS_Function(); |
| PixelShader = compile ps_2_0 PS_Function(); |
| } |
| } |