pbr-default.glsl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //@renderpasses 1,7,11,2,6,10
  2. //@import "pbr"
  3. //@vertex
  4. void main(){
  5. transformVertex();
  6. }
  7. //@fragment
  8. #if MX2_COLORPASS //is this a color pass?
  9. #if MX2_TEXTURED
  10. uniform sampler2D m_ColorTexture;
  11. uniform sampler2D m_AmbientTexture;
  12. uniform sampler2D m_EmissiveTexture;
  13. uniform sampler2D m_MetalnessTexture;
  14. uniform sampler2D m_RoughnessTexture;
  15. uniform sampler2D m_OcclusionTexture;
  16. #if MX2_BUMPMAPPED
  17. uniform sampler2D m_NormalTexture;
  18. #endif
  19. #endif
  20. uniform vec4 m_ColorFactor;
  21. uniform vec4 m_AmbientFactor;
  22. uniform vec4 m_EmissiveFactor;
  23. uniform float m_MetalnessFactor;
  24. uniform float m_RoughnessFactor;
  25. void main(){
  26. #if MX2_TEXTURED
  27. vec4 color=texture2D( m_ColorTexture,v_TexCoord0 );
  28. color.rgb=pow( color.rgb,vec3( 2.2 ) );
  29. color*=m_ColorFactor;
  30. vec3 ambient=pow( texture2D( m_AmbientTexture,v_TexCoord1 ).rgb,vec3( 2.2 ) ) * m_AmbientFactor.rgb;
  31. vec3 emissive=pow( texture2D( m_EmissiveTexture,v_TexCoord0 ).rgb,vec3( 2.2 ) ) * m_EmissiveFactor.rgb;
  32. float metalness=texture2D( m_MetalnessTexture,v_TexCoord0 ).b * m_MetalnessFactor;
  33. float roughness=texture2D( m_RoughnessTexture,v_TexCoord0 ).g * m_RoughnessFactor;
  34. float occlusion=texture2D( m_OcclusionTexture,v_TexCoord0 ).r;
  35. #if MX2_BUMPMAPPED
  36. vec3 normal=texture2D( m_NormalTexture,v_TexCoord0 ).xyz * 2.0 - 1.0;
  37. normal=normalize( v_TanMatrix * normal );
  38. #else
  39. vec3 normal=normalize( v_Normal );
  40. #endif
  41. #else //untextured...
  42. vec4 color=m_ColorFactor;
  43. vec3 ambient=m_AmbientFactor.rgb;
  44. vec3 emissive=m_EmissiveFactor.rgb;
  45. float metalness=m_MetalnessFactor;
  46. float roughness=m_RoughnessFactor;
  47. float occlusion=1.0;
  48. vec3 normal=normalize( v_Normal );
  49. #endif
  50. emitPbrFragment( color,ambient,emissive,metalness,roughness,occlusion,normal );
  51. }
  52. #else //if not a color pass, must be a shadow pass...
  53. void main(){
  54. emitShadowFragment();
  55. }
  56. #endif