/*** Generated through Lumonix shaderFX by: Chris in 3dsmax at: 5/9/2010 3:10:51 AM ***/ // This FX shader was built to support 3ds Max's standard shader compiler. texture HDRDiffuseCube : environment < string Name = "C:\\_project\\ChiliDogs\\Assets\\Characters\\_Common\\HDR_StPeters_Blue_DIF.dds"; string UIName = "HDR Cube Map"; string type = "Cube"; >; samplerCUBE HDRDiffuseCubeSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = CLAMP; AddressV = CLAMP; }; float HDRDiffuseLevel < string UIType = "FloatSpinner"; float UIMin = 0.0; float UIMax = 10.0; float UIStep = 0.1; string UIName = "HDR Cube Map Level"; > = 1.0; texture diffuseTexture :DIFFUSE < string Name = "EUPHBARK.TGA"; string UIName = "Diffuse Map"; string ResourceType = "2D"; >; sampler2D diffuseSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; int texcoord0 : Texcoord < int Texcoord = 0; int MapChannel = 1; string UIType = "None"; >; int texcoord1 : Texcoord < int Texcoord = 1; int MapChannel = 2; string UIType = "None"; >; texture aoTexture < string Name = "d_leaves1.dds"; string UIName = "AO Map"; string ResourceType = "2D"; >; sampler2D aoTextureSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; texture NormalMap : NormalMap < string Name = "C:\\_project\\ChiliDogs\\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 = WRAP; AddressV = WRAP; }; bool SpecMap < string UIType = "slider"; // float UIMin = 0.0; // float UIMax = 1.0; // float UIStep = 1.0; string UIName = "Spec from Normal Alpha?"; > = true; float SpecularLevel < string UIType = "FloatSpinner"; float UIMin = 0.0; float UIMax = 10.0; float UIStep = 0.1; string UIName = "Specular Level"; > = 1.0; float SpecPower < string UIType = "FloatSpinner"; float UIMin = 1.0; float UIMax = 100.0; float UIStep = 0.1; string UIName = "Specular Power"; > = 10.0; bool OpacityLevel < string UIType = "slider"; //float UIMin = 0.0; //float UIMax = 1.0; //float UIStep = 0.01; string UIName = "Opacity Flag"; > = 1; #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); } // 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 : LIGHTCOLOR = { 1.0f, 1.0f, 1.0f, 1.0f}; float4 light1Attenuation : LightAttenuation = { 20.0f, 30.0f, 0.0f, 100.0f}; float light1Hotspot : LightHotSpot = { 43.0f }; float light1Falloff : LightFallOff = { 45.0f }; #define light1Type 1 #define light1attenType 0 #define light1coneType 0 #define light1CastShadows false bool BackgroundFlag < string UIType = "slider"; string UIName = "Outer Arena Object Flag"; > = true; //---------------------------------- 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, float3x3 objTangentXf, int lightType) { float3 lightVec = mul(objTangentXf, (mul((lightVector - worldSpacePos), worldI).xyz)); return lightVec; } // input from application struct a2v { float4 position : POSITION; float2 texCoord : TEXCOORD0; float2 texCoord1 : TEXCOORD1; float4 tangent : TANGENT; float4 binormal : BINORMAL; float4 normal : NORMAL; //float2 texCoord : TEXCOORD0; //float2 texCoordAo : TEXCOORD1; }; // output to fragment program struct v2f { float4 position : POSITION; float3 worldNormal : TEXCOORD0; float2 texCoord : TEXCOORD1; float2 texCoord1 : TEXCOORD2; float3 lightVec : TEXCOORD3; float3 eyeVec : TEXCOORD4; float3 worldTangent : TEXCOORD5; float3 worldBinormal : TEXCOORD6; //float2 texCoord : TEXCOORD7; //float2 texCoordAo : TEXCOORD8; }; //Vertex Shader v2f av(a2v In, uniform float3 light1Pos, uniform int lightType) { v2f Out = (v2f)0; float3x3 objTangentXf; //build object to tangent space transform matrix #ifdef YUP objTangentXf[0] = In.tangent.xyz; objTangentXf[1] = -In.binormal.xyz; #else objTangentXf[0] = In.binormal.xyz; objTangentXf[1] = -In.tangent.xyz; #endif objTangentXf[2] = In.normal.xyz; float3 worldSpacePos = mul(In.position, world).xyz; //world space position Out.lightVec = lightVec_func(worldSpacePos, light1Pos,objTangentXf, light1Type); In.texCoord += float2(0.0,1.0); //this fixes Max's V texcoord which is off by one Out.texCoord = In.texCoord; //pass through texture coordinates from channel 1 In.texCoord1 += float2(0.0,1.0); //this fixes Max's V texcoord which is off by one Out.texCoord1 = In.texCoord1; //pass through texture coordinates from channel 2 float4 osIPos = mul(viewInv[3], worldI); //put world space eye position in object space float3 osIVec = osIPos.xyz - In.position.xyz; //object space eye vector Out.eyeVec = mul(objTangentXf, osIVec); //tangent space eye vector passed out Out.position = mul(In.position, wvp); //transform vert position to homogeneous clip space Out.worldNormal = mul(In.normal, worldIT).xyz; //compute world space normal Out.worldBinormal = mul(In.binormal, worldIT).xyz; //compute world space binormal Out.worldTangent = mul(In.tangent, worldIT).xyz; //compute world space tangent return Out; } //Pixel Shader float4 af(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, uniform int shadowPassCount) : COLOR { float3 V = normalize(In.eyeVec); //creating the eye vector float4 NormalMap = tex2D(NormalMapSampler, In.texCoord.xy); if (BackgroundFlag == 1) { NormalMap = float4 (0.5,0.5,1,1); } NormalMap.xyz = NormalMap.xyz * 2 - 1; //expand to -1 to 1 range NormalMap.rgb = normalize(NormalMap.rgb); float3 N = NormalMap.rgb; 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); float3 MathWorldXform_Rotate = ( Nn * NormalMap.rgb.z ) + (NormalMap.rgb.x * Tn ) + ( NormalMap.rgb.y * -Bn); float4 diffuseTex = tex2D(diffuseSampler, In.texCoord.xy); float4 aoTex = tex2D(aoTextureSampler, In.texCoord1.xy); float RX = -90.0; float RY = 0.0; float RZ = 0.0; float3 RotFix = rotate_vector(RX, RY, RZ,MathWorldXform_Rotate); float4 DiffuseCubeMap = texCUBE(HDRDiffuseCubeSampler, RotFix.xyz); float3 DiffuseHDR_Level = HDRDiffuseLevel * DiffuseCubeMap.rgb; float3 Diffuse_HDRDiffuse = (diffuseTex.rgb * DiffuseHDR_Level * aoTex.rgb * 0.5); float3 MathVecConstuct_964 = float3(NormalMap.a, NormalMap.a, NormalMap.a); float3 Lerp_NaSpec = lerp(diffuseTex.rgb, MathVecConstuct_964, SpecMap); float3 NormalA_SpecLevel = Lerp_NaSpec * SpecularLevel; float3 NaSpec_HDRDiffuse = NormalA_SpecLevel * DiffuseHDR_Level; float3 specular = NaSpec_HDRDiffuse; float glossiness = SpecPower/2; float3 L = normalize(In.lightVec.xyz); float3 NdotL = dot(N, L) ; float3 DiffuseLighting = saturate(NdotL); float3 H = normalize(L + V); float NdotH = saturate(dot(N,H)); //Compute NdotH1 float3 MaterialSpecular = pow(NdotH, glossiness) * specular; //Raise to glossiness power and compute final specular color //float3 Material = ((DiffuseLighting))+ (diffuseTex.rgb + DiffuseHDR_Level); // * ((aoTex+0.5))); //float3 Material = ((MaterialSpecular))+ (diffuseTex.rgb * DiffuseHDR_Level); // * ((aoTex+0.5))); float3 Material = ((DiffuseLighting+1)*0.25)+ (diffuseTex.rgb * Diffuse_HDRDiffuse * ((aoTex*2))); Material *=MaterialSpecular; //Material *=DiffuseLighting; Material +=Diffuse_HDRDiffuse; float3 AlphaTest =(diffuseTex.a,diffuseTex.a,diffuseTex.a); float4 ret = float4(0,0,0,1); ret =float4 (Material, pow(diffuseTex.a,0.1) + OpacityLevel); return ret; } technique Complete { pass ambient { VertexShader = compile vs_2_0 av(light1Pos, light1Type); ZEnable = true; ZWriteEnable = true; CullMode = cw; ShadeMode = Gouraud; AlphaBlendEnable = true; AlphaTestEnable = true; PixelShader = compile ps_2_0 af(light1Dir, light1Color, light1Attenuation, light1Hotspot, light1Falloff, light1Type, light1attenType, light1coneType, light1CastShadows, 1); } }