Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. #ifdef FLAG_DIFFUSE_MAP
  2. uniform sampler2D sBasemap;
  3. #endif
  4.  
  5. #ifdef FLAG_GLOW_MAP
  6. uniform sampler2D sGlowmap;
  7. #endif
  8.  
  9. #ifdef FLAG_SPEC_MAP
  10. uniform sampler2D sSpecmap;
  11. #endif
  12.  
  13. #ifdef FLAG_ENV_MAP
  14. uniform samplerCube sEnvmap;
  15. uniform bool alpha_spec;
  16. out vec3 envReflect;
  17. #endif
  18.  
  19. #ifdef FLAG_NORMAL_MAP
  20. uniform sampler2D sNormalmap;
  21. out mat3 tbnMatrix;
  22. #endif
  23.  
  24. #ifdef FLAG_FOG
  25. out float fogDist;
  26. #endif
  27.  
  28. in vec3 Surface_normal;
  29. in vec4 Position;
  30.  
  31. out vec4 Diffuse_color = vec4(0.0, 0.0, 0.0, 1.0);
  32. out vec4 Surface_Normal = vec4(0.0, 0.0, 0.0, 1.0);
  33. out vec4 Specular_color = vec4(0.0, 0.0, 0.0, 1.0);
  34. out vec4 Glow_color = vec4(0.0, 0.0, 0.0, 1.0);
  35.  
  36. #define SPECULAR_FACTOR 1.75
  37. #define SPECULAR_ALPHA 0.1
  38. #define SPEC_FACTOR_NO_SPEC_MAP 0.6
  39. #define ENV_ALPHA_FACTOR 0.3
  40. #define GLOW_MAP_INTENSITY 1.5
  41. #define AMBIENT_LIGHT_BOOST 1.0
  42.  
  43. void main() {
  44. vec2 texCoord = gl_TexCoord[0].xy;
  45.  
  46. #ifdef FLAG_NORMAL_MAP
  47. // Normal map - convert from DXT5nm
  48. vec3 normal;
  49.  
  50. normal.rg = (texture2D(sNormalmap, texCoord).ag * 2.0) - 1.0;
  51. #ifdef FLAG_ENV_MAP
  52. vec3 envOffset = vec3(0.0);
  53. envOffset.xy = normal.xy;
  54. #endif
  55. normal.b = sqrt(1.0 - dot(normal.rg, normal.rg));
  56. normal = normalize(tbnMatrix * normal);
  57. #else
  58. vec3 normal = lNormal;
  59. #endif
  60.  
  61. //Write result to normal buffer
  62. Surface_Normal = vec4(normal, 1.0);
  63.  
  64. //Write diffuse color to difuse buffer
  65. #ifdef FLAG_DIFFUSE_MAP
  66. Diffuse_color = texture2D(sBasemap, texCoord);
  67. #else
  68. Diffuse_color = gl_Color;
  69. #endif
  70.  
  71. //Write glow color to glow buffer
  72. #ifdef FLAG_GLOW_MAP
  73. Glow_Color = texture2D(sGlowmap, texCoord).rgb * GLOW_MAP_INTENSITY;
  74. #endif
  75.  
  76. //Write spec color to spec buffer
  77. #ifdef FLAG_SPEC_MAP
  78. Specular_color.rgb += lightSpecular.rgb * (texture2D(sSpecmap, texCoord).rgb * SPECULAR_FACTOR);
  79. Specular_color.a += (dot(lightSpecular.a, lightSpecular.a) * SPECULAR_ALPHA);
  80. #else
  81. Specular_color.rgb += lightSpecular.rgb * (baseColor.rgb * SPEC_FACTOR_NO_SPEC_MAP);
  82. #endif
  83.  
  84. //Write env color to spec as well
  85. #ifdef FLAG_ENV_MAP
  86. // Env color
  87. #ifdef FLAG_NORMAL_MAP
  88. vec3 envReflectNM = envReflect + envOffset;
  89. vec3 envIntensity = (alpha_spec) ? vec3(texture2D(sSpecmap, texCoord).a) : texture2D(sSpecmap, texCoord).rgb;
  90. Specular_color.a += (dot(textureCube(sEnvmap, envReflectNM).rgb, textureCube(sEnvmap, envReflectNM).rgb) * ENV_ALPHA_FACTOR);
  91. Specular_color.rgb += textureCube(sEnvmap, envReflectNM).rgb * envIntensity;
  92. #else
  93. vec3 envIntensity = (alpha_spec) ? vec3(texture2D(sSpecmap, texCoord).a) : texture2D(sSpecmap, texCoord).rgb;
  94. Specular_color.a += (dot(textureCube(sEnvmap, envReflect).rgb, textureCube(sEnvmap, envReflect).rgb) * ENV_ALPHA_FACTOR);
  95. Specular_color.rgb += textureCube(sEnvmap, envReflect).rgb * envIntensity;
  96. #endif
  97. #endif
  98.  
  99. //Mix fog into diffuse
  100. #ifdef FLAG_FOG
  101. Diffuse_color.rgb = mix(Diffuse_color.rgb, gl_Fog.color.rgb, fogDist);
  102. #endif
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement