bump.glsl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //@renderpasses 0,1,2
  2. varying vec2 texCoord0;
  3. varying mat2 tanMatrix;
  4. varying vec4 color;
  5. //@vertex
  6. attribute vec4 mx2_Vertex;
  7. attribute vec2 mx2_TexCoord0;
  8. attribute vec2 mx2_TexCoord1;
  9. attribute vec4 mx2_Color;
  10. uniform mat4 mx2_ModelViewProjectionMatrix;
  11. uniform vec4 mx2_AmbientLight;
  12. uniform vec4 mx2_ImageColor;
  13. void main(){
  14. texCoord0=mx2_TexCoord0;
  15. #if MX2_RENDERPASS==2
  16. tanMatrix=mat2( mx2_TexCoord1.x,mx2_TexCoord1.y,-mx2_TexCoord1.y,mx2_TexCoord1.x );
  17. #endif
  18. #if MX2_RENDERPASS==0
  19. color=mx2_AmbientLight * mx2_ImageColor * mx2_Color;
  20. #else
  21. color=mx2_ImageColor * mx2_Color;
  22. #endif
  23. gl_Position=mx2_ModelViewProjectionMatrix * mx2_Vertex;
  24. }
  25. //@fragment
  26. uniform sampler2D mx2_ImageTexture0;
  27. uniform sampler2D mx2_ImageTexture1;
  28. void main(){
  29. vec4 diffuse=texture2D( mx2_ImageTexture0,texCoord0 ) * 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( mx2_ImageTexture1,texCoord0 ).xyz;
  36. normal.xy=tanMatrix * (normal.xy * 2.0 - 1.0) * 0.5 + 0.5;
  37. gl_FragColor=vec4( normal*diffuse.a,diffuse.a );
  38. #endif
  39. }