0001:
0002:
0003:
0004:
0005:
0006:
0007:
0008:
0009:
0010:
0011: float4x4 mWVP;
0012:
0013: float4 vLightDir;
0014: float4 vColor;
0015: float3 vEyePos;
0016:
0017:
0018:
0019:
0020:
0021: texture DecaleTex;
0022: sampler DecaleSamp = sampler_state
0023: {
0024: Texture = <DecaleTex>;
0025: MinFilter = LINEAR;
0026: MagFilter = LINEAR;
0027: MipFilter = NONE;
0028:
0029: AddressU = Clamp;
0030: AddressV = Clamp;
0031: };
0032:
0033:
0034: texture NormalMap;
0035: sampler NormalSamp = sampler_state
0036: {
0037: Texture = <NormalMap>;
0038: MinFilter = LINEAR;
0039: MagFilter = LINEAR;
0040: MipFilter = NONE;
0041:
0042: AddressU = Wrap;
0043: AddressV = Wrap;
0044: };
0045:
0046:
0047:
0048: texture HeightMap;
0049: sampler HeightSamp = sampler_state
0050: {
0051: Texture = <HeightMap>;
0052: MinFilter = LINEAR;
0053: MagFilter = LINEAR;
0054: MipFilter = NONE;
0055:
0056: AddressU = Wrap;
0057: AddressV = Wrap;
0058: };
0059:
0060:
0061:
0062:
0063: struct VS_OUTPUT
0064: {
0065: float4 Pos : POSITION;
0066: float4 Color : COLOR0;
0067: float2 Tex : TEXCOORD0;
0068: float3 L : TEXCOORD1;
0069: float3 E : TEXCOORD2;
0070: };
0071:
0072:
0073:
0074: VS_OUTPUT VS(
0075: float4 Pos : POSITION,
0076: float3 Normal : NORMAL,
0077: float3 Tangent : TANGENT0,
0078: float2 Texcoord : TEXCOORD0
0079: ){
0080: VS_OUTPUT Out = (VS_OUTPUT)0;
0081:
0082:
0083: Out.Pos = mul(Pos, mWVP);
0084:
0085:
0086: Out.Color = vColor;
0087:
0088:
0089: Out.Tex = Texcoord;
0090:
0091:
0092: float3 N = Normal;
0093: float3 T = Tangent;
0094: float3 B = cross(N,T);
0095:
0096:
0097: float3 E = vEyePos - Pos.xyz;
0098: Out.E.x = dot(E,T);
0099: Out.E.y = dot(E,B);
0100: Out.E.z = dot(E,N);
0101:
0102: float3 L = -vLightDir.xyz;
0103: Out.L.x = dot(L,T);
0104: Out.L.y = dot(L,B);
0105: Out.L.z = dot(L,N);
0106:
0107: return Out;
0108: }
0109:
0110: float4 PS( VS_OUTPUT In) : COLOR
0111: {
0112: float3 L = normalize(In.L);
0113: float3 E = normalize(In.E);
0114:
0115: float h = tex2D( HeightSamp, In.Tex );
0116:
0117: float2 Tex = In.Tex + 0.03 * h * E.xy;
0118:
0119: float3 N = 2.0f*tex2D( NormalSamp, Tex ).xyz-1.0;
0120: float3 R = reflect(-E, N);
0121: float amb = -vLightDir.w;
0122:
0123: return In.Color * tex2D( DecaleSamp, Tex )
0124: * (max(0, dot(N, L))+amb)
0125: + 0.3f * pow(max(0,dot(R, L)), 8);
0126: }
0127:
0128:
0129: float4 PS_BUMP( VS_OUTPUT In) : COLOR
0130: {
0131: float3 L = normalize(In.L);
0132: float3 E = normalize(In.E);
0133:
0134: float h = tex2D( HeightSamp, In.Tex );
0135:
0136: float2 Tex = In.Tex;
0137:
0138: float3 N = 2.0f*tex2D( NormalSamp, Tex ).xyz-1.0;
0139: float3 R = reflect(-E, N);
0140: float amb = -vLightDir.w;
0141:
0142: return In.Color * tex2D( DecaleSamp, Tex )
0143: * (max(0, dot(N, L))+amb)
0144: + 0.3f * pow(max(0,dot(R, L)), 8);
0145: }
0146:
0147:
0148:
0149:
0150: technique TShader
0151: {
0152: pass P0
0153: {
0154: VertexShader = compile vs_1_1 VS();
0155: PixelShader = compile ps_2_0 PS();
0156: }
0157: pass P1
0158: {
0159: VertexShader = compile vs_1_1 VS();
0160: PixelShader = compile ps_2_0 PS_BUMP();
0161: }
0162: }
0163: