0001: // -------------------------------------------------------------
0002: // ガウスフィルタ
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: float weight[8];
0014: 
0015: // -------------------------------------------------------------
0016: // テクスチャ
0017: // -------------------------------------------------------------
0018: texture SrcMap;
0019: sampler SrcSamp = sampler_state
0020: {
0021:     Texture = <SrcMap>;
0022:     MinFilter = LINEAR;
0023:     MagFilter = LINEAR;
0024:     MipFilter = NONE;
0025: 
0026:     AddressU = Clamp;
0027:     AddressV = Clamp;
0028: };
0029: // -------------------------------------------------------------
0030: // 頂点シェーダからピクセルシェーダに渡すデータ
0031: // -------------------------------------------------------------
0032: struct VS_OUTPUT
0033: {
0034:     float4 Pos          : POSITION;
0035:     float2 Tex          : TEXCOORD0;
0036: };
0037: 
0038: // -------------------------------------------------------------
0039: // Xぼかす
0040: // -------------------------------------------------------------
0041: 
0042: // -------------------------------------------------------------
0043: // 頂点シェーダプログラム
0044: // -------------------------------------------------------------
0045: VS_OUTPUT VS_pass1 (
0046:       float4 Pos    : POSITION,          // モデルの頂点
0047:       float4 Tex    : TEXCOORD0          // テクスチャ座標
0048: ){
0049:     VS_OUTPUT Out = (VS_OUTPUT)0;        // 出力データ
0050:     
0051:     // 位置座標
0052:     Out.Pos = Pos;
0053:     
0054:     Out.Tex = Tex + float2( 0, 0.5f/MAP_HEIGHT );
0055:     
0056:     return Out;
0057: }
0058: 
0059: // -------------------------------------------------------------
0060: // ピクセルシェーダプログラム
0061: // -------------------------------------------------------------
0062: float4 PS_pass1(VS_OUTPUT In) : COLOR
0063: {   
0064:     float4 Color;
0065:     
0066:     Color  = weight[0] *  tex2D( SrcSamp, In.Tex );
0067:     Color += weight[1]
0068:      * (tex2D( SrcSamp, In.Tex + float2( + 2.0f/MAP_WIDTH, 0 ) )
0069:      +  tex2D( SrcSamp, In.Tex + float2( - 2.0f/MAP_WIDTH, 0 ) ));
0070:     Color += weight[2]
0071:      * (tex2D( SrcSamp, In.Tex + float2( + 4.0f/MAP_WIDTH, 0 ) )
0072:      +  tex2D( SrcSamp, In.Tex + float2( - 4.0f/MAP_WIDTH, 0 ) ));
0073:     Color += weight[3]
0074:      * (tex2D( SrcSamp, In.Tex + float2( + 6.0f/MAP_WIDTH, 0 ) )
0075:      +  tex2D( SrcSamp, In.Tex + float2( - 6.0f/MAP_WIDTH, 0 ) ));
0076:     Color += weight[4]
0077:      * (tex2D( SrcSamp, In.Tex + float2( + 8.0f/MAP_WIDTH, 0 ) )
0078:      +  tex2D( SrcSamp, In.Tex + float2( - 8.0f/MAP_WIDTH, 0 ) ));
0079:     Color += weight[5]
0080:      * (tex2D( SrcSamp, In.Tex + float2( +10.0f/MAP_WIDTH, 0 ) )
0081:      +  tex2D( SrcSamp, In.Tex + float2( -10.0f/MAP_WIDTH, 0 ) ));
0082:     Color += weight[6]
0083:      * (tex2D( SrcSamp, In.Tex + float2( +12.0f/MAP_WIDTH, 0 ) )
0084:      +  tex2D( SrcSamp, In.Tex + float2( -12.0f/MAP_WIDTH, 0 ) ));
0085:     Color += weight[7]
0086:      * (tex2D( SrcSamp, In.Tex + float2( +14.0f/MAP_WIDTH, 0 ) )
0087:      +  tex2D( SrcSamp, In.Tex + float2( -14.0f/MAP_WIDTH, 0 ) ));
0088:     
0089:     return Color;
0090: }
0091: // -------------------------------------------------------------
0092: // Yぼかす
0093: // -------------------------------------------------------------
0094: 
0095: // -------------------------------------------------------------
0096: // 頂点シェーダプログラム
0097: // -------------------------------------------------------------
0098: VS_OUTPUT VS_pass2 (
0099:       float4 Pos    : POSITION,          // モデルの頂点
0100:       float4 Tex    : TEXCOORD0          // テクスチャ座標
0101: ){
0102:     VS_OUTPUT Out = (VS_OUTPUT)0;        // 出力データ
0103:     
0104:     // 位置座標
0105:     Out.Pos = Pos;
0106:     
0107:     Out.Tex = Tex + float2( 0.5f/MAP_WIDTH, 0 );
0108:     
0109:     return Out;
0110: }
0111: 
0112: // -------------------------------------------------------------
0113: // ピクセルシェーダプログラム
0114: // -------------------------------------------------------------
0115: float4 PS_pass2(VS_OUTPUT In) : COLOR
0116: {   
0117:     float4 Color;
0118:     
0119:     Color  = weight[0] *  tex2D( SrcSamp, In.Tex );
0120:     Color += weight[1]
0121:      * (tex2D( SrcSamp, In.Tex + float2( 0, + 2.0f/MAP_HEIGHT) )
0122:      +  tex2D( SrcSamp, In.Tex + float2( 0, - 2.0f/MAP_HEIGHT) ));
0123:     Color += weight[2]
0124:      * (tex2D( SrcSamp, In.Tex + float2( 0, + 4.0f/MAP_HEIGHT) )
0125:      +  tex2D( SrcSamp, In.Tex + float2( 0, - 4.0f/MAP_HEIGHT) ));
0126:     Color += weight[3]
0127:      * (tex2D( SrcSamp, In.Tex + float2( 0, + 6.0f/MAP_HEIGHT) )
0128:      +  tex2D( SrcSamp, In.Tex + float2( 0, - 6.0f/MAP_HEIGHT) ));
0129:     Color += weight[4]
0130:      * (tex2D( SrcSamp, In.Tex + float2( 0, + 8.0f/MAP_HEIGHT) )
0131:      +  tex2D( SrcSamp, In.Tex + float2( 0, - 8.0f/MAP_HEIGHT) ));
0132:     Color += weight[5]
0133:      * (tex2D( SrcSamp, In.Tex + float2( 0, +10.0f/MAP_HEIGHT) )
0134:      +  tex2D( SrcSamp, In.Tex + float2( 0, -10.0f/MAP_HEIGHT) ));
0135:     Color += weight[6]
0136:      * (tex2D( SrcSamp, In.Tex + float2( 0, +12.0f/MAP_HEIGHT) )
0137:      +  tex2D( SrcSamp, In.Tex + float2( 0, -12.0f/MAP_HEIGHT) ));
0138:     Color += weight[7]
0139:      * (tex2D( SrcSamp, In.Tex + float2( 0, +14.0f/MAP_HEIGHT) )
0140:      +  tex2D( SrcSamp, In.Tex + float2( 0, -14.0f/MAP_HEIGHT) ));
0141:     
0142:     return Color;
0143: }
0144: 
0145: // -------------------------------------------------------------
0146: // テクニック
0147: // -------------------------------------------------------------
0148: technique TShader
0149: {
0150:     pass P0
0151:     {
0152:         // シェーダ
0153:         VertexShader = compile vs_1_1 VS_pass1();
0154:         PixelShader  = compile ps_2_0 PS_pass1();
0155:         
0156:         Sampler[0] = (SrcSamp);
0157:     }
0158:     pass P1
0159:     {
0160:         // シェーダ
0161:         VertexShader = compile vs_1_1 VS_pass2();
0162:         PixelShader  = compile ps_2_0 PS_pass2();
0163:         
0164:         Sampler[0] = (SrcSamp);
0165:     }
0166: }
0167: