//=================================================================== // Fence shader that only takes a material color // @author jboldiga //=================================================================== #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 float3 AmbientColor : Ambient < string UIName = "Material Color"; string UIWidget = "Color"; > = {1.0f,1.0f,1.0f}; float OpacityLevel < string UIType = "FloatSpinner"; float UIMin = -999999.0; float UIMax = 999999.0; float UIStep = 0.1; string UIName = "Opacity Level"; > = 1.0; float PixelDepthPower < string UIType = "FloatSpinner"; float UIMin = -99999.0; float UIMax = 99999.0; float UIStep = 1.0; string UIName = "PixelDepthPower"; > = -128.0; float MinOpacityLevel < string UIType = "FloatSpinner"; float UIMin = -999999.0; float UIMax = 999999.0; float UIStep = 0.001; string UIName = "Min Opacity Level"; > = 0.01; 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; }; // matrices float4x4 wvp : WorldViewProjection < string UIType = "None"; >; // input from application struct a2v { float4 position : POSITION; float2 texCoord : TEXCOORD0; }; // output to fragment program struct v2f { float4 position : POSITION; float2 texCoord : TEXCOORD1; float2 pixelDepth : TEXCOORD0; }; //Vertex Shader v2f av(a2v In) { v2f Out = (v2f)0; Out.texCoord = In.texCoord; //pass through texture coordinates from channel 1 Out.position = matmul(In.position, wvp); //transform vert position to homogeneous clip space Out.pixelDepth.xy = Out.position.zw; //take Z and W component from clip space vertex position return Out; } //Pixel Shader float4 af(v2f In) : COLOR { float3 Material = AmbientColor; float4 diffuseTex = tex2D(diffuseTextureSampler, In.texCoord.xy); Material = diffuseTex.rgb * AmbientColor; //------------------------------------------------------------------------------------------------------------------------ // OPACITY CODE SNIPPET. Function: Does a pixel-based alpha fade on objects of interest, so Camera can see our fighters. // Details: game sets opacity parameter to NOT = 1.0f. This triggers pixel-based fading. //------------------------------------------------------------------------------------------------------------------------- float final_opacity; if (OpacityLevel >= 0.999f) // jboldiga - for precision... final_opacity = 1.0f; // don't fade if calling code sets param to 1.0f. else { #ifdef _XBOX float distanceMod = 0.05f; // 360 needs own value #else float distanceMod = 0.005; // used El Matador as test level for tweaking btw #endif //float distanceMod = 0.005; // this "works" For el matador. was 0.000005 float pixelDepth = (In.pixelDepth.x / In.pixelDepth.y); // divide Z and W from clip space vertex pos, to get depth per pixel if (pixelDepth < 0.0f) pixelDepth = 0.00001f; float pixelPower = pow(pixelDepth, PixelDepthPower); // opt this math float a = pixelPower * distanceMod; a = clamp(a, 0, 1); float pixel_alpha = 1.0f - a; //Subtract the input from one final_opacity = clamp(pixel_alpha, MinOpacityLevel, 1.0f); //used at END of program.. } //------------------------------------------ END OPACITY CODE SNIPPET ----------------------------------------------------- return float4(Material, final_opacity); } technique Complete { pass ambient { VertexShader = compile vs_3_0 av(); ZEnable = true; ZWriteEnable = true; CullMode = cw; ShadeMode = Gouraud; AlphaBlendEnable = true; AlphaTestEnable = false; PixelShader = compile ps_3_0 af(); } }