Guest User

Untitled

a guest
May 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. #version 120
  2.  
  3. /* Here, intervalMult might need to be tweaked per texture pack.
  4. The first two numbers determine how many samples are taken per fragment. They should always be the equal to eachother.
  5. The third number divided by one of the first two numbers is inversely proportional to the range of the height-map. */
  6.  
  7. const vec3 intervalMult = vec3(0.0039, 0.0039, 4.5); //const vec3 intervalMult = vec3(0.0039, 0.0039, 4.5); // Fine for 16x16 tile size //const vec3 intervalMult = vec3(0.0019, 0.0019, 0.5); // Fine for 32x32 tile size //const vec3 intervalMult = vec3(0.0009765625, 0.0009765625, 0.145); // Fine (presumably) for 64x64 //const vec3 intervalMult = vec3(0.00048828125, 0.00048828125, 0.2); // Fine for 128x128 tile size const vec3 intervalMult = vec3(0.000244140625, 0.000244140625, 0.1);// Fine for 256x256 tile size
  8.  
  9. uniform sampler2D texture;
  10. uniform sampler2D lightmap;
  11. uniform sampler2D normals;
  12. uniform sampler2D specular;
  13.  
  14. varying vec4 color;
  15. varying vec4 texcoord;
  16. varying vec4 lmcoord;
  17.  
  18. varying vec3 viewVector;
  19.  
  20. varying vec3 normal;
  21. varying vec3 tangent;
  22. varying vec3 binormal;
  23.  
  24. varying float distance;
  25.  
  26. const float MAX_OCCLUSION_DISTANCE = 100.0;
  27.  
  28. const int MAX_OCCLUSION_POINTS = 50;
  29.  
  30. const int GL_LINEAR = 9729;
  31. const int GL_EXP = 2048;
  32.  
  33. uniform int fogMode;
  34.  
  35. void main() {
  36. gl_FragData[1] = vec4(vec3(gl_FragCoord.z), 1.0);
  37.  
  38. vec2 adjustedTexCoord = texcoord.st;
  39.  
  40. if (distance <= MAX_OCCLUSION_DISTANCE && viewVector.z < 0.0) {
  41. vec3 coord = vec3(texcoord.st, 1.0);
  42.  
  43. if (texture2D(normals, coord.st).a < 1.0) {
  44. vec2 minCoord = vec2(texcoord.s - mod(texcoord.s, 0.0625), texcoord.t - mod(texcoord.t, 0.0625));
  45. vec2 maxCoord = vec2(minCoord.s + 0.0625, minCoord.t + 0.0625);
  46.  
  47. vec3 interval = viewVector * intervalMult;
  48.  
  49. for (int loopCount = 0; texture2D(normals, coord.st).a < coord.z && loopCount < MAX_OCCLUSION_POINTS; ++loopCount) {
  50. coord += interval;
  51. if (coord.s < minCoord.s) {
  52. coord.s += 0.0625;
  53. } else if (coord.s >= maxCoord.s) {
  54. coord.s -= 0.0625;
  55. }
  56. if (coord.t < minCoord.t) {
  57. coord.t += 0.0625;
  58. } else if (coord.t >= maxCoord.t) {
  59. coord.t -= 0.0625;
  60. }
  61. }
  62. }
  63.  
  64. adjustedTexCoord = coord.st;
  65. }
  66.  
  67. gl_FragData[0] = texture2D(texture, adjustedTexCoord.st) * texture2D(lightmap, lmcoord.st) * color;
  68.  
  69. vec3 bump = texture2D(normals, adjustedTexCoord.st).xyz * 2.0 - 1.0;
  70.  
  71. mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
  72. tangent.y, binormal.y, normal.y,
  73. tangent.z, binormal.z, normal.z);
  74.  
  75. gl_FragData[2] = vec4(bump * tbnMatrix * 0.5 + 0.5, 1.0);
  76.  
  77. gl_FragData[4] = vec4(texture2D(specular, adjustedTexCoord.st).rgb, 1.0);
  78.  
  79. if (fogMode == GL_EXP) {
  80. gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb, 1.0 - clamp(exp(-gl_Fog.density * gl_FogFragCoord), 0.0, 1.0));
  81. } else if (fogMode == GL_LINEAR) {
  82. gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb, clamp((gl_FogFragCoord - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0));
  83. }
  84. }
Add Comment
Please, Sign In to add comment