VertShader.vsh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. attribute highp vec3 inVertex;
  2. uniform highp mat4 ModelViewMatrix;
  3. uniform highp mat4 MVPMatrix;
  4. uniform highp vec3 EyePosition; // Eye (aka Camera) positon in model-space
  5. uniform mediump vec2 BumpTranslation0;
  6. uniform mediump vec2 BumpScale0;
  7. uniform mediump vec2 BumpTranslation1;
  8. uniform mediump vec2 BumpScale1;
  9. uniform highp float PerturbScale;
  10. varying mediump vec2 BumpCoord0;
  11. varying mediump vec2 BumpCoord1;
  12. varying mediump vec3 WaterToEye;
  13. varying mediump float WaterToEyeLength;
  14. void main()
  15. {
  16. // Convert each vertex into projection-space and output the value
  17. highp vec4 vInVertex = vec4(inVertex, 1.0);
  18. gl_Position = MVPMatrix * vInVertex;
  19. // The texture coordinate is calculated this way to reduce the number of attributes needed
  20. mediump vec2 vTexCoord = inVertex.xz;
  21. // Scale and translate texture coordinates used to sample the normal map - section 2.2 of white paper
  22. BumpCoord0 = vTexCoord.xy * BumpScale0;
  23. BumpCoord0 += BumpTranslation0;
  24. BumpCoord1 = vTexCoord.xy * BumpScale1;
  25. BumpCoord1 += BumpTranslation1;
  26. /*
  27. The water to eye vector is used to calculate the Fresnel term
  28. and to fade out perturbations based on distance from the viewer
  29. */
  30. WaterToEye = EyePosition - inVertex;
  31. WaterToEyeLength = length(WaterToEye);
  32. }