//=================================================================== // 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 lightMapTexture < string Name = "d_leaves1.dds"; string UIName = "LightMap and AO"; string ResourceType = "2D"; >; sampler2D lightMapSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; texture contactShadowTexture < string Name = "d_leaves1.dds"; string UIName = "Contact Shadow Map"; string ResourceType = "2D"; >; sampler2D contactShadowSampler = 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"; >; int texcoord2 : Texcoord < int Texcoord = 2; int MapChannel = 3; string UIType = "None"; >; #endif float4 CSMask < string UIWidget = "Color"; string UIName = "Contact Shadow Mask"; > = {1.0f, 0.0f, 0.0f, 0.0f}; float3 AmbientColor : Ambient < string UIName = "Ambient Light"; string UIWidget = "Color"; > = {0.0f,0.0f,0.0f}; float LowExposure < string UIWidget = "slider"; string UIName = "Low Exposure"; float UIMin = -100.0; float UIMax = 0.0; float UIStep = 0.5; > = -2.0; float HighExposure < string UIWidget = "slider"; string UIName = "High Exposure"; float UIMin = 0.0; float UIMax = 100.0; float UIStep = 0.5; > = 2.0; float Threshold < string UIWidget = "slider"; string UIName = "Threshold"; float UIMin = 0.0; float UIMax = 100.0; float UIStep = 0.1; > = 50.0f; // matrices float4x4 wvp : WorldViewProjection < string UIType = "None"; >; // input from application struct a2v { float4 position : POSITION; float2 texCoord0 : TEXCOORD0; float2 texCoord1 : TEXCOORD1; float2 texCoord2 : TEXCOORD2; }; // output to fragment program struct v2f { float4 position : POSITION; float2 texCoord0 : TEXCOORD0; float4 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.xy = In.texCoord1; //pass through texture coordinates from channel 2 into xy Out.texCoord1.zw = In.texCoord2; //pass through texture coordinates from channel 3 into zw 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 lightMapTex = tex2D(lightMapSampler, In.texCoord1.xy); float4 contactShadowMap = tex2D(contactShadowSampler, In.texCoord1.zw); float contactShadow = contactShadowMap * CSMask; float3 lightMapHDR = CalculateLightMapHDR(lightMapTex.rgb, LowExposure, HighExposure, Threshold); // aoLightMap contains the LightMap in the RGB channels float3 diffuseContribution = lightMapHDR.rgb; float3 ambientContribution = AmbientColor; float3 Material = ((ambientContribution + diffuseContribution) * diffuseTex.rgb) * contactShadow; 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(); } }