/*** Generated through Lumonix shaderFX by: scott in 3dsmax at: 11/12/2009 4:33:56 PM ***/ // This FX shader was built to support 3ds Max's standard shader compiler. #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 texture DiffuseMap : DiffuseMap < string ResourceName = "C:\\_project\\Fatburger\\Assets\\Characters\\_Common\\Common_Glove_DaS.dds"; string UIName = "Diffuse Map"; string ResourceType = "2D"; >; sampler2D DiffuseMapSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; float HDRDiffuseLevel < string UIType = "FloatSpinner"; float UIMin = 0.0; float UIMax = 10.0; float UIStep = 0.1; string UIName = "HDR Diffuse Level"; > = 1.0; texture NormalMap : NormalMap < string ResourceName = "C:\\_project\\Fatburger\\Assets\\Characters\\_Common\\Common_flat_N.dds"; string UIName = "Normal Map"; string ResourceType = "2D"; >; sampler2D NormalMapSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = CLAMP; AddressV = CLAMP; }; #define M_PI 3.14158 float3 rotate_vector(float RX, float RY, float RZ, float3 v) { float heading = RY*M_PI/180; float bank = RX*M_PI/180; float attitude = RZ*M_PI/180; float3x3 m; float ch = cos(heading); float sh = sin(heading); float ca = cos(attitude); float sa = sin(attitude); float cb = cos(bank); float sb = sin(bank); m[0][0] = ch * ca; m[0][1] = sh*sb - ch*sa*cb; m[0][2] = ch*sa*sb + sh*cb; m[1][0] = sa; m[1][1] = ca*cb; m[1][2] = -ca*sb; m[2][0] = -sh*ca; m[2][1] = sh*sa*cb + ch*sb; m[2][2] = -sh*sa*sb + ch*cb; return mul(m,v); } texture HDRDiffuseCube : environment < string ResourceName = "C:\\_project\\Fatburger\\Assets\\Characters\\_Common\\HDR_RG_Fight_D.dds"; string UIName = "HDR Diffuse Cube"; string type = "Cube"; >; samplerCUBE HDRDiffuseCubeSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = CLAMP; AddressV = CLAMP; }; float SpecularLevelBase < string UIType = "FloatSpinner"; float UIMin = 0.0; float UIMax = 10.0; float UIStep = 0.1; string UIName = "Specular Level Base"; > = 2.0; float SpecularPowerBase < string UIType = "FloatSpinner"; float UIMin = 1.0; float UIMax = 1000.0; float UIStep = 1.0; string UIName = "Specular Power Base"; > = 43.0; // this function does the different types of light attenuation float attenuation_func(int lightattenType, float4 lightAttenuation, float3 lightVec) { float att = 1.0; return att; } // this function does the different types of cone angle float coneangle_func(int lightconeType, float lightHotspot, float lightFalloff, float3 lightVec, float3 lightDir) { float cone = 1.0; return cone; } /************** light info **************/ float3 light1Dir : Direction < string UIName = "Light 1 Direction"; string Object = "TargetLight"; string Space = "World"; int refID = 1; > = {100.0f, 100.0f, 100.0f}; float3 light1Pos : POSITION < string UIName = "Light 1 Position"; string Object = "PointLight"; string Space = "World"; int refID = 1; > = {100.0f, 100.0f, 100.0f}; float4 light1Color : Diffuse = { 1.0f, 1.0f, 1.0f, 1.0f}; float4 light1Attenuation : Attenuation = { 1.0f, 1.0f, 1.0f, 1.0f}; float light1Hotspot : HotSpot < string UIType = "FloatSpinner"; float UIMin = 0.0f; float UIMax = 90.0f; float UIStep = 0.01f; string UIName = "Hot Spot Value"; > = 43.0f; float light1Falloff : FallOff < string UIType = "FloatSpinner"; float UIMin = 0.0f; float UIMax = 90.0f; float UIStep = 0.01f; string UIName = "Falloff Value"; > = 45.0f; #define light1Type 1 #define light1attenType 0 #define light1coneType 0 #define light1CastShadows false //---------------------------------- float4x4 wvp : WorldViewProjection < string UIType = "None"; >; float4x4 worldI : WorldInverse < string UIType = "None"; >; float4x4 worldIT : WorldInverseTranspose < string UIType = "None"; >; float4x4 viewInv : ViewInverse < string UIType = "None"; >; float4x4 world : World < string UIType = "None"; >; // create the light vector float3 lightVec_func(float3 worldSpacePos, float3 lightVector, int lightType) { float3 lightVec = lightVector - worldSpacePos; return lightVec; } // input from application struct a2v { float4 position : POSITION; float2 texCoord : TEXCOORD0; float4 tangent : TANGENT; float4 binormal : BINORMAL; float4 normal : NORMAL; }; // output to fragment program struct v2f { float4 position : POSITION; float3 light1Vec : TEXCOORD0; float3 eyeVec : TEXCOORD1; float2 texCoord : TEXCOORD2; float3 worldTangent : TEXCOORD3; float3 worldBinormal : TEXCOORD4; float3 worldNormal : TEXCOORD5; }; //Vertex Shader v2f v(a2v In, uniform float3 lightPos, uniform int lightType, uniform float3 lightDir) { v2f Out = (v2f)0; float3 worldSpacePos = matmul(In.position, world).xyz; //world space position Out.light1Vec = lightVec_func(worldSpacePos, light1Pos, light1Type); Out.eyeVec = viewInv[3] - worldSpacePos; //eye vector in world space Out.position = matmul(In.position, wvp); //transform vert position to homogeneous clip space In.texCoord.y += 1.0f; //this fixes Max's V texcoord which is off by one Out.texCoord = In.texCoord; //pass through texture coordinates from channel 1 //this code was added by the Texture Map Node Out.worldNormal = matmul(In.normal, worldIT).xyz; //compute world space normal Out.worldBinormal = matmul(In.binormal, worldIT).xyz; //compute world space binormal Out.worldTangent = matmul(In.tangent, worldIT).xyz; //compute world space tangent return Out; } //Pixel Shader float4 f(v2f In, uniform float3 lightDir, uniform float4 lightColor, uniform float4 lightAttenuation, uniform float lightHotspot, uniform float lightFalloff, uniform int lightType, uniform int lightattenType, uniform int lightconeType, uniform bool lightCastShadows) : COLOR { float3 V = normalize(In.eyeVec); //creating the eye vector float4 DiffuseMap = tex2D(DiffuseMapSampler, In.texCoord.xy); float4 NormalMap = tex2D(NormalMapSampler, In.texCoord.xy); NormalMap.xyz = NormalMap.xyz * 2 - 1; //expand to -1 to 1 range //this code was added by the Tex2d Node float3 Nn = normalize(In.worldNormal); //input the vectors required for tangent to world space transform float3 Tn = normalize(In.worldTangent); float3 Bn = normalize(In.worldBinormal); NormalMap = float4((Nn * NormalMap.z) + (NormalMap.x * Tn + NormalMap.y * -Bn), NormalMap.w); //create a per-pixel normal for Y up NormalMap.rgb = normalize(NormalMap.rgb); //normalized the normal vector float3 MathWorldXform_Rotate = NormalMap.rgb; float RX = -90.0; float RY = 0.0; float RZ = 0.0; float3 CustomCode_1882 = rotate_vector(RX, RY, RZ,MathWorldXform_Rotate); float4 DiffuseCubeMap = texCUBE(HDRDiffuseCubeSampler, CustomCode_1882.xyz); float3 DiffuseHDR_Level = HDRDiffuseLevel * DiffuseCubeMap.rgb; float3 Diffuse_HDRDiffuse = DiffuseMap.rgb * DiffuseHDR_Level; float3 input1 = Diffuse_HDRDiffuse; float3 DiffuseOFF = float3(0.0f, 0.0f, 0.0f ); float3 input2 = DiffuseOFF.rgb; float3 Diffuse_SpecLevel = Diffuse_HDRDiffuse * SpecularLevelBase; float3 input3 = Diffuse_SpecLevel; float input5 = SpecularPowerBase; float3 input8 = NormalMap.rgb; float3 ret = float3(0,0,0); float3 AmbIllum = input1; ret = AmbIllum; float3 diffuseColor = input2; float3 N = input8; //using the Normal socket float3 spec = float3(0,0,0); float3 specularColor = input3; //using the Specular Color socket float glossiness = input5; //using the Glossiness socket float3 L1 = normalize(In.light1Vec.xyz); float3 light1 = float3(0.0, 0.0, 0.0); float3 NdotL1 = dot(N, L1) ; float3 diffuse1 = saturate(NdotL1); float3 H1 = V;//normalize(L1 + V); float NdotH1 = saturate(dot(N,H1)); //Compute NdotH1 float3 specularColor1 = pow(NdotH1, glossiness) * specularColor;//Raise to glossiness power and compute final specular color light1 += specularColor1 + (diffuseColor * diffuse1); //add specular and diffuse color together light1 *= light1Color.xyz; float3 light1Dir = -light1Dir; //use the light direction from the light header information float attenuation1 = attenuation_func(light1attenType, light1Attenuation, In.light1Vec); //calculate the light attenuation float coneangle1 = coneangle_func(light1coneType, light1Hotspot, light1Falloff, In.light1Vec, light1Dir); //calculate the light's cone angle light1 *= attenuation1 * coneangle1; //multiply by the light decay ret += light1; float4 done = float4(ret, 1); return done; } technique Complete { pass one { VertexShader = compile vs_3_0 v(light1Pos, light1Type, light1Dir); ZEnable = true; ZWriteEnable = true; CullMode = cw; ShadeMode = Gouraud; AlphaBlendEnable = false; AlphaTestEnable = FALSE; PixelShader = compile ps_3_0 f(-light1Dir, light1Color, light1Attenuation, light1Hotspot, light1Falloff, light1Type, light1attenType, light1coneType, light1CastShadows); } }