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