0001:
0002:
0003:
0004:
0005:
0006:
0007:
0008:
0009:
0010: float4x4 mWVP;
0011: float4x4 mWVPT;
0012: float4 vLightDir;
0013: float4 vCol;
0014:
0015:
0016:
0017:
0018: texture DecaleMap;
0019: sampler DecaleMapSamp = sampler_state
0020: {
0021: Texture = <DecaleMap>;
0022: MinFilter = LINEAR;
0023: MagFilter = LINEAR;
0024: MipFilter = NONE;
0025:
0026: AddressU = Clamp;
0027: AddressV = Clamp;
0028: };
0029:
0030:
0031:
0032:
0033:
0034:
0035:
0036:
0037:
0038:
0039:
0040: struct VS_OUTPUT
0041: {
0042: float4 Pos : POSITION;
0043: float4 Col : COLOR0;
0044: float2 Tex : TEXCOORD0;
0045: float2 Depth : TEXCOORD1;
0046: };
0047:
0048:
0049:
0050:
0051: VS_OUTPUT VS (
0052: float4 Pos : POSITION
0053: , float4 Normal : NORMAL
0054: , float4 Tex : TEXCOORD0
0055: ){
0056: VS_OUTPUT Out = (VS_OUTPUT)0;
0057:
0058:
0059: float4 pos = mul( Pos, mWVP );
0060:
0061:
0062: Out.Pos = pos;
0063:
0064:
0065: Out.Col = vCol * max( dot(vLightDir, Normal), 0);
0066:
0067:
0068: Out.Tex = Tex;
0069:
0070:
0071: Out.Depth = pos.z / pos.w;
0072:
0073: return Out;
0074: }
0075:
0076:
0077:
0078: struct PS_OUTPUT {
0079: float4 Color : COLOR0;
0080: float4 Depth : COLOR1;
0081: };
0082:
0083:
0084:
0085: PS_OUTPUT PS ( VS_OUTPUT In ) {
0086:
0087: PS_OUTPUT Out = ( PS_OUTPUT ) 0;
0088:
0089:
0090: Out.Color = In.Col * tex2D( DecaleMapSamp, In.Tex );
0091:
0092:
0093: Out.Depth.x = In.Depth;
0094:
0095: return Out;
0096: }
0097:
0098:
0099:
0100:
0101: technique TShader
0102: {
0103: pass P0
0104: {
0105:
0106: VertexShader = compile vs_1_1 VS();
0107: PixelShader = compile ps_2_0 PS();
0108:
0109: Sampler[0] = (DecaleMapSamp);
0110: }
0111: }
0112:
0113:
0114:
0115:
0116:
0117:
0118:
0119:
0120:
0121:
0122:
0123: texture DepthMap;
0124: sampler DepthMapSamp = sampler_state
0125: {
0126: Texture = <DepthMap>;
0127: MinFilter = LINEAR;
0128: MagFilter = LINEAR;
0129: MipFilter = NONE;
0130:
0131: AddressU = Clamp;
0132: AddressV = Clamp;
0133: };
0134:
0135: texture FrameBuffer;
0136: sampler FrameBufferSamp = sampler_state
0137: {
0138: Texture = <FrameBuffer>;
0139: MinFilter = POINT;
0140: MagFilter = POINT;
0141: MipFilter = NONE;
0142:
0143: AddressU = Clamp;
0144: AddressV = Clamp;
0145: };
0146:
0147:
0148:
0149: struct VS_OUTPUT_VOLUME
0150: {
0151: float4 Pos : POSITION;
0152: float4 Depth : COLOR0;
0153: float4 Tex : TEXCOORD0;
0154: };
0155:
0156:
0157:
0158: VS_OUTPUT_VOLUME VS_VOLUME (
0159: float4 Pos : POSITION
0160: , float4 Tex : TEXCOORD0
0161: ){
0162: VS_OUTPUT_VOLUME Out = (VS_OUTPUT_VOLUME)0;
0163:
0164:
0165: float4 pos = mul( Pos, mWVP );
0166:
0167:
0168: Out.Pos = pos;
0169:
0170:
0171: Out.Depth = pos.z / pos.w;
0172:
0173:
0174: Out.Tex = mul(Pos, mWVPT);
0175:
0176: return Out;
0177: }
0178:
0179:
0180:
0181: float4 PS_VOLUME1( VS_OUTPUT_VOLUME In) : COLOR
0182: {
0183: float depth_map = tex2Dproj( DepthMapSamp, In.Tex ).x;
0184: float frame_buffer = tex2Dproj( FrameBufferSamp, In.Tex ).x;
0185: float diff = 20.0f*(In.Depth.x - depth_map);
0186:
0187: return frame_buffer - ((0 < diff) ? 0 : diff);
0188: }
0189:
0190:
0191:
0192:
0193: float4 PS_VOLUME2 ( VS_OUTPUT_VOLUME In) : COLOR
0194: {
0195: float depth_map = tex2Dproj( DepthMapSamp, In.Tex ).x;
0196: float frame_buffer = tex2Dproj( FrameBufferSamp, In.Tex ).x;
0197: float diff = 20.0f*(In.Depth.x - depth_map);
0198:
0199: return frame_buffer + ((0 < diff) ? 0 : diff);
0200: }
0201:
0202:
0203:
0204:
0205: technique TVolume
0206: {
0207: pass P0
0208: {
0209: Sampler[0] = (DepthMapSamp);
0210: Sampler[1] = (FrameBufferSamp);
0211:
0212:
0213: CullMode = CCW;
0214: Zenable = False;
0215:
0216:
0217: VertexShader = compile vs_1_1 VS_VOLUME ();
0218: PixelShader = compile ps_2_0 PS_VOLUME1();
0219:
0220: }
0221: pass P1
0222: {
0223: Sampler[0] = (DepthMapSamp);
0224: Sampler[1] = (FrameBufferSamp);
0225:
0226:
0227: CullMode = CW;
0228: Zenable = False;
0229:
0230:
0231: VertexShader = compile vs_1_1 VS_VOLUME ();
0232: PixelShader = compile ps_2_0 PS_VOLUME2();
0233: }
0234: }
0235:
0236:
0237:
0238:
0239:
0240:
0241:
0242:
0243:
0244:
0245: texture FogMap;
0246: sampler FogMapSamp = sampler_state
0247: {
0248: Texture = <FogMap>;
0249: MinFilter = POINT;
0250: MagFilter = POINT;
0251: MipFilter = NONE;
0252:
0253: AddressU = Clamp;
0254: AddressV = Clamp;
0255: };
0256:
0257: texture ColorMap;
0258: sampler ColorMapSamp = sampler_state
0259: {
0260: Texture = <ColorMap>;
0261: MinFilter = POINT;
0262: MagFilter = POINT;
0263: MipFilter = NONE;
0264:
0265: AddressU = Clamp;
0266: AddressV = Clamp;
0267: };
0268:
0269:
0270:
0271: struct VS_OUTPUT_FINAL
0272: {
0273: float4 Pos : POSITION;
0274: float2 Tex : TEXCOORD0;
0275: };
0276:
0277:
0278:
0279: VS_OUTPUT_FINAL VS_FINAL (
0280: float4 Pos : POSITION
0281: , float2 Tex : TEXCOORD0
0282: ){
0283: VS_OUTPUT_FINAL Out;
0284:
0285:
0286: Out.Pos = Pos;
0287:
0288:
0289: Out.Tex = Tex;
0290:
0291: return Out;
0292: }
0293:
0294:
0295:
0296: float4 PS_FINAL ( VS_OUTPUT_FINAL In) : COLOR
0297: {
0298: float fog_map = tex2D( FogMapSamp, In.Tex ).x;
0299: float4 col_map = tex2D( ColorMapSamp, In.Tex );
0300: float4 fog_color = {0.84f, 0.88f, 1.0f, 1.0f};
0301:
0302: return lerp(col_map, fog_color, fog_map);
0303: }
0304:
0305:
0306:
0307:
0308: technique TFinal
0309: {
0310: pass P0
0311: {
0312: Sampler[0] = (FogMapSamp);
0313: Sampler[1] = (ColorMapSamp);
0314:
0315:
0316: AlphaBlendEnable = False;
0317:
0318:
0319: VertexShader = compile vs_1_1 VS_FINAL();
0320: PixelShader = compile ps_2_0 PS_FINAL();
0321: }
0322: }
0323: