0001: // -------------------------------------------------------------
0002: // Silhouette Map Filtering
0003: // 
0004: // Copyright (c) 2003 IMAGIRE Takashi. All rights reserved.
0005: // -------------------------------------------------------------
0006: 
0007: // -------------------------------------------------------------
0008: // グローバル変数
0009: // -------------------------------------------------------------
0010: 
0011: 
0012: // -------------------------------------------------------------
0013: // テクスチャ
0014: // -------------------------------------------------------------
0015: texture tSrc;
0016: sampler SrcSamp = sampler_state
0017: {
0018:     Texture = <tSrc>;
0019:     MinFilter = POINT;
0020:     MagFilter = POINT;
0021:     MipFilter = NONE;
0022: 
0023:     AddressU = Clamp;
0024:     AddressV = Clamp;
0025: };
0026: 
0027: 
0028: // -------------------------------------------------------------
0029: // 頂点シェーダからピクセルシェーダに渡すデータ
0030: // -------------------------------------------------------------
0031: struct VS_OUTPUT
0032: {
0033:     float4 Pos      : POSITION;
0034:     float4 Tex      : TEXCOORD0;
0035: };
0036: 
0037: // -------------------------------------------------------------
0038: // ピクセルシェーダ
0039: // -------------------------------------------------------------
0040: const float TEX_SIZE     = 5.0;
0041: const float TEX_SIZE_INV = 1.0/5.0;
0042: 
0043: float4 PS(VS_OUTPUT In) : COLOR
0044: {
0045:     float4 t0 = In.Tex / In.Tex.w;
0046:     float2 t1 = t0 + float2(-TEX_SIZE_INV, 0);
0047:     float2 t2 = t0 + float2( TEX_SIZE_INV, 0);
0048:     float2 t3 = t0 + float2(            0,-TEX_SIZE_INV);
0049:     float2 t4 = t0 + float2(            0, TEX_SIZE_INV);
0050:     float2 t5 = t0 + float2( TEX_SIZE_INV, TEX_SIZE_INV);
0051:     
0052:     float4 c0 = tex2D( SrcSamp, t0 );
0053:     float4 c1 = tex2D( SrcSamp, t1 );
0054:     float4 c2 = tex2D( SrcSamp, t2 );
0055:     float4 c3 = tex2D( SrcSamp, t3 );
0056:     float4 c4 = tex2D( SrcSamp, t4 );
0057:     float4 c5 = tex2D( SrcSamp, t5 );
0058:     
0059:     float3 uv0, uv1, uv2, uv3, uv4;
0060:     
0061:     uv0.y = frac( 16 * c0.a );
0062:     uv1.y = frac( 16 * c1.a );
0063:     uv2.y = frac( 16 * c2.a );
0064:     uv3.y = frac( 16 * c3.a );
0065:     uv4.y = frac( 16 * c4.a );
0066:     uv0.x = frac(      c0.a ) - uv0.y/16;
0067:     uv1.x = frac(      c1.a ) - uv1.y/16;
0068:     uv2.x = frac(      c2.a ) - uv2.y/16;
0069:     uv3.x = frac(      c3.a ) - uv3.y/16;
0070:     uv4.x = frac(      c4.a ) - uv4.y/16;
0071:     
0072:     uv0.z = uv1.z = uv2.z = uv3.z = uv4.z = 0;
0073: 
0074:     uv1.xy += float2(-1, 0);
0075:     uv2.xy += float2( 1, 0);
0076:     uv3.xy += float2( 0,-1);
0077:     uv4.xy += float2( 0, 1);
0078: 
0079:     float3 dt = frac(TEX_SIZE*t0) - uv0;
0080: 
0081:     float frag1 = cross(uv1-uv0, dt).z;
0082:     float frag2 = cross(uv2-uv0, dt).z;
0083:     float frag3 = cross(uv3-uv0, dt).z;
0084:     float frag4 = cross(uv4-uv0, dt).z;
0085:     
0086:     float4 ret = c5;
0087:     if(0<frag1){
0088:         if(frag3<0) ret = c0;
0089:     }else{
0090:         if(0 <frag4) ret = c4;
0091:     }
0092:     if(frag2<=0 && 0<frag3) ret = c2;
0093: 
0094:     return ret;
0095: }
0096: // -------------------------------------------------------------
0097: // テクニック
0098: // -------------------------------------------------------------
0099: technique TShader
0100: {
0101:     pass P0
0102:     {
0103:         // シェーダ
0104:         PixelShader  = compile ps_2_0 PS();
0105:     }
0106: }
0107: