//=================================================================== // Environment Diffuse Normal Specular LightMap Ambient Occlusion Shader // @author jboldiga // No dynamic lighting. Uses HDR lightmaps and fake specular lighting //=================================================================== #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 diffuseTexture : Diffuse < string Name = "EUPHBARK.TGA"; string UIName = "Diffuse Map"; string ResourceType = "2D"; >; sampler2D diffuseTextureSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; texture lightMapAOTexture < string Name = "d_leaves1.dds"; string UIName = "LightMap and AO"; string ResourceType = "2D"; >; sampler2D lightMapAOSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; #ifdef _MAX_ // this is so that in max the channels match correctly int texcoord0 : Texcoord < int Texcoord = 0; int MapChannel = 1; string UIType = "None"; >; int texcoord1 : Texcoord < int Texcoord = 1; int MapChannel = 2; string UIType = "None"; >; #endif float3 AmbientColor : Ambient < string UIName = "Ambient Light"; string UIWidget = "Color"; > = {1.0f, 1.0f, 1.0f}; float AODiffuseBlend < float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.1; string UIName = "AO Influence"; > = 0.5f; // matrices float4x4 wvp : WorldViewProjection < string UIType = "None"; >; // input from application struct a2v { float4 position : POSITION; float2 texCoord0 : TEXCOORD0; float2 texCoord1 : TEXCOORD1; }; // output to fragment program struct v2f { float4 position : POSITION; float2 texCoord0 : TEXCOORD0; float2 texCoord1 : TEXCOORD1; }; //Vertex Shader v2f av(a2v In) { v2f Out = (v2f)0; Out.texCoord0 = In.texCoord0; //pass through texture coordinates from channel 1 Out.texCoord1 = In.texCoord1; //pass through texture coordinates from channel 2 Out.position = matmul(In.position, wvp); //transform vert position to homogeneous clip space return Out; } //Pixel Shader float4 af(v2f In) : COLOR { float4 diffuseTex = tex2D(diffuseTextureSampler, In.texCoord0.xy); float4 lightMapAOTex = tex2D(lightMapAOSampler, In.texCoord1.xy); // aoLightMap contains the LightMap in the RGB channels and the AO map in the A channel float3 diffuseContribution = lightMapAOTex.rgb; float3 ambientContribution = AmbientColor * lightMapAOTex.a; float3 Material = (ambientContribution * diffuseTex.rgb) + ((diffuseContribution * diffuseTex.rgb) * saturate(lerp(1.0, lightMapAOTex.a, AODiffuseBlend))); 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(); } }