float4x4 viewprojection; float4x4 Model; float4x4 shadowBoxMatrix; uniform float4 ShadowPos; #ifdef _XBOX // Vertex shader texture sampler for the bone matrix palette. #define POINT_SAMPLER sampler_state { MipFilter = NONE; MinFilter = POINT; MagFilter = POINT; AddressU = CLAMP; AddressV = CLAMP; } sampler1D bone_palette_texture = POINT_SAMPLER; int bone_count; //jboldiga 2011-01-27: Fetch bone from the bone pallete in the texture cache float4x3 TFetchBoneMatrix( float BoneIndex ) { float TexCoord = BoneIndex / bone_count; float4 Result1; float4 Result2; float4 Result3; asm { tfetch1D Result1, TexCoord, bone_palette_texture, UseComputedLOD = false, OffsetX = 0.5 tfetch1D Result2, TexCoord, bone_palette_texture, UseComputedLOD = false, OffsetX = 1.5 tfetch1D Result3, TexCoord, bone_palette_texture, UseComputedLOD = false, OffsetX = 2.5 }; float4x3 Result; Result._11_21_31_41 = Result1.xyzw; Result._12_22_32_42 = Result2.xyzw; Result._13_23_33_43 = Result3.xyzw; return Result; } #endif struct IN { float4 position : POSITION; #ifdef _XBOX float4 boneIndices : BLENDINDICES; float4 boneWeights : BLENDWEIGHT; #endif }; struct OUT { float4 position : POSITION; float4 color : COLOR; }; OUT main(IN input) { OUT output; float4 position = input.position; #ifdef _XBOX float BoneWeights[4] = (float[4])input.boneWeights; int BoneIndices[4] = (int[4])input.boneIndices; float4x3 LocalToWorldMatrix = 0; for( int i = 3; i >= 0; --i ) { LocalToWorldMatrix += BoneWeights[i] * TFetchBoneMatrix( BoneIndices[i] ); } [isolate] { position = float4(mul( position, LocalToWorldMatrix ), 1.0f); } #endif float4 world_pos = mul(position, Model); float4 light_vector = normalize(world_pos-ShadowPos); float4 projectedPos = world_pos+light_vector*world_pos.z; projectedPos = mul(projectedPos, shadowBoxMatrix); output.position = mul(projectedPos, viewprojection); // distance along light vector for self shadowing output.position.z = -world_pos.z/light_vector.z; output.position.z /= 3; // maps to clip space (0,1) output.position.z = 1- output.position.z; //original //output.color.w = 1.0f - (world_pos.z/4); //scott's version //float shadowFadePower = pow(world_pos.z,.88); //output.color.w = 1.0f - clamp(shadowFadePower,0,.76); // set shadow alpha .. will and scott new version const float height = 1.815; // height of fighter in meters float lighter = pow(((world_pos.z/height)+.5) , 4); lighter = clamp(lighter, 0, .6); output.color.w = .4f + lighter; // .w is alpha component. 1 = darkest, 0 = lightest //set shadow color // float color_base = 0.9f; // 1= darkest // float color_mod = (.9f * (world_pos.z/height)); //float color_mod = 0.0f; // color_mod = clamp(color_mod, 0.0, .6); float color_mod = 0.0f; output.color.x = color_mod; output.color.y = color_mod; output.color.z = color_mod; output.color.w = color_mod; return output; }