textured.frag 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifdef OPENGL_ES
  2. #ifdef GL_FRAGMENT_PRECISION_HIGH
  3. precision highp float;
  4. #else
  5. precision mediump float;
  6. #endif
  7. #endif
  8. #ifndef DIRECTIONAL_LIGHT_COUNT
  9. #define DIRECTIONAL_LIGHT_COUNT 0
  10. #endif
  11. #ifndef SPOT_LIGHT_COUNT
  12. #define SPOT_LIGHT_COUNT 0
  13. #endif
  14. #ifndef POINT_LIGHT_COUNT
  15. #define POINT_LIGHT_COUNT 0
  16. #endif
  17. #if (DIRECTIONAL_LIGHT_COUNT > 0) || (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)
  18. #define LIGHTING
  19. #endif
  20. ///////////////////////////////////////////////////////////
  21. // Uniforms
  22. uniform vec3 u_ambientColor;
  23. uniform sampler2D u_diffuseTexture;
  24. #if defined(LIGHTMAP)
  25. uniform sampler2D u_lightmapTexture;
  26. #endif
  27. #if defined(LIGHTING)
  28. #if defined(BUMPED)
  29. uniform sampler2D u_normalmapTexture;
  30. #endif
  31. #if (DIRECTIONAL_LIGHT_COUNT > 0)
  32. uniform vec3 u_directionalLightColor[DIRECTIONAL_LIGHT_COUNT];
  33. #if !defined(BUMPED)
  34. uniform vec3 u_directionalLightDirection[DIRECTIONAL_LIGHT_COUNT];
  35. #endif
  36. #endif
  37. #if (POINT_LIGHT_COUNT > 0)
  38. uniform vec3 u_pointLightColor[POINT_LIGHT_COUNT];
  39. uniform vec3 u_pointLightPosition[POINT_LIGHT_COUNT];
  40. uniform float u_pointLightRangeInverse[POINT_LIGHT_COUNT];
  41. #endif
  42. #if (SPOT_LIGHT_COUNT > 0)
  43. uniform vec3 u_spotLightColor[SPOT_LIGHT_COUNT];
  44. uniform float u_spotLightRangeInverse[SPOT_LIGHT_COUNT];
  45. uniform float u_spotLightInnerAngleCos[SPOT_LIGHT_COUNT];
  46. uniform float u_spotLightOuterAngleCos[SPOT_LIGHT_COUNT];
  47. #if !defined(BUMPED)
  48. uniform vec3 u_spotLightDirection[SPOT_LIGHT_COUNT];
  49. #endif
  50. #endif
  51. #if defined(SPECULAR)
  52. uniform float u_specularExponent;
  53. #endif
  54. #endif
  55. #if defined(MODULATE_COLOR)
  56. uniform vec4 u_modulateColor;
  57. #endif
  58. #if defined(MODULATE_ALPHA)
  59. uniform float u_modulateAlpha;
  60. #endif
  61. ///////////////////////////////////////////////////////////
  62. // Variables
  63. vec4 _baseColor;
  64. ///////////////////////////////////////////////////////////
  65. // Varyings
  66. varying vec2 v_texCoord;
  67. #if defined(LIGHTMAP)
  68. varying vec2 v_texCoord1;
  69. #endif
  70. #if defined(LIGHTING)
  71. #if !defined(BUMPED)
  72. varying vec3 v_normalVector;
  73. #endif
  74. #if defined(BUMPED) && (DIRECTIONAL_LIGHT_COUNT > 0)
  75. varying vec3 v_directionalLightDirection[DIRECTIONAL_LIGHT_COUNT];
  76. #endif
  77. #if (POINT_LIGHT_COUNT > 0)
  78. varying vec3 v_vertexToPointLightDirection[POINT_LIGHT_COUNT];
  79. #endif
  80. #if (SPOT_LIGHT_COUNT > 0)
  81. varying vec3 v_vertexToSpotLightDirection[SPOT_LIGHT_COUNT];
  82. #if defined(BUMPED)
  83. varying vec3 v_spotLightDirection[SPOT_LIGHT_COUNT];
  84. #endif
  85. #endif
  86. #if defined(SPECULAR)
  87. varying vec3 v_cameraDirection;
  88. #endif
  89. #include "lighting.frag"
  90. #endif
  91. #if defined(CLIP_PLANE)
  92. varying float v_clipDistance;
  93. #endif
  94. void main()
  95. {
  96. #if defined(CLIP_PLANE)
  97. if(v_clipDistance < 0.0) discard;
  98. #endif
  99. _baseColor = texture2D(u_diffuseTexture, v_texCoord);
  100. gl_FragColor.a = _baseColor.a;
  101. #if defined(TEXTURE_DISCARD_ALPHA)
  102. if (gl_FragColor.a < 0.5)
  103. discard;
  104. #endif
  105. #if defined(LIGHTING)
  106. gl_FragColor.rgb = getLitPixel();
  107. #else
  108. gl_FragColor.rgb = _baseColor.rgb;
  109. #endif
  110. #if defined(LIGHTMAP)
  111. vec4 lightColor = texture2D(u_lightmapTexture, v_texCoord1);
  112. gl_FragColor.rgb *= lightColor.rgb;
  113. #endif
  114. #if defined(MODULATE_COLOR)
  115. gl_FragColor *= u_modulateColor;
  116. #endif
  117. #if defined(MODULATE_ALPHA)
  118. gl_FragColor.a *= u_modulateAlpha;
  119. #endif
  120. }