cloudLayerV.glsl 3.9 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. #include "hlslCompat.glsl"
  23. in vec4 vPosition;
  24. in vec3 vNormal;
  25. in vec3 vBinormal;
  26. in vec3 vTangent;
  27. in vec2 vTexCoord0;
  28. out vec4 texCoord12;
  29. #define OUT_texCoord12 texCoord12
  30. out vec4 texCoord34;
  31. #define OUT_texCoord34 texCoord34
  32. out vec3 vLightTS; // light vector in tangent space, denormalized
  33. #define OUT_vLightTS vLightTS
  34. out vec3 vViewTS; // view vector in tangent space, denormalized
  35. #define OUT_vViewTS vViewTS
  36. out float worldDist;
  37. #define OUT_worldDist worldDist
  38. //-----------------------------------------------------------------------------
  39. // Uniforms
  40. //-----------------------------------------------------------------------------
  41. uniform mat4 modelview;
  42. uniform vec3 eyePosWorld;
  43. uniform vec3 sunVec;
  44. uniform vec2 texOffset0;
  45. uniform vec2 texOffset1;
  46. uniform vec2 texOffset2;
  47. uniform vec3 texScale;
  48. //-----------------------------------------------------------------------------
  49. // Main
  50. //-----------------------------------------------------------------------------
  51. void main()
  52. {
  53. vec4 IN_pos = vPosition;
  54. vec3 IN_normal = vNormal;
  55. vec3 IN_binormal = vBinormal;
  56. vec3 IN_tangent = vTangent;
  57. vec2 IN_uv0 = vTexCoord0.st;
  58. gl_Position = modelview * IN_pos;
  59. // Offset the uv so we don't have a seam directly over our head.
  60. vec2 uv = IN_uv0 + vec2( 0.5, 0.5 );
  61. OUT_texCoord12.xy = uv * texScale.x;
  62. OUT_texCoord12.xy += texOffset0;
  63. OUT_texCoord12.zw = uv * texScale.y;
  64. OUT_texCoord12.zw += texOffset1;
  65. OUT_texCoord34.xy = uv * texScale.z;
  66. OUT_texCoord34.xy += texOffset2;
  67. OUT_texCoord34.z = IN_pos.z;
  68. OUT_texCoord34.w = 0.0;
  69. // Transform the normal, tangent and binormal vectors from object space to
  70. // homogeneous projection space:
  71. vec3 vNormalWS = -IN_normal;
  72. vec3 vTangentWS = -IN_tangent;
  73. vec3 vBinormalWS = -IN_binormal;
  74. // Compute position in world space:
  75. vec4 vPositionWS = IN_pos + vec4( eyePosWorld, 1 ); //tMul( IN_pos, objTrans );
  76. // Compute and output the world view vector (unnormalized):
  77. vec3 vViewWS = eyePosWorld - vPositionWS.xyz;
  78. // Compute denormalized light vector in world space:
  79. vec3 vLightWS = -sunVec;
  80. // Normalize the light and view vectors and transform it to the IN_tangent space:
  81. mat3 mWorldToTangent = mat3( vTangentWS, vBinormalWS, vNormalWS );
  82. // Propagate the view and the light vectors (in tangent space):
  83. OUT_vLightTS = vLightWS * mWorldToTangent;
  84. OUT_vViewTS = mWorldToTangent * vViewWS;
  85. OUT_worldDist = clamp( pow( max( IN_pos.z, 0 ), 2 ), 0.0, 1.0 );
  86. correctSSP(gl_Position);
  87. }