0001:
0002:
0003:
0004:
0005:
0006:
0007:
0008:
0009:
0010: float4x4 mWVP;
0011: float4 LightPos;
0012: float4 EyePos;
0013: float4 alpha;
0014:
0015:
0016:
0017:
0018: texture MapP;
0019: sampler SampP = sampler_state
0020: {
0021: Texture = <MapP>;
0022: MinFilter = LINEAR;
0023: MagFilter = LINEAR;
0024: MipFilter = NONE;
0025:
0026: AddressU = Clamp;
0027: AddressV = Clamp;
0028: };
0029:
0030: texture MapQ;
0031: sampler SampQ = sampler_state
0032: {
0033: Texture = <MapQ>;
0034: MinFilter = LINEAR;
0035: MagFilter = LINEAR;
0036: MipFilter = NONE;
0037:
0038: AddressU = Clamp;
0039: AddressV = Clamp;
0040: };
0041:
0042:
0043:
0044: struct VS_INPUT
0045: {
0046: float4 Pos : POSITION;
0047: float3 Normal : NORMAL0;
0048: float2 Tex : TEXCOORD0;
0049: };
0050:
0051:
0052:
0053: struct VS_OUTPUT
0054: {
0055: float4 Pos : POSITION;
0056: float2 v : TEXCOORD0;
0057: float2 h : TEXCOORD1;
0058: float2 w : TEXCOORD2;
0059: };
0060:
0061:
0062:
0063:
0064: float2 Q(float3 In, float3 B, float3 T, float3 N)
0065: {
0066: float2 Out = (float2)0;
0067:
0068:
0069: float3 v;
0070: v.x = dot(B,In);
0071: v.y = dot(T,In);
0072: v.z = dot(N,In);
0073:
0074:
0075: float pv = 7.0f/8.0f;
0076: float ar = 1.0/(2.0*(1.000000001+v.z));
0077:
0078: Out.x = pv * ar * v.x + 0.5;
0079: Out.y = pv * ar * v.y + 0.5;
0080:
0081: return Out;
0082: }
0083:
0084:
0085:
0086: VS_OUTPUT VS(VS_INPUT In)
0087: {
0088: VS_OUTPUT Out = (VS_OUTPUT)0;
0089:
0090:
0091: Out.Pos = mul( In.Pos, mWVP );
0092:
0093:
0094: float3 N = In.Normal;
0095: float3 B = float3(0,1,0);
0096: float3 T = normalize(cross(N,B));
0097: B = cross(T,N);
0098:
0099:
0100: float3 V = normalize(EyePos -In.Pos.xyz);
0101: float3 W = normalize(LightPos-In.Pos.xyz);
0102: float3 H = normalize(W+V);
0103:
0104:
0105: Out.v = Q(V, B,T,N);
0106: Out.w = Q(W, B,T,N);
0107: Out.h = Q(H, B,T,N);
0108:
0109: return Out;
0110: }
0111:
0112:
0113:
0114: float4 PS(VS_OUTPUT In) : COLOR
0115: {
0116: float4 v = tex2D( SampP, In.v );
0117: float4 h = tex2D( SampQ, In.h );
0118: float4 w = tex2D( SampP, In.w );
0119:
0120: return alpha * v * h * w;
0121: }
0122:
0123:
0124:
0125: technique TShader
0126: {
0127: pass P0
0128: {
0129: VertexShader = compile vs_1_1 VS();
0130: PixelShader = compile ps_1_1 PS();
0131: }
0132: }
0133:
0134: