#ifdef _MAX_ // Max includes are in ../3dsMax/MaterialLibraries/ #include "../KFF_Macros" #include "lighting.fx" #else #include "c:/_project/Fatburger/Assets/Shaders/lighting.fx" #include "c:/_project/Fatburger/Assets/Shaders/KFF_Macros" #endif #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; #endif texture TextureMap < string Name = "C:\\_project\\Fatburger\\Assets\\Characters\\Audience\\Textures\\aud_02_M_00_D.dds"; string UIName = "Diffuse Map"; string ResourceType = "2D"; >; sampler2D TextureMapSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; float4x4 wvp : WorldViewProjection < string UIType = "None"; >; float4x4 model : Model < string UIType = "None"; >; float4x4 world : World < string UIType = "None"; >; float4x4 worldI : WorldInverse < string UIType = "None"; >; #ifdef _XBOX //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 // input from application struct a2v { float3 position : POSITION; float3 normal : NORMAL; float2 texCoord : TEXCOORD0; #ifdef _XBOX float4 boneIndices : BLENDINDICES; float4 boneWeights : BLENDWEIGHT; #endif }; // output to fragment program struct V2F { float4 position : POSITION; float2 texCoord : TEXCOORD0; float4 worldPosition : TEXCOORD1; float4 worldNormal : TEXCOORD2; }; // Ambient Pass Vertex Shader: V2F av(a2v In) { V2F Out = (V2F)0; float4 position, normal; position = float4(In.position, 1.0f); normal = float4(In.normal, 0.0f); #ifdef _XBOX float BoneWeights[4] = (float[4])In.boneWeights; int BoneIndices[4] = (int[4])In.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); normal = float4(mul( normal, LocalToWorldMatrix ), 0.0f); } //position = matmul(position, worldI); #endif Out.worldPosition = matmul(position, model); //transform vert position to world space Out.worldNormal = matmul(normal, world); //compute world space normal Out.position = matmul(position, wvp); //transform vert position to homogeneous clip space Out.texCoord = In.texCoord; //pass through texture coordinates from channel 1 return Out; } // Ambient Pass Pixel Shader: float4 af(V2F In) : COLOR { float4 TextureMap = tex2D(TextureMapSampler, In.texCoord.xy); float3 diffuseContribution = float3(1.0f, 1.0f, 1.0f); EvaluatePhong_DiffuseOnly(In.worldPosition, In.worldNormal, float3(1.0f, 1.0f, 1.0f), diffuseContribution); float3 lightContribution = TextureMap.rgb * diffuseContribution; return float4(lightContribution, 1.0f); } technique Complete { pass ambient { VertexShader = compile vs_3_0 av( ); ZEnable = true; ZWriteEnable = true; CullMode = CW; ShadeMode = Gouraud; AlphaBlendEnable = FALSE; AlphaTestEnable = FALSE; PixelShader = compile ps_3_0 af(); } }