opengl_vertex.glsl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. uniform mat4 mWorld;
  2. uniform vec3 eyePosition;
  3. uniform float animationTimer;
  4. varying vec3 vNormal;
  5. varying vec3 vPosition;
  6. varying vec3 worldPosition;
  7. varying lowp vec4 varColor;
  8. #ifdef GL_ES
  9. varying mediump vec2 varTexCoord;
  10. #else
  11. centroid varying vec2 varTexCoord;
  12. #endif
  13. varying vec3 eyeVec;
  14. varying float vIDiff;
  15. const float e = 2.718281828459;
  16. const float BS = 10.0;
  17. float directional_ambient(vec3 normal)
  18. {
  19. vec3 v = normal * normal;
  20. if (normal.y < 0.0)
  21. return dot(v, vec3(0.670820, 0.447213, 0.836660));
  22. return dot(v, vec3(0.670820, 1.000000, 0.836660));
  23. }
  24. void main(void)
  25. {
  26. varTexCoord = (mTexture * inTexCoord0).st;
  27. gl_Position = mWorldViewProj * inVertexPosition;
  28. vPosition = gl_Position.xyz;
  29. vNormal = inVertexNormal;
  30. worldPosition = (mWorld * inVertexPosition).xyz;
  31. eyeVec = -(mWorldView * inVertexPosition).xyz;
  32. #if (MATERIAL_TYPE == TILE_MATERIAL_PLAIN) || (MATERIAL_TYPE == TILE_MATERIAL_PLAIN_ALPHA)
  33. vIDiff = 1.0;
  34. #else
  35. // This is intentional comparison with zero without any margin.
  36. // If normal is not equal to zero exactly, then we assume it's a valid, just not normalized vector
  37. vIDiff = length(inVertexNormal) == 0.0
  38. ? 1.0
  39. : directional_ambient(normalize(inVertexNormal));
  40. #endif
  41. varColor = inVertexColor;
  42. }