0001:
0002:
0003:
0004:
0005:
0006:
0007:
0008:
0009:
0010:
0011:
0012:
0013: float4x4 g_mWorldViewProjection;
0014:
0015: float g_fTexSize;
0016: float g_fInvTexSize;
0017:
0018:
0019:
0020:
0021: texture Texture;
0022: sampler Sampler =
0023: sampler_state
0024: {
0025: Texture = <Texture>;
0026: MinFilter = LINEAR;
0027: MagFilter = LINEAR;
0028: MipFilter = LINEAR;
0029:
0030: AddressU = Clamp;
0031: AddressV = Clamp;
0032: };
0033:
0034: texture WangTexture;
0035: sampler WangSampler =
0036: sampler_state
0037: {
0038: Texture = <WangTexture>;
0039: MinFilter = LINEAR;
0040: MagFilter = LINEAR;
0041: MipFilter = NONE;
0042:
0043: AddressU = Clamp;
0044: AddressV = Clamp;
0045: };
0046:
0047: texture RandTexture;
0048: sampler RandSampler =
0049: sampler_state
0050: {
0051: Texture = <RandTexture>;
0052: MinFilter = POINT;
0053: MagFilter = POINT;
0054: MipFilter = NONE;
0055:
0056: AddressU = Wrap;
0057: AddressV = Wrap;
0058: };
0059:
0060:
0061:
0062:
0063:
0064: struct VS_OUTPUT
0065: {
0066: float4 Position : POSITION;
0067: float2 TextureUV : TEXCOORD0;
0068: };
0069:
0070:
0071:
0072:
0073:
0074:
0075:
0076: VS_OUTPUT WangVS( float4 vPos : POSITION,
0077: float3 vNormal : NORMAL,
0078: float2 vTexCoord0 : TEXCOORD0 )
0079: {
0080: VS_OUTPUT Output;
0081:
0082:
0083: Output.Position = mul(vPos, g_mWorldViewProjection );
0084:
0085:
0086: Output.TextureUV.xy = vTexCoord0;
0087:
0088: return Output;
0089: }
0090:
0091:
0092:
0093:
0094:
0095:
0096:
0097: float4 WangPS( VS_OUTPUT In ) : COLOR
0098: {
0099: float2 TexCoord;
0100: float2 Tex;
0101:
0102: TexCoord.x = 0.25 * frac( g_fTexSize * In.TextureUV.x );
0103: TexCoord.y = 0.25 * frac( g_fTexSize * In.TextureUV.y );
0104:
0105: float2 e0 = tex2D( RandSampler, In.TextureUV ).xy;
0106: float ex = tex2D( RandSampler, In.TextureUV + float2( g_fInvTexSize, 0.0 ) ).x;
0107: float ey = tex2D( RandSampler, In.TextureUV + float2( 0.0, g_fInvTexSize ) ).y;
0108:
0109: if( e0.x < 0.5 )
0110: {
0111: if( ex < 0.5 )
0112: {
0113:
0114: }else{
0115: TexCoord.x += 0.25;
0116: }
0117: }else{
0118: if( ex < 0.5 )
0119: {
0120: TexCoord.x += 0.75;
0121: }else{
0122: TexCoord.x += 0.50;
0123: }
0124: }
0125: if( ey < 0.5 )
0126: {
0127: if( e0.y < 0.5 )
0128: {
0129: TexCoord.y += 0.75;
0130: }else{
0131: TexCoord.y += 0.50;
0132: }
0133: }else{
0134: if( e0.y < 0.5 )
0135: {
0136:
0137: }else{
0138: TexCoord.y += 0.25;
0139: }
0140: }
0141:
0142: return tex2D( WangSampler, TexCoord );
0143: }
0144:
0145:
0146:
0147:
0148:
0149: technique WangTechnique
0150: {
0151: pass P0
0152: {
0153: VertexShader = compile vs_1_1 WangVS();
0154: PixelShader = compile ps_2_0 WangPS();
0155: }
0156: }
0157:
0158:
0159:
0160:
0161:
0162:
0163:
0164:
0165:
0166: VS_OUTPUT SimpleVS( float4 vPos : POSITION,
0167: float3 vNormal : NORMAL,
0168: float2 vTexCoord0 : TEXCOORD0 )
0169: {
0170: VS_OUTPUT Output;
0171:
0172:
0173: Output.Position = mul(vPos, g_mWorldViewProjection );
0174:
0175:
0176: Output.TextureUV.xy = vTexCoord0;
0177:
0178: return Output;
0179: }
0180:
0181:
0182:
0183:
0184:
0185:
0186:
0187: float4 SimplePS( VS_OUTPUT In ) : COLOR
0188: {
0189: return tex2D( Sampler, In.TextureUV );
0190: }
0191:
0192:
0193:
0194:
0195:
0196: technique SimpleTechnique
0197: {
0198: pass P0
0199: {
0200: VertexShader = compile vs_1_1 SimpleVS();
0201: PixelShader = compile ps_1_1 SimplePS();
0202: }
0203: }
0204:
0205:
0206:
0207:
0208: