PBRVegetation.glsl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "Uniforms.glsl"
  2. #include "Samplers.glsl"
  3. #include "Transform.glsl"
  4. #include "ScreenPos.glsl"
  5. #include "Lighting.glsl"
  6. #include "Constants.glsl"
  7. #include "Fog.glsl"
  8. #include "PBR.glsl"
  9. #include "IBL.glsl"
  10. #line 30010
  11. uniform float cWindHeightFactor;
  12. uniform float cWindHeightPivot;
  13. uniform float cWindPeriod;
  14. uniform vec2 cWindWorldSpacing;
  15. #ifdef WINDSTEMAXIS
  16. uniform vec3 cWindStemAxis;
  17. #endif
  18. #if defined(NORMALMAP)
  19. varying vec4 vTexCoord;
  20. varying vec4 vTangent;
  21. #else
  22. varying vec2 vTexCoord;
  23. #endif
  24. varying vec3 vNormal;
  25. varying vec4 vWorldPos;
  26. #ifdef VERTEXCOLOR
  27. varying vec4 vColor;
  28. #endif
  29. #ifdef PERPIXEL
  30. #ifdef SHADOW
  31. #ifndef GL_ES
  32. varying vec4 vShadowPos[NUMCASCADES];
  33. #else
  34. varying highp vec4 vShadowPos[NUMCASCADES];
  35. #endif
  36. #endif
  37. #ifdef SPOTLIGHT
  38. varying vec4 vSpotPos;
  39. #endif
  40. #ifdef POINTLIGHT
  41. varying vec3 vCubeMaskVec;
  42. #endif
  43. #else
  44. varying vec3 vVertexLight;
  45. varying vec4 vScreenPos;
  46. #ifdef ENVCUBEMAP
  47. varying vec3 vReflectionVec;
  48. #endif
  49. #if defined(LIGHTMAP) || defined(AO)
  50. varying vec2 vTexCoord2;
  51. #endif
  52. #endif
  53. void VS()
  54. {
  55. mat4 modelMatrix = iModelMatrix;
  56. vec3 worldPos = GetWorldPos(modelMatrix);
  57. #ifdef WINDSTEMAXIS
  58. float stemDistance = dot(iPos.xyz, cWindStemAxis);
  59. #else
  60. float stemDistance = iPos.y;
  61. #endif
  62. float windStrength = max(stemDistance - cWindHeightPivot, 0.0) * cWindHeightFactor;
  63. float windPeriod = cElapsedTime * cWindPeriod + dot(worldPos.xz, cWindWorldSpacing);
  64. worldPos.x += windStrength * sin(windPeriod);
  65. worldPos.z -= windStrength * cos(windPeriod);
  66. gl_Position = GetClipPos(worldPos);
  67. vNormal = GetWorldNormal(modelMatrix);
  68. vWorldPos = vec4(worldPos, GetDepth(gl_Position));
  69. #ifdef VERTEXCOLOR
  70. vColor = iColor;
  71. #endif
  72. #if defined(NORMALMAP) || defined(DIRBILLBOARD)
  73. vec4 tangent = GetWorldTangent(modelMatrix);
  74. vec3 bitangent = cross(tangent.xyz, vNormal) * tangent.w;
  75. vTexCoord = vec4(GetTexCoord(iTexCoord), bitangent.xy);
  76. vTangent = vec4(tangent.xyz, bitangent.z);
  77. #else
  78. vTexCoord = GetTexCoord(iTexCoord);
  79. #endif
  80. #ifdef PERPIXEL
  81. // Per-pixel forward lighting
  82. vec4 projWorldPos = vec4(worldPos, 1.0);
  83. #ifdef SHADOW
  84. // Shadow projection: transform from world space to shadow space
  85. for (int i = 0; i < NUMCASCADES; i++)
  86. vShadowPos[i] = GetShadowPos(i, vNormal, projWorldPos);
  87. #endif
  88. #ifdef SPOTLIGHT
  89. // Spotlight projection: transform from world space to projector texture coordinates
  90. vSpotPos = projWorldPos * cLightMatrices[0];
  91. #endif
  92. #ifdef POINTLIGHT
  93. vCubeMaskVec = (worldPos - cLightPos.xyz) * mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz);
  94. #endif
  95. #else
  96. // Ambient & per-vertex lighting
  97. #if defined(LIGHTMAP) || defined(AO)
  98. // If using lightmap, disregard zone ambient light
  99. // If using AO, calculate ambient in the PS
  100. vVertexLight = vec3(0.0, 0.0, 0.0);
  101. vTexCoord2 = iTexCoord1;
  102. #else
  103. vVertexLight = GetAmbient(GetZonePos(worldPos));
  104. #endif
  105. #ifdef NUMVERTEXLIGHTS
  106. for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
  107. vVertexLight += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;
  108. #endif
  109. vScreenPos = GetScreenPos(gl_Position);
  110. #ifdef ENVCUBEMAP
  111. vReflectionVec = worldPos - cCameraPos;
  112. #endif
  113. #endif
  114. }