ccShader_3D_Terrain.frag 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const char* cc3D_Terrain_frag = R"(
  2. #ifdef GL_ES
  3. precision mediump float;
  4. #endif
  5. uniform vec3 u_color;
  6. varying vec2 v_texCoord;
  7. varying vec3 v_normal;
  8. #ifdef GL_ES
  9. uniform lowp int u_has_alpha;
  10. uniform lowp int u_has_light_map;
  11. #else
  12. uniform int u_has_alpha;
  13. uniform int u_has_light_map;
  14. #endif
  15. uniform sampler2D u_alphaMap;
  16. uniform sampler2D u_texture0;
  17. uniform sampler2D u_texture1;
  18. uniform sampler2D u_texture2;
  19. uniform sampler2D u_texture3;
  20. uniform sampler2D u_lightMap;
  21. uniform float u_detailSize[4];
  22. uniform vec3 u_lightDir;
  23. void main()
  24. {
  25. vec4 lightColor;
  26. if(u_has_light_map<=0)
  27. {
  28. lightColor = vec4(1.0,1.0,1.0,1.0);
  29. }else
  30. {
  31. lightColor = texture2D(u_lightMap,v_texCoord);
  32. }
  33. float lightFactor = dot(-u_lightDir,v_normal);
  34. if(u_has_alpha<=0)
  35. {
  36. gl_FragColor = texture2D(u_texture0, v_texCoord)*lightColor*lightFactor;
  37. }else
  38. {
  39. vec4 blendFactor =texture2D(u_alphaMap,v_texCoord);
  40. vec4 color = vec4(0.0,0.0,0.0,0.0);
  41. color = texture2D(u_texture0, v_texCoord*u_detailSize[0])*blendFactor.r +
  42. texture2D(u_texture1, v_texCoord*u_detailSize[1])*blendFactor.g + texture2D(u_texture2, v_texCoord*u_detailSize[2])*blendFactor.b
  43. + texture2D(u_texture3, v_texCoord*u_detailSize[3])*(1.0 - blendFactor.a);
  44. gl_FragColor = vec4(color.rgb*lightColor.rgb*lightFactor, 1.0);
  45. }
  46. }
  47. )";