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

游戏引擎

开发平台:

Visual C++

  1. float scale;
  2. float4 trailCorner00, trailCorner10, trailCorner01, trailCorner11;
  3. struct VS_INPUT
  4. {
  5.     float3  Pos     : POSITION;
  6.     float2  tc     : TEXCOORD0;
  7. };
  8. struct VS_OUTPUT
  9. {
  10. float4  Pos : POSITION;
  11. float2  tc0 : TEXCOORD0;
  12. float2  tc1 : TEXCOORD1;
  13. float2  tc2 : TEXCOORD2;
  14. };
  15. texture noise0;
  16. texture noise1;
  17. texture trailHeight;
  18. sampler noise0Sampler = sampler_state 
  19. {
  20. texture = <noise0>;
  21. AddressU  = WRAP;
  22. AddressV  = WRAP;
  23. MIPFILTER = LINEAR;
  24. MINFILTER = LINEAR;
  25. MAGFILTER = LINEAR;
  26. };
  27. sampler noise1Sampler = sampler_state 
  28. {
  29. texture = <noise1>;
  30. AddressU  = WRAP;
  31. AddressV  = WRAP;
  32. MIPFILTER = LINEAR;
  33. MINFILTER = LINEAR;
  34. MAGFILTER = LINEAR;
  35. };
  36. sampler trailSampler = sampler_state 
  37. {
  38. texture = <trailHeight>;
  39. AddressU  = WRAP;
  40. AddressV  = WRAP;
  41. MIPFILTER = LINEAR;
  42. MINFILTER = LINEAR;
  43. MAGFILTER = LINEAR;
  44. };
  45. VS_OUTPUT VShader(VS_INPUT i)
  46. {
  47. VS_OUTPUT o;
  48. o.Pos = float4( i.tc.x*2-1,1-i.tc.y*2, 0, 1 );
  49. o.tc0 = scale*i.Pos.xz*0.01;
  50. o.tc1 = scale*i.Pos.xz*0.1;
  51. o.tc2 = i.Pos.xz;
  52. return o;
  53. }
  54. float4 PShader(VS_OUTPUT i) : COLOR
  55. {
  56. float2 trail_tc;
  57. float a = 0.0f;
  58. if(i.tc2.x>trailCorner00.x && i.tc2.y>trailCorner00.z && i.tc2.x<trailCorner11.x && i.tc2.y<trailCorner11.z)
  59. {
  60. trail_tc = (i.tc2 - trailCorner00.xz)/(trailCorner11.xz - trailCorner00.xz);
  61. a = 1.0f;
  62. }
  63. //return ((tex2D(noise0Sampler, i.tc0) + tex2D(noise1Sampler, i.tc1)) - 0.5f) * (1.0f-a);//*tex2D(trailSampler, trail_tc)
  64. return a*(tex2D(trailSampler, trail_tc.yx)-0.5f)*0.4 + ((tex2D(noise0Sampler, i.tc0) + tex2D(noise1Sampler, i.tc1)) - 0.5f);
  65. }
  66. technique T0
  67. {
  68. pass P0
  69. {
  70. vertexshader = compile vs_2_0 VShader();
  71. pixelshader = compile ps_2_0 PShader();  
  72. }
  73. }