Root/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | //----------------------------------------------------------------------------- // AlphaTestEffect.fx // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #include "Macros.fxh" DECLARE_TEXTURE(Texture, 0); BEGIN_CONSTANTS float4 DiffuseColor _vs(c0) _cb(c0); float4 AlphaTest _ps(c0) _cb(c1); float3 FogColor _ps(c1) _cb(c2); float4 FogVector _vs(c5) _cb(c3); MATRIX_CONSTANTS float4x4 WorldViewProj _vs(c1) _cb(c0); END_CONSTANTS #include "Structures.fxh" #include "Common.fxh" // Vertex shader: basic. VSOutputTx VSAlphaTest(VSInputTx vin) { VSOutputTx vout; CommonVSOutput cout = ComputeCommonVSOutput(vin.Position); SetCommonVSOutputParams; vout.TexCoord = vin.TexCoord; return vout; } // Vertex shader: no fog. VSOutputTxNoFog VSAlphaTestNoFog(VSInputTx vin) { VSOutputTxNoFog vout; CommonVSOutput cout = ComputeCommonVSOutput(vin.Position); SetCommonVSOutputParamsNoFog; vout.TexCoord = vin.TexCoord; return vout; } // Vertex shader: vertex color. VSOutputTx VSAlphaTestVc(VSInputTxVc vin) { VSOutputTx vout; CommonVSOutput cout = ComputeCommonVSOutput(vin.Position); SetCommonVSOutputParams; vout.TexCoord = vin.TexCoord; vout.Diffuse *= vin.Color; return vout; } // Vertex shader: vertex color, no fog. VSOutputTxNoFog VSAlphaTestVcNoFog(VSInputTxVc vin) { VSOutputTxNoFog vout; CommonVSOutput cout = ComputeCommonVSOutput(vin.Position); SetCommonVSOutputParamsNoFog; vout.TexCoord = vin.TexCoord; vout.Diffuse *= vin.Color; return vout; } // Pixel shader: less/greater compare function. float4 PSAlphaTestLtGt(PSInputTx pin) : SV_Target0 { float4 color = SAMPLE_TEXTURE(Texture, pin.TexCoord) * pin.Diffuse; clip((color.a < AlphaTest.x) ? AlphaTest.z : AlphaTest.w); ApplyFog(color, pin.Specular.w); return color; } // Pixel shader: less/greater compare function, no fog. float4 PSAlphaTestLtGtNoFog(PSInputTxNoFog pin) : SV_Target0 { float4 color = SAMPLE_TEXTURE(Texture, pin.TexCoord) * pin.Diffuse; clip((color.a < AlphaTest.x) ? AlphaTest.z : AlphaTest.w); return color; } // Pixel shader: equal/notequal compare function. float4 PSAlphaTestEqNe(PSInputTx pin) : SV_Target0 { float4 color = SAMPLE_TEXTURE(Texture, pin.TexCoord) * pin.Diffuse; clip((abs(color.a - AlphaTest.x) < AlphaTest.y) ? AlphaTest.z : AlphaTest.w); ApplyFog(color, pin.Specular.w); return color; } // Pixel shader: equal/notequal compare function, no fog. float4 PSAlphaTestEqNeNoFog(PSInputTxNoFog pin) : SV_Target0 { float4 color = SAMPLE_TEXTURE(Texture, pin.TexCoord) * pin.Diffuse; clip((abs(color.a - AlphaTest.x) < AlphaTest.y) ? AlphaTest.z : AlphaTest.w); return color; } VertexShader VSArray[4] = { compile vs_2_0 VSAlphaTest(), compile vs_2_0 VSAlphaTestNoFog(), compile vs_2_0 VSAlphaTestVc(), compile vs_2_0 VSAlphaTestVcNoFog(), }; int VSIndices[8] = { 0, // lt/gt 1, // lt/gt, no fog 2, // lt/gt, vertex color 3, // lt/gt, vertex color, no fog 0, // eq/ne 1, // eq/ne, no fog 2, // eq/ne, vertex color 3, // eq/ne, vertex color, no fog }; PixelShader PSArray[4] = { compile ps_2_0 PSAlphaTestLtGt(), compile ps_2_0 PSAlphaTestLtGtNoFog(), compile ps_2_0 PSAlphaTestEqNe(), compile ps_2_0 PSAlphaTestEqNeNoFog(), }; int PSIndices[8] = { 0, // lt/gt 1, // lt/gt, no fog 0, // lt/gt, vertex color 1, // lt/gt, vertex color, no fog 2, // eq/ne 3, // eq/ne, no fog 2, // eq/ne, vertex color 3, // eq/ne, vertex color, no fog }; int ShaderIndex = 0; Technique AlphaTestEffect { Pass { VertexShader = (VSArray[VSIndices[ShaderIndex]]); PixelShader = (PSArray[PSIndices[ShaderIndex]]); } } |