Shaders for Shadows
Shader code for rendering shadows of translucent occluders, soft shadows and single scattering with moment shadow maps.
 All Classes Files Functions Variables Pages
Skinning.fx
1 
18 void ComputeMeshToWorldSpaceSkinned(out float4x4 MeshToWorldSpaceSkinned,float4x4 ObjectToWorldSpace,float Time,float3 SkinWeights,int4 SkinIndices,SSamplerTexturePair2D AnimationTextureSampler,float4 AnimationTextureSize,float3 AnimationTextureTimeRange){
19  // Construct a complete list of skin weights
20  float4 AllSkinWeights=float4(SkinWeights.x,SkinWeights.y,SkinWeights.z,1.0f-dot(float3(1.0f,1.0f,1.0f),SkinWeights));
21  // Compute the texture coordinate for the time-axis with proper wrapping and
22  // without going into no-mans land
23  float WrappedRelativeTime=frac((Time-AnimationTextureTimeRange.x)*AnimationTextureTimeRange.z);
24  float TimeCoordinate=lerp(0.5f*AnimationTextureTimeRange.z,1.0f-0.5f*AnimationTextureTimeRange.z,WrappedRelativeTime);
25  // Prepare the mesh to object space matrix
26  float4x4 MeshToObjectSpace=float4x4(0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f);
27  [unroll] for(int i=0;i!=4;++i){
28  // Compute the texture coordinate
29  int iRotationRow=SkinIndices[i]*2;
30  float2 RotationTexCoord=float2(TimeCoordinate,iRotationRow*AnimationTextureSize.w);
31  RotationTexCoord.y+=0.5f*AnimationTextureSize.w;
32  float2 TranslationScalingTexCoord=RotationTexCoord+float2(0.0f,AnimationTextureSize.w);
33  // Sample the textures to obtain the coordinate frame
34  float4 Rotation=normalize(AnimationTextureSampler.Texture.SampleLevel(AnimationTextureSampler.Sampler,RotationTexCoord,0.0f));
35  float4 TranslationScaling=AnimationTextureSampler.Texture.SampleLevel(AnimationTextureSampler.Sampler,TranslationScalingTexCoord,0.0f);
36  // Convert to a matrix and add to the weighted sum
37  float xx=Rotation.x*Rotation.x;
38  float xy=Rotation.x*Rotation.y;
39  float xz=Rotation.x*Rotation.z;
40  float xw=Rotation.x*Rotation.w;
41  float yy=Rotation.y*Rotation.y;
42  float yz=Rotation.y*Rotation.z;
43  float yw=Rotation.y*Rotation.w;
44  float zz=Rotation.z*Rotation.z;
45  float zw=Rotation.z*Rotation.w;
46  float Scaling=TranslationScaling.w;
47  MeshToObjectSpace+=AllSkinWeights[i]*float4x4(
48  Scaling*(1.0f-2.0f*(yy+zz)),2.0f*Scaling*(xy+zw),2.0f*Scaling*(xz-yw),0.0f,
49  2.0f*Scaling*(xy-zw),Scaling*(1.0f-2.0f*(xx+zz)),2.0f*Scaling*(yz+xw),0.0f,
50  2.0f*Scaling*(xz+yw),2.0f*Scaling*(yz-xw),Scaling*(1.0f-2.0f*(xx+yy)),0.0f,
51  TranslationScaling.x,TranslationScaling.y,TranslationScaling.z,1.0f);
52  }
53  // Go to world space
54  MeshToWorldSpaceSkinned=mul(MeshToObjectSpace,ObjectToWorldSpace);
55 }