0001:
0002:
0003:
0004:
0005:
0006:
0007:
0008:
0009:
0010: float4x4 mWVP;
0011:
0012:
0013:
0014:
0015: texture DecaleMap;
0016: sampler DecaleSamp = sampler_state
0017: {
0018: Texture = <DecaleMap>;
0019: MinFilter = LINEAR;
0020: MagFilter = LINEAR;
0021: MipFilter = NONE;
0022:
0023: AddressU = Clamp;
0024: AddressV = Clamp;
0025: };
0026:
0027: texture DepthMap;
0028: sampler DepthSamp = sampler_state
0029: {
0030: Texture = <DepthMap>;
0031: MinFilter = POINT;
0032: MagFilter = POINT;
0033: MipFilter = NONE;
0034:
0035: AddressU = Clamp;
0036: AddressV = Clamp;
0037: };
0038:
0039: texture ColorMap;
0040: sampler ColorSamp = sampler_state
0041: {
0042: Texture = <ColorMap>;
0043: MinFilter = POINT;
0044: MagFilter = POINT;
0045: MipFilter = NONE;
0046:
0047: AddressU = Clamp;
0048: AddressV = Clamp;
0049: };
0050:
0051:
0052:
0053:
0054:
0055:
0056:
0057:
0058:
0059:
0060: struct VS_OUTPUT
0061: {
0062: float4 Position : POSITION;
0063: float2 Tex : TEXCOORD0;
0064: float4 Pos : TEXCOORD1;
0065: };
0066:
0067:
0068:
0069: VS_OUTPUT VS (
0070: float4 Pos : POSITION
0071: ,float4 Tex : TEXCOORD0
0072: ){
0073: VS_OUTPUT Out = (VS_OUTPUT)0;
0074:
0075:
0076: Out.Pos = Out.Position = mul( Pos, mWVP );
0077:
0078: Out.Tex = Tex;
0079:
0080: return Out;
0081: }
0082:
0083:
0084:
0085: struct PS_OUTPUT {
0086: float4 Color : COLOR0;
0087: float4 Depth : COLOR1;
0088: };
0089:
0090:
0091:
0092: PS_OUTPUT PS ( VS_OUTPUT In ) {
0093:
0094: PS_OUTPUT Out = ( PS_OUTPUT ) 0;
0095:
0096:
0097: Out.Color = tex2D( DecaleSamp, In.Tex );
0098:
0099:
0100: float depth = In.Pos.z / In.Pos.w;
0101: Out.Depth.x = depth;
0102: Out.Depth.y = depth * 256.0;
0103: Out.Depth.z = depth * 256.0f * 256.0f;
0104: Out.Depth.w = 0.0f;
0105: Out.Depth = frac(Out.Depth);
0106:
0107: return Out;
0108: }
0109:
0110:
0111:
0112:
0113:
0114:
0115:
0116:
0117:
0118:
0119: struct PS_OUTPUT_Mapping {
0120: float4 Color : COLOR0;
0121: float Depth : DEPTH;
0122: };
0123:
0124:
0125:
0126: PS_OUTPUT_Mapping psMapping ( float4 Tex : TEXCOORD0 ) {
0127:
0128: PS_OUTPUT_Mapping Out = ( PS_OUTPUT_Mapping ) 0;
0129:
0130:
0131: Out.Color = tex2D( ColorSamp, Tex );
0132:
0133:
0134: float4 depth = tex2D( DepthSamp, Tex );
0135: Out.Depth = depth.x
0136: + depth.y / 256.0f
0137: + depth.z / (256.0f*256.0f);
0138:
0139: return Out;
0140: }
0141:
0142:
0143:
0144:
0145:
0146: technique TShader
0147: {
0148: pass P0
0149: {
0150: VertexShader = compile vs_1_1 VS();
0151: PixelShader = compile ps_2_0 PS();
0152:
0153: Sampler[0] = (DecaleSamp);
0154: }
0155: pass P1
0156: {
0157: PixelShader = compile ps_2_0 psMapping();
0158: }
0159: }
0160: