Advertisement
Guest User

Untitled

a guest
Dec 13th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. uniform sampler2D baseTexture;
  2. uniform sampler2D normalTexture;
  3. uniform sampler2D useNormalmap;
  4.  
  5. uniform vec4 skyBgColor;
  6. uniform float fogDistance;
  7. uniform vec3 eyePosition;
  8.  
  9. varying vec3 vPosition;
  10. varying vec3 eyeVec;
  11.  
  12. #ifdef ENABLE_PARALLAX_OCCLUSION
  13. varying vec3 tsEyeVec;
  14. #endif
  15.  
  16. float intensity (vec3 color){
  17. return (color.r + color.g + color.b) / 3.0;
  18. }
  19.  
  20. const float e = 2.718281828459;
  21.  
  22. void main (void)
  23. {
  24. vec3 color;
  25. vec2 uv = gl_TexCoord[0].st;
  26.  
  27. #ifdef USE_NORMALMAPS
  28. float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;
  29. #endif
  30.  
  31.  
  32.  
  33. /* Steep parallax code, for future use
  34. if ((parallaxMappingMode == 2.0) && (use_normalmap > 0.0)) {
  35. const float numSteps = 40.0;
  36. float height = 1.0;
  37. float step = 1.0 / numSteps;
  38. vec4 NB = texture2D(normalTexture, uv);
  39. vec2 delta = tsEye * parallaxMappingScale / numSteps;
  40. for (float i = 0.0; i < numSteps; i++) {
  41. if (NB.a < height) {
  42. height -= step;
  43. uv += delta;
  44. NB = texture2D(normalTexture, uv);
  45. } else {
  46. break;
  47. }
  48. }
  49. }
  50. */
  51.  
  52. #ifdef ENABLE_BUMPMAPPING
  53.  
  54. float ps = 1 / 16.0;
  55. float step = 1 / 16.0 / 16.0;
  56. float strength = 4.0;
  57. float sx = (abs(fract(uv.x / ps) * 2.0 - 1.0));
  58. float sy = (abs(fract(uv.y / ps) * 2.0 - 1.0));
  59.  
  60. float tl = intensity(texture2D(baseTexture, vec2(uv.x-step,uv.y+step)).rgb);
  61. float t = intensity(texture2D(baseTexture, vec2(uv.x,uv.y-step)).rgb);
  62. float tr = intensity(texture2D(baseTexture, vec2(uv.x+step,uv.y+step)).rgb);
  63. float r = intensity(texture2D(baseTexture, vec2(uv.x+step,uv.y)).rgb);
  64. float br = intensity(texture2D(baseTexture, vec2(uv.x+step,uv.y-step)).rgb);
  65. float b = intensity(texture2D(baseTexture, vec2(uv.x,uv.y-step)).rgb);
  66. float bl = intensity(texture2D(baseTexture, vec2(uv.x-step,uv.y-step)).rgb);
  67. float l = intensity(texture2D(baseTexture, vec2(uv.x-step,uv.y)).rgb);
  68.  
  69. float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl);
  70. float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr);
  71. float dZ = 1.0 / (strength);
  72. //float dZ = 0.5 * sqrt( 1.0 - dX * dX - dY * dY );
  73.  
  74. vec3 bump = normalize(vec3 (dX, dY, dZ));
  75.  
  76. if (1) {
  77. vec3 base = texture2D(baseTexture, uv).rgb;
  78. vec3 vVec = normalize(eyeVec);
  79. //vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);
  80. vec3 R = reflect(-vVec, bump);
  81. vec3 lVec = normalize(vVec);
  82. float diffuse = max(dot(lVec, bump), 0.0);
  83. float specular = pow(clamp(dot(R, lVec), 0.0, 1.0),1.0);
  84. color = mix (base,diffuse*base,1.0) + 0.1 * specular * diffuse;
  85. } else {
  86. color = texture2D(baseTexture, uv).rgb;
  87. }
  88. #else
  89. color = texture2D(baseTexture, uv).rgb;
  90. #endif
  91.  
  92. float alpha = texture2D(baseTexture, uv).a;
  93. vec4 col = vec4(color.r, color.g, color.b, alpha);
  94. col *= gl_Color;
  95. col = col * col; // SRGB -> Linear
  96. col *= 1.8;
  97. col.r = 1.0 - exp(1.0 - col.r) / e;
  98. col.g = 1.0 - exp(1.0 - col.g) / e;
  99. col.b = 1.0 - exp(1.0 - col.b) / e;
  100. col = sqrt(col); // Linear -> SRGB
  101. if(fogDistance != 0.0){
  102. float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
  103. col = mix(col, skyBgColor, d);
  104. }
  105. gl_FragColor = vec4(col.r, col.g, col.b, alpha);
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement