ModelVShader.vsh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #define ENABLE_TEXTURE
  2. attribute highp vec3 inVertex;
  3. attribute highp vec3 inNormal;
  4. attribute highp vec2 inTexCoord;
  5. uniform highp mat4 MVPMatrix;
  6. uniform mediump vec3 LightDirection;
  7. #ifdef ENABLE_FOG_DEPTH
  8. uniform highp mat4 ModelMatrix;
  9. uniform mediump float WaterHeight; //Assume water always lies on the y-axis
  10. #endif
  11. #ifdef ENABLE_LIGHTING
  12. varying lowp float LightIntensity;
  13. #endif
  14. #ifdef ENABLE_TEXTURE
  15. varying mediump vec2 TexCoord;
  16. #endif
  17. #ifdef ENABLE_FOG_DEPTH
  18. varying mediump float VertexDepth;
  19. #endif
  20. void main()
  21. {
  22. // Convert each vertex into projection-space and output the value
  23. highp vec4 vInVertex = vec4(inVertex, 1.0);
  24. gl_Position = MVPMatrix * vInVertex;
  25. #ifdef ENABLE_TEXTURE
  26. TexCoord = inTexCoord;
  27. #endif
  28. #ifdef ENABLE_FOG_DEPTH
  29. // Calculate the vertex's distance under water surface. This assumes clipping has removed all objects above the water
  30. mediump float vVertexHeight = (ModelMatrix * vec4(inVertex,1.0)).y;
  31. VertexDepth = WaterHeight - vVertexHeight;
  32. #endif
  33. #ifdef ENABLE_LIGHTING
  34. // Simple diffuse lighting in model space
  35. LightIntensity = 0.3 + clamp(dot(inNormal, -LightDirection),0.0,1.0); // 0.5 is ambient light
  36. #endif
  37. }