cloudLayerV.hlsl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------
  23. // Structures
  24. //-----------------------------------------------------------------------------
  25. #include "shaderModel.hlsl"
  26. struct CloudVert
  27. {
  28. float3 pos : POSITION;
  29. float3 normal : NORMAL;
  30. float3 binormal : BINORMAL;
  31. float3 tangent : TANGENT;
  32. float2 uv0 : TEXCOORD0;
  33. };
  34. struct ConnectData
  35. {
  36. float4 hpos : TORQUE_POSITION;
  37. float4 texCoord12 : TEXCOORD0;
  38. float4 texCoord34 : TEXCOORD1;
  39. float3 vLightTS : TEXCOORD2; // light vector in tangent space, denormalized
  40. float3 vViewTS : TEXCOORD3; // view vector in tangent space, denormalized
  41. float worldDist : TEXCOORD4;
  42. };
  43. //-----------------------------------------------------------------------------
  44. // Uniforms
  45. //-----------------------------------------------------------------------------
  46. uniform float4x4 modelview;
  47. uniform float3 eyePosWorld;
  48. uniform float3 sunVec;
  49. uniform float2 texOffset0;
  50. uniform float2 texOffset1;
  51. uniform float2 texOffset2;
  52. uniform float3 texScale;
  53. //-----------------------------------------------------------------------------
  54. // Main
  55. //-----------------------------------------------------------------------------
  56. ConnectData main( CloudVert IN )
  57. {
  58. ConnectData OUT;
  59. OUT.hpos = mul(modelview, float4(IN.pos,1.0));
  60. // Offset the uv so we don't have a seam directly over our head.
  61. float2 uv = IN.uv0 + float2( 0.5, 0.5 );
  62. OUT.texCoord12.xy = uv * texScale.x;
  63. OUT.texCoord12.xy += texOffset0;
  64. OUT.texCoord12.zw = uv * texScale.y;
  65. OUT.texCoord12.zw += texOffset1;
  66. OUT.texCoord34.xy = uv * texScale.z;
  67. OUT.texCoord34.xy += texOffset2;
  68. OUT.texCoord34.z = IN.pos.z;
  69. OUT.texCoord34.w = 0.0;
  70. // Transform the normal, tangent and binormal vectors from object space to
  71. // homogeneous projection space:
  72. float3 vNormalWS = -IN.normal;
  73. float3 vTangentWS = -IN.tangent;
  74. float3 vBinormalWS = -IN.binormal;
  75. // Compute position in world space:
  76. float4 vPositionWS = float4(IN.pos, 1.0) + float4(eyePosWorld, 1); //mul( IN.pos, objTrans );
  77. // Compute and output the world view vector (unnormalized):
  78. float3 vViewWS = eyePosWorld - vPositionWS.xyz;
  79. // Compute denormalized light vector in world space:
  80. float3 vLightWS = -sunVec;
  81. // Normalize the light and view vectors and transform it to the tangent space:
  82. float3x3 mWorldToTangent = float3x3( vTangentWS, vBinormalWS, vNormalWS );
  83. // Propagate the view and the light vectors (in tangent space):
  84. OUT.vLightTS = mul( vLightWS, mWorldToTangent );
  85. OUT.vViewTS = mul( mWorldToTangent, vViewWS );
  86. OUT.worldDist = saturate( pow( max( IN.pos.z, 0 ), 2 ) );
  87. return OUT;
  88. }