CalcTrail.fx
上传用户:henghua
上传日期:2007-11-14
资源大小:7655k
文件大小:3k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. float waveSpeedSquared;
  2. float4 coefficient;
  3. float halfTimeIntervalSquared;
  4. float4 unitSize;
  5. float4 delta01, delta10, delta12, delta21;
  6. texture prevHeightMap;
  7. texture curHeightMap;
  8. texture dampeningMap;
  9. sampler prevHeightSampler = sampler_state
  10. {  
  11.     Texture = <prevHeightMap>; 
  12.     MipFilter = NONE; 
  13.     MinFilter = POINT; 
  14.     MagFilter = POINT; 
  15. AddressU  = CLAMP;
  16. AddressV  = CLAMP;
  17. };
  18. sampler curHeightSampler = sampler_state
  19. {  
  20.     Texture = <curHeightMap>; 
  21.     MipFilter = NONE; 
  22.     MinFilter = POINT; 
  23.     MagFilter = POINT; 
  24. AddressU  = CLAMP;
  25. AddressV  = CLAMP;
  26. };
  27. sampler dampeningSampler = sampler_state
  28. {  
  29.     Texture = <dampeningMap>; 
  30.     MipFilter = NONE; 
  31.     MinFilter = POINT; 
  32.     MagFilter = POINT; 
  33. AddressU  = CLAMP;
  34. AddressV  = CLAMP;
  35. };
  36. struct VS_INPUT
  37. {
  38. float4 position : POSITION;
  39. float2 texCoord : TEXCOORD0;
  40. float4 diffuse  : COLOR0;
  41. };
  42. struct VS_OUTPUT
  43. {
  44. float4 position : POSITION;
  45. float2 texCoord : TEXCOORD0;
  46. float4 diffuse  : COLOR0;
  47. };
  48. VS_OUTPUT vertexShader(VS_INPUT i)
  49. {
  50. VS_OUTPUT o;
  51. o.position = i.position;
  52. o.diffuse = i.diffuse;
  53. o.texCoord = i.texCoord;
  54. return(o);
  55. }
  56. half4 pixelShader(VS_OUTPUT i) : COLOR
  57. {
  58. half  height11;
  59. half  height01, height21;
  60. half  height10, height12;
  61. half  prevHeight;
  62. half  acceleration;  
  63. half  newHeight;
  64. half  dampening;
  65. half3 normal;
  66. half3 dydx, dydz;
  67. half4 result;
  68. height11 = tex2D(curHeightSampler, i.texCoord) ;
  69. height01 = tex2D(curHeightSampler, i.texCoord + delta01);
  70. height21 = tex2D(curHeightSampler, i.texCoord + delta21);
  71. height10 = tex2D(curHeightSampler, i.texCoord + delta10);
  72. height12 = tex2D(curHeightSampler, i.texCoord + delta12);
  73. prevHeight = tex2D(prevHeightSampler, i.texCoord);
  74. dampening = tex2D(dampeningSampler, i.texCoord);
  75. acceleration = 0.5*dampening * waveSpeedSquared * 
  76.    (height01 + height21 + height10 + height12 - 4.0 * height11); // waveSpeedSquared 10.0f
  77. newHeight = coefficient.x * height11 - // 1.99f
  78.                 coefficient.y * prevHeight + // 0.99f
  79.                 halfTimeIntervalSquared * acceleration; // 0.01f
  80.  
  81. dydx = half3(unitSize.x, height21 - height11, 0.0  ); // 50/128
  82. dydz = half3(0.0,  height12 - height11, -unitSize.z); // 20/128
  83. normal = cross(dydx, dydz);
  84. normal = normalize(normal);
  85. result = half4(newHeight, normal);
  86. return(result);
  87. }
  88. technique T0
  89. {
  90. pass P0
  91. {
  92. vertexshader = compile vs_2_0 vertexShader();
  93. pixelshader = compile ps_2_0 pixelShader();  
  94. }
  95. }