//=================================================================== // Light Beam // @author jboldiga // Simulate a beam of light. //=================================================================== #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 // globals float4 EmissiveColor < string UIName = "Emissive Color"; string UIWidget = "Color"; > = {1.0f, 1.0f, 1.0f, 1.0f}; float Brightness < string UIWidget = "slider"; string UIName = "Opacity"; float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.025; > = 1.0f; texture falloffTexture : Diffuse < string Name = "EUPHBARK.TGA"; string UIName = "Falloff Map"; string ResourceType = "2D"; >; sampler2D falloffSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; texture falloffTexture2 : Diffuse < string Name = "EUPHBARK.TGA"; string UIName = "Underneath Falloff Map"; string ResourceType = "2D"; >; sampler2D falloffSampler2 = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = CLAMP; AddressV = CLAMP; }; // matrices float4x4 wvp : WorldViewProjection < string UIType = "None"; >; float4x4 worldIT : WorldInverseTranspose < string UIType = "None"; >; float4x4 viewinverse : ViewInverse < string UIType = "None"; >; float4x4 view : View < string UIType = "None"; >; float4x4 world : World < string UIType = "None"; >; // input from application struct a2v { float4 position : POSITION; float4 normal : NORMAL; float2 texCoord0 : TEXCOORD0; }; // output to fragment program struct v2f { float4 position : POSITION; float2 texCoord0 : TEXCOORD0; float3 worldNormal : TEXCOORD1; float3 eyeVec : TEXCOORD2; }; //Vertex Shader v2f av(a2v In) { v2f Out = (v2f)0; Out.texCoord0 = In.texCoord0; //pass through texture coordinates #ifdef _MAX_ Out.texCoord0.x += 1; Out.texCoord0.y += 1; #endif float3 worldSpacePos = matmul(In.position, world).xyz; //world space position float4 osIPos = mattrans(viewinverse); // world space eye position float3 osIVec = osIPos.xyz - worldSpacePos; // world space eye vector Out.eyeVec = osIVec; Out.position = matmul(In.position, wvp); //transform vert position to homogeneous clip space Out.worldNormal = matmul(In.normal, worldIT).xyz; //compute world space normal Out.eyeVec = matmul(float4(Out.eyeVec, 0.0f), view).xyz; Out.worldNormal = matmul(float4(Out.worldNormal, 0.0f), view).xyz; return Out; } //Pixel Shader float4 af(v2f In) : COLOR { float3 V = normalize(In.eyeVec); float3 Nn = normalize(In.worldNormal); float2 uvs = In.texCoord0; // calculate reflection vector float3 reflection = reflect(Nn, V); // calculate UV's for first falloff uvs.x = reflection.x * 0.5f + 0.5f; float falloff = tex2D(falloffSampler, uvs).g; // calculate UV's for second falloff uvs = reflection.xy * 0.5f + 0.5f; float falloff2 = tex2D(falloffSampler, uvs).r; return float4(EmissiveColor.rgb * Brightness, falloff * falloff2); } technique Complete { pass ambient { VertexShader = compile vs_3_0 av(); ZEnable = true; ZWriteEnable = false; CullMode = none; ShadeMode = Gouraud; AlphaBlendEnable = true; AlphaTestEnable = false; SrcBlend = SRCALPHA; DestBlend = ONE; PixelShader = compile ps_3_0 af(); } }