//=================================================================== // Audience shader with specular front on lighting // @author jboldiga //=================================================================== #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; }; float audienceFalloff : FallOff < string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 100.0f; float UIStep = 0.01f; string UIName = "Falloff Value"; > = 1.0f; float intensity : Intensity < string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 100.0f; float UIStep = 0.01f; string UIName = "Brightness"; > = 1.0f; float audienceVerticalFalloff : VerticalFallOff < string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 100.0f; float UIStep = 0.01f; string UIName = "Vertical Falloff"; > = 0.0f; float audienceVerticalFalloffOffset : VerticalFallOffOffset < string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 100.0f; float UIStep = 0.01f; string UIName = "Vertical Falloff Offset"; > = 1.0f; float audienceGlobalBrightness : GlobalBrightness < string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 100.0f; float UIStep = 0.01f; string UIName = "Global Brightness"; > = 1.0f; float brightnessUpperClamp : BrightnessUpperClamp < string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 100.0f; float UIStep = 0.01f; string UIName = "Brightness Upper Clamp"; > = 1.1f; float brightnessLowerClamp : BrightnessLowerClamp < string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 100.0f; float UIStep = 0.01f; string UIName = "Brightness Lower Clamp"; > = 0.16f; float4 SpecColor < string UIWidget = "Color"; string UIName = "Specular Color"; > = {0.318f, 0.553f, 0.910f, 1.0f}; float SpecPower < string UIWidget = "Slider"; float UIMin = 0.0; float UIMax = 100.0; float UIStep = 0.01; string UIName = "Specular Power"; > = 0.899; float SpecGloss < string UIWidget = "Slider"; float UIMin = 0.0; float UIMax = 100.0; float UIStep = 0.01; string UIName = "Specular Glossiness"; > = 2.75; float SpecFresnel < string UIWidget = "Slider"; float UIMin = 0.0; float UIMax = 100.0; float UIStep = 0.01; string UIName = "Specular Fresnel"; > = 1.84; float FresnelPower < string UIWidget = "Slider"; float UIMin = 0.0; float UIMax = 100.0; float UIStep = 0.01; string UIName = "Specular Fresnel Power"; > = 3.88; float FresnelGloss < string UIWidget = "Slider"; float UIMin = 0.0; float UIMax = 100.0; float UIStep = 0.01; string UIName = "Specular Fresnel Gloss"; > = 2.61; float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; float4x4 model : Model < string UIWidget = "None"; >; float4x4 worldI : WorldInverse < string UIWidget = "None"; >; float4x4 viewInv : ViewInverse < 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; float2 brightness : TEXCOORD1; float3 normal : TEXCOORD2; float3 eyeVec : TEXCOORD3; float3 worldPosition : TEXCOORD4; }; // 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 float4 worldPos = matmul(position, model); //transform vert position to world space Out.position = matmul(position, wvp); //transform vert position to homogeneous clip space float4 osIPos = mattrans(viewInv); // world space eye position float3 osIVec = osIPos.xyz - worldPos.xyz; // world space eye vector Out.eyeVec = osIVec; float3 worldNormal = matmul(normal, model).xyz; Out.texCoord = In.texCoord; //pass through texture coordinates from channel 1 float len = length(worldPos) / 5.0f; intensity = dot(normalize(-worldPos), float4(worldNormal, 0))/len; Out.brightness.x = (clamp((intensity + 0.2f/(len * len * audienceFalloff)) * (audienceVerticalFalloffOffset + audienceVerticalFalloff * position.z), brightnessLowerClamp, brightnessUpperClamp)) * audienceGlobalBrightness; Out.normal = worldNormal; Out.worldPosition = worldPos; return Out; } // Ambient Pass Pixel Shader: float4 af(V2F In) : COLOR { float3 EV = normalize(In.eyeVec); float3 Nws = normalize(In.normal); float3 lightDir = normalize(-In.worldPosition); // origin (0,0,0) - worldPos; assumes origin is the light pos float4 FresnelMask = dot(EV, Nws) * SpecFresnel; float4 FresnelStrength = saturate(1.0f - FresnelMask) * FresnelPower + 1.0f; float4 FresnelGlossiness = FresnelMask * FresnelGloss + 1.0f; float4 Spec = SpecularFrontOn(Nws, EV, lightDir, SpecPower * FresnelStrength, SpecGloss * FresnelGlossiness) * SpecColor; float4 TextureMap = tex2D(TextureMapSampler, In.texCoord.xy); float3 Material = (TextureMap * In.brightness.x).xyz + Spec; return float4 (Material, 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(); } }