bump.glsl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //@renderpasses 0,1,2
  2. varying vec2 v_TexCoord0;
  3. varying mat2 v_TanMatrix;
  4. varying vec4 v_Color;
  5. //@vertex
  6. attribute vec4 a_Position;
  7. attribute vec2 a_TexCoord0;
  8. attribute vec2 a_TexCoord1;
  9. attribute vec4 a_Color;
  10. uniform mat4 r_ModelViewProjectionMatrix;
  11. uniform vec4 r_AmbientLight;
  12. uniform vec4 m_ImageColor;
  13. void main(){
  14. v_TexCoord0=a_TexCoord0;
  15. #if MX2_RENDERPASS==2
  16. v_TanMatrix=mat2( a_TexCoord1.x,a_TexCoord1.y,-a_TexCoord1.y,a_TexCoord1.x );
  17. #endif
  18. #if MX2_RENDERPASS==0
  19. v_Color=r_AmbientLight * m_ImageColor * a_Color;
  20. #else
  21. v_Color=m_ImageColor * a_Color;
  22. #endif
  23. gl_Position=r_ModelViewProjectionMatrix * a_Position;
  24. }
  25. //@fragment
  26. uniform sampler2D m_ImageTexture0;
  27. uniform sampler2D m_ImageTexture1;
  28. void main(){
  29. vec4 diffuse=texture2D( m_ImageTexture0,v_TexCoord0 ) * v_Color;
  30. #if MX2_RENDERPASS==0 //ambient
  31. gl_FragColor=diffuse;
  32. #elif MX2_RENDERPASS==1 //diffuse
  33. gl_FragColor=diffuse;
  34. #elif MX2_RENDERPASS==2 //normal
  35. vec3 normal=texture2D( m_ImageTexture1,v_TexCoord0 ).xyz;
  36. normal.xy=v_TanMatrix * (normal.xy * 2.0 - 1.0) * 0.5 + 0.5;
  37. gl_FragColor=vec4( normal*diffuse.a,diffuse.a );
  38. #endif
  39. }