CalcTrail.fx
上传用户:henghua
上传日期:2007-11-14
资源大小:7655k
文件大小:3k
- float waveSpeedSquared;
- float4 coefficient;
- float halfTimeIntervalSquared;
- float4 unitSize;
- float4 delta01, delta10, delta12, delta21;
- texture prevHeightMap;
- texture curHeightMap;
- texture dampeningMap;
- sampler prevHeightSampler = sampler_state
- {
- Texture = <prevHeightMap>;
- MipFilter = NONE;
- MinFilter = POINT;
- MagFilter = POINT;
- AddressU = CLAMP;
- AddressV = CLAMP;
- };
- sampler curHeightSampler = sampler_state
- {
- Texture = <curHeightMap>;
- MipFilter = NONE;
- MinFilter = POINT;
- MagFilter = POINT;
- AddressU = CLAMP;
- AddressV = CLAMP;
- };
- sampler dampeningSampler = sampler_state
- {
- Texture = <dampeningMap>;
- MipFilter = NONE;
- MinFilter = POINT;
- MagFilter = POINT;
- AddressU = CLAMP;
- AddressV = CLAMP;
- };
- struct VS_INPUT
- {
- float4 position : POSITION;
- float2 texCoord : TEXCOORD0;
- float4 diffuse : COLOR0;
- };
- struct VS_OUTPUT
- {
- float4 position : POSITION;
- float2 texCoord : TEXCOORD0;
- float4 diffuse : COLOR0;
- };
- VS_OUTPUT vertexShader(VS_INPUT i)
- {
- VS_OUTPUT o;
- o.position = i.position;
- o.diffuse = i.diffuse;
- o.texCoord = i.texCoord;
- return(o);
- }
- half4 pixelShader(VS_OUTPUT i) : COLOR
- {
- half height11;
- half height01, height21;
- half height10, height12;
- half prevHeight;
- half acceleration;
- half newHeight;
- half dampening;
- half3 normal;
- half3 dydx, dydz;
- half4 result;
-
- height11 = tex2D(curHeightSampler, i.texCoord) ;
- height01 = tex2D(curHeightSampler, i.texCoord + delta01);
- height21 = tex2D(curHeightSampler, i.texCoord + delta21);
- height10 = tex2D(curHeightSampler, i.texCoord + delta10);
- height12 = tex2D(curHeightSampler, i.texCoord + delta12);
- prevHeight = tex2D(prevHeightSampler, i.texCoord);
- dampening = tex2D(dampeningSampler, i.texCoord);
- acceleration = 0.5*dampening * waveSpeedSquared *
- (height01 + height21 + height10 + height12 - 4.0 * height11); // waveSpeedSquared 10.0f
- newHeight = coefficient.x * height11 - // 1.99f
- coefficient.y * prevHeight + // 0.99f
- halfTimeIntervalSquared * acceleration; // 0.01f
-
- dydx = half3(unitSize.x, height21 - height11, 0.0 ); // 50/128
- dydz = half3(0.0, height12 - height11, -unitSize.z); // 20/128
- normal = cross(dydx, dydz);
- normal = normalize(normal);
- result = half4(newHeight, normal);
- return(result);
- }
- technique T0
- {
- pass P0
- {
- vertexshader = compile vs_2_0 vertexShader();
- pixelshader = compile ps_2_0 pixelShader();
- }
- }