0001: // -------------------------------------------------------------
0002: // Summed Area Tables
0003: // 
0004: // Copyright (c) 2003 IMAGIRE Takashi. All rights reserved.
0005: // -------------------------------------------------------------
0006: 
0007: // -------------------------------------------------------------
0008: // グローバル変数
0009: // -------------------------------------------------------------
0010: 
0011: float  MAP_WIDTH;
0012: float  MAP_HEIGHT;
0013: 
0014: // -------------------------------------------------------------
0015: // テクスチャ
0016: // -------------------------------------------------------------
0017: texture SrcMap;
0018: sampler SrcSamp = sampler_state
0019: {
0020:     Texture = <SrcMap>;
0021:     MinFilter = POINT;
0022:     MagFilter = POINT;
0023:     MipFilter = NONE;
0024: 
0025:     AddressU = Clamp;
0026:     AddressV = Clamp;
0027: };
0028: // -------------------------------------------------------------
0029: // 頂点シェーダからピクセルシェーダに渡すデータ
0030: // -------------------------------------------------------------
0031: struct VS_OUTPUT
0032: {
0033:     float4 Pos          : POSITION;
0034:     float2 ofset        : COLOR0;
0035:     float2 Tex0         : TEXCOORD0;
0036:     float2 Tex1         : TEXCOORD1;
0037:     float2 Tex2         : TEXCOORD2;
0038:     float2 Tex3         : TEXCOORD3;
0039: };
0040: 
0041: // -------------------------------------------------------------
0042: // -------------------------------------------------------------
0043: // SAT作成
0044: // -------------------------------------------------------------
0045: // -------------------------------------------------------------
0046: 
0047: // -------------------------------------------------------------
0048: // 頂点シェーダプログラム
0049: // -------------------------------------------------------------
0050: VS_OUTPUT VS_sat_x (
0051:       float4 Pos    : POSITION,          // モデルの頂点
0052:       float4 Tex    : TEXCOORD0          // テクスチャ座標
0053: ){
0054:     VS_OUTPUT Out = (VS_OUTPUT)0;        // 出力データ
0055:     
0056:     // 位置座標
0057:     Out.Pos = Pos;
0058:     
0059:     Out.Tex0 = Tex + float2( 0.5f/MAP_WIDTH, 0.5f/MAP_HEIGHT );
0060:     Out.Tex1 = Tex + float2(-0.5f/MAP_WIDTH, 0.5f/MAP_HEIGHT );
0061:     
0062:     return Out;
0063: }
0064: 
0065: // -------------------------------------------------------------
0066: // 頂点シェーダプログラム
0067: // -------------------------------------------------------------
0068: VS_OUTPUT VS_sat_y (
0069:       float4 Pos    : POSITION,          // モデルの頂点
0070:       float4 Tex    : TEXCOORD0          // テクスチャ座標
0071: ){
0072:     VS_OUTPUT Out = (VS_OUTPUT)0;        // 出力データ
0073:     
0074:     // 位置座標
0075:     Out.Pos = Pos;
0076:     
0077:     Out.Tex0 = Tex + float2( 0.5f/MAP_WIDTH, 0.5f/MAP_HEIGHT );
0078:     Out.Tex1 = Tex + float2( 0.5f/MAP_WIDTH,-0.5f/MAP_HEIGHT );
0079:     
0080:     return Out;
0081: }
0082: 
0083: // -------------------------------------------------------------
0084: // ピクセルシェーダプログラム
0085: // -------------------------------------------------------------
0086: float4 PS_sat(VS_OUTPUT In) : COLOR
0087: {   
0088:     float4 Color;
0089:     
0090:     Color  = tex2D( SrcSamp, In.Tex0 ) + tex2D( SrcSamp, In.Tex1 );
0091:     
0092:     return Color-0.5f;
0093: }
0094: 
0095: // -------------------------------------------------------------
0096: // -------------------------------------------------------------
0097: // 最終出力
0098: // -------------------------------------------------------------
0099: // -------------------------------------------------------------
0100: 
0101: // -------------------------------------------------------------
0102: // 頂点シェーダプログラム
0103: // -------------------------------------------------------------
0104: VS_OUTPUT VS_out (
0105:       float4 Pos    : POSITION,          // モデルの頂点
0106:       float4 Tex    : TEXCOORD0          // テクスチャ座標
0107: ){
0108:     VS_OUTPUT Out = (VS_OUTPUT)0;        // 出力データ
0109:     
0110:     // 位置座標
0111:     Out.Pos = Pos;
0112:     
0113:     Out.Tex0 = Tex + float2( - 19.5f/MAP_WIDTH, -19.5f/MAP_HEIGHT );
0114:     Out.Tex1 = Tex + float2( - 19.5f/MAP_WIDTH, +20.5f/MAP_HEIGHT );
0115:     Out.Tex2 = Tex + float2( + 20.5f/MAP_WIDTH, -19.5f/MAP_HEIGHT );
0116:     Out.Tex3 = Tex + float2( + 20.5f/MAP_WIDTH, +20.5f/MAP_HEIGHT );
0117:     
0118:     return Out;
0119: }
0120: 
0121: // -------------------------------------------------------------
0122: // ピクセルシェーダプログラム
0123: // -------------------------------------------------------------
0124: float4 PS_out(VS_OUTPUT In) : COLOR
0125: {   
0126:     float4 Color;
0127:     
0128:     Color  =( tex2D( SrcSamp, In.Tex0 )
0129:             - tex2D( SrcSamp, In.Tex1 )
0130:             - tex2D( SrcSamp, In.Tex2 )
0131:             + tex2D( SrcSamp, In.Tex3 ))/(40.0f*40.0f);
0132: 
0133:     return Color+0.5f;
0134: }
0135: 
0136: // -------------------------------------------------------------
0137: // テクニック
0138: // -------------------------------------------------------------
0139: technique TShader
0140: {
0141:     pass P0
0142:     {
0143:         // -----------------------------------------------------
0144:         // X軸ぼかし
0145:         // -----------------------------------------------------
0146:         VertexShader = compile vs_1_1 VS_sat_x();
0147:         PixelShader  = compile ps_1_1 PS_sat();
0148:     }
0149:     pass P1
0150:     {
0151:         // -----------------------------------------------------
0152:         // Y軸ぼかし
0153:         // -----------------------------------------------------
0154:         VertexShader = compile vs_1_1 VS_sat_y();
0155:         PixelShader  = compile ps_1_1 PS_sat();
0156:     }
0157:     pass P2
0158:     {
0159:         // -----------------------------------------------------
0160:         // 出力
0161:         // -----------------------------------------------------
0162:         VertexShader = compile vs_1_1 VS_out();
0163:         PixelShader  = compile ps_1_1 PS_out();
0164:     }
0165: }
0166: