You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.9 KiB

  1. ///////////////////////////////////////////////////////////
  2. // Attributes
  3. attribute vec3 a_position;
  4. attribute vec2 a_texCoord;
  5. attribute vec4 a_color;
  6. ///////////////////////////////////////////////////////////
  7. // Uniforms
  8. uniform mat4 u_projectionMatrix;
  9. ///////////////////////////////////////////////////////////
  10. // Varyings
  11. varying vec2 v_texCoord;
  12. varying vec4 v_color;
  13. #if defined(TEXTURE_REPEAT)
  14. uniform vec2 u_textureRepeat;
  15. #endif
  16. #if defined(TEXTURE_OFFSET)
  17. uniform vec2 u_textureOffset;
  18. #endif
  19. #if defined(NO_Z_FIGHTING)
  20. // Éî¶ÈÆ«ÒÆÖµ
  21. uniform float u_depthOffset;
  22. #endif
  23. varying float v_fogFactor; //fog factor
  24. //fog parameter
  25. uniform vec4 u_fogparam; // .x, .y, .z, .w stand for fog density, fog start, fog end, fog type. fog type 0, no fog, fog type 1 linear fog, fog type 2 exp fog, fog type 3 exp2 fog
  26. void main()
  27. {
  28. gl_Position = u_projectionMatrix * vec4(a_position, 1);
  29. v_texCoord = a_texCoord;
  30. v_color = a_color;
  31. #if defined(NO_Z_FIGHTING)
  32. gl_Position.z -= u_depthOffset;
  33. #endif
  34. #if defined(TEXTURE_REPEAT)
  35. v_texCoord *= u_textureRepeat;
  36. #endif
  37. #if defined(TEXTURE_OFFSET)
  38. v_texCoord += u_textureOffset;
  39. #endif
  40. #if defined(FOG)
  41. // linear fog
  42. #if FOG == 1
  43. float z = gl_Position.z;//(u_worldViewMatrix * position).z;
  44. v_fogFactor = (u_fogparam.z - z) / (u_fogparam.z - u_fogparam.y);
  45. v_fogFactor = clamp(v_fogFactor, 0.0, 1.0);
  46. // exp fog
  47. #elif FOG == 2
  48. float z = gl_Position.z;//(u_worldViewMatrix * position).z;
  49. const float LOG2 = 1.442695;
  50. v_fogFactor = exp2( -u_fogparam.x *
  51. z *
  52. LOG2 );
  53. v_fogFactor = clamp(v_fogFactor, 0.0, 1.0);
  54. // exp2 fog
  55. #elif FOG == 3
  56. float z = gl_Position.z;//(u_worldViewMatrix * position).z;
  57. const float LOG2 = 1.442695;
  58. v_fogFactor = exp2( -u_fogparam.x *
  59. u_fogparam.x *
  60. z *
  61. z *
  62. LOG2 );
  63. v_fogFactor = clamp(v_fogFactor, 0.0, 1.0);
  64. #endif
  65. #endif
  66. }