NormalShader.fx
上传用户:henghua
上传日期:2007-11-14
资源大小:7655k
文件大小:2k
- float dsizeX,dsizeY;
- float4 corner00, corner10, corner01, corner11;
- float amplitude;
- struct VS_INPUT
- {
- float3 Pos : POSITION;
- float2 tc : TEXCOORD0;
- };
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float2 tc : TEXCOORD0;
- float3 tc01 : TEXCOORD1;
- float3 tc11 : TEXCOORD2;
- float3 tc00 : TEXCOORD3;
- float3 tc10 : TEXCOORD4;
- };
- texture heightmap;
- sampler hsampler = sampler_state
- {
- texture = <heightmap>;
- AddressU = WRAP;
- AddressV = WRAP;
- MIPFILTER = NONE;
- MINFILTER = LINEAR;
- MAGFILTER = LINEAR;
- };
- VS_OUTPUT VShader(VS_INPUT i)
- {
- VS_OUTPUT o;
-
- o.Pos = float4( i.tc.x*2-1,1-i.tc.y*2, 0, 1 );
- float scale = 1;
-
- float2 tc = i.tc + float2(-dsizeX*scale,0);
- float4 meh = lerp(lerp(corner00,corner10,tc.x),lerp(corner01,corner11,tc.x),tc.y);
- o.tc00 = meh.xyz/meh.w;
-
- tc = i.tc + float2(dsizeX*scale,0);
- meh = lerp(lerp(corner00,corner10,tc.x),lerp(corner01,corner11,tc.x),tc.y);
- o.tc01 = meh.xyz/meh.w;
-
- tc = i.tc + float2(0,-dsizeY*scale);
- meh = lerp(lerp(corner00,corner10,tc.x),lerp(corner01,corner11,tc.x),tc.y);
- o.tc10 = meh.xyz/meh.w;
-
- tc = i.tc + float2(0,dsizeY*scale);
- meh = lerp(lerp(corner00,corner10,tc.x),lerp(corner01,corner11,tc.x),tc.y);
- o.tc11 = meh.xyz/meh.w;
- o.tc = i.tc;
-
- return o;
- }
- float4 PShader(VS_OUTPUT i) : COLOR
- {
- float2 dx = {dsizeX,0},
- dy = {0,dsizeY};
- i.tc01.y = amplitude*tex2D(hsampler, i.tc+dx);
- i.tc00.y = amplitude*tex2D(hsampler, i.tc-dx);
- i.tc11.y = amplitude*tex2D(hsampler, i.tc+dy);
- i.tc10.y = amplitude*tex2D(hsampler, i.tc-dy);
- float3 normal = normalize(-cross(i.tc01-i.tc00, i.tc11-i.tc10));
- return float4(0.5+0.5*normal,1);
- }
- technique T0
- {
- pass P0
- {
- vertexshader = compile vs_2_0 VShader();
- pixelshader = compile ps_2_0 PShader();
- }
- }