bump.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. tanMatrix=mat2( mx2_TexCoord1.x,mx2_TexCoord1.y,-mx2_TexCoord1.y,mx2_TexCoord1.x );
  16. #if MX2_RENDERPASS==0
  17. color=mx2_AmbientLight * mx2_ImageColor * mx2_Color;
  18. #else
  19. color=mx2_ImageColor * mx2_Color;
  20. #endif
  21. gl_Position=mx2_ModelViewProjectionMatrix * mx2_Vertex;
  22. }
  23. //@fragment
  24. uniform sampler2D mx2_ImageTexture0;
  25. uniform sampler2D mx2_ImageTexture1;
  26. void main(){
  27. vec4 diffuse=texture2D( mx2_ImageTexture0,texCoord0 ) * color;
  28. #if MX2_RENDERPASS==0 //ambient
  29. gl_FragColor=diffuse;
  30. #elif MX2_RENDERPASS==1 //diffuse
  31. gl_FragColor=diffuse;
  32. #elif MX2_RENDERPASS==2 //normal
  33. vec3 normal=texture2D( mx2_ImageTexture1,texCoord0 ).xyz;
  34. normal.xy=tanMatrix * (normal.xy * 2.0 - 1.0) * diffuse.a * 0.5 + 0.5;
  35. normal.z*=diffuse.a;
  36. gl_FragColor=vec4( normal,diffuse.a );
  37. #endif
  38. }