Advertisement
Guest User

Untitled

a guest
Apr 1st, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 120
  2.  
  3. varying vec4 color;
  4. varying vec4 texcoord;
  5. varying vec4 lmcoord;
  6. varying vec3 worldPosition;
  7.  
  8.  
  9. attribute vec4 mc_Entity;
  10.  
  11. uniform int worldTime;
  12. uniform vec3 cameraPosition;
  13. uniform float frameTimeCounter;
  14. uniform float rainStrength;
  15. uniform mat4 gbufferModelView;
  16. uniform mat4 gbufferModelViewInverse;
  17. uniform mat4 shadowModelView;
  18. uniform mat4 shadowModelViewInverse;
  19. uniform mat4 gbufferProjection;
  20. uniform mat4 gbufferProjectionInverse;
  21.  
  22. uniform float aspectRatio;
  23.  
  24. uniform sampler2D noisetex;
  25.  
  26. varying vec3 normal;
  27. varying vec3 tangent;
  28. varying vec3 binormal;
  29. varying vec2 waves;
  30. varying vec3 worldNormal;
  31.  
  32. varying float distance;
  33. //varying float idCheck;
  34.  
  35. varying float materialIDs;
  36.  
  37. varying mat3 tbnMatrix;
  38. varying vec4 vertexPos;
  39. varying vec3 vertexViewVector;
  40.  
  41.  
  42. #define WAVING_GRASS
  43. #define WAVING_WHEAT
  44. //#define WAVING_LEAVES
  45.  
  46. vec4 newpos(in vec4 orig)
  47. {
  48.   //Uniform random direction using equal-area projection
  49.   float noisep = clamp(fract(sin(dot(orig ,vec4(12.9898f,78.233f,16.5f,0.0f))) * 43758.5453f),0.0f,1.0f)*6.2831853f;
  50.   float noisez = clamp(fract(sin(dot(orig, vec4(16.5f, 12.9898f,78.233f,0.0f))) * 43758.5453f),0.0f,1.0f)*2.0f-1.0f;
  51.   float k = sqrt(1-noisez*noisez);
  52.   vec4 dir = vec4(k*cos(noisep), k*sin(noisep), noisez, 0.0f);
  53.  
  54.   //Box-Muller method to generate normal variates
  55.   float noise3 = clamp(fract(sin(dot(orig, vec4(12.9898f,16.5f, 78.233f,0.0f))) * 43758.5453f),0.0f,1.0f);
  56.   float noise4 = clamp(fract(sin(dot(orig, vec4(16.6f, 16.6f,16.6f,0.0f))) * 43758.5453f),0.0f,1.0f);
  57.   float normv = sqrt(-2.0f * log(noise3)) * sin(6.2831853f*noise4);
  58.   float scale = clamp(normv*0.33f,-1.0f,1.0f)*0.7; //increase last number for greater effect
  59.   return dir*scale;
  60. }
  61.  
  62. vec4 cubic(float x)
  63. {
  64.     float x2 = x * x;
  65.     float x3 = x2 * x;
  66.     vec4 w;
  67.     w.x =   -x3 + 3*x2 - 3*x + 1;
  68.     w.y =  3*x3 - 6*x2       + 4;
  69.     w.z = -3*x3 + 3*x2 + 3*x + 1;
  70.     w.w =  x3;
  71.     return w / 6.f;
  72. }
  73.  
  74. vec4 BicubicTexture(in sampler2D tex, in vec2 coord)
  75. {
  76.     int resolution = 64;
  77.  
  78.     coord *= resolution;
  79.  
  80.     float fx = fract(coord.x);
  81.     float fy = fract(coord.y);
  82.     coord.x -= fx;
  83.     coord.y -= fy;
  84.  
  85.     vec4 xcubic = cubic(fx);
  86.     vec4 ycubic = cubic(fy);
  87.  
  88.     vec4 c = vec4(coord.x - 0.5, coord.x + 1.5, coord.y - 0.5, coord.y + 1.5);
  89.     vec4 s = vec4(xcubic.x + xcubic.y, xcubic.z + xcubic.w, ycubic.x + ycubic.y, ycubic.z + ycubic.w);
  90.     vec4 offset = c + vec4(xcubic.y, xcubic.w, ycubic.y, ycubic.w) / s;
  91.  
  92.     vec4 sample0 = texture2D(tex, vec2(offset.x, offset.z) / resolution);
  93.     vec4 sample1 = texture2D(tex, vec2(offset.y, offset.z) / resolution);
  94.     vec4 sample2 = texture2D(tex, vec2(offset.x, offset.w) / resolution);
  95.     vec4 sample3 = texture2D(tex, vec2(offset.y, offset.w) / resolution);
  96.  
  97.     float sx = s.x / (s.x + s.y);
  98.     float sy = s.z / (s.z + s.w);
  99.  
  100.     return mix( mix(sample3, sample2, sx), mix(sample1, sample0, sx), sy);
  101. }
  102.  
  103.  
  104.  
  105.  
  106. //  vec4 result = mix(texCenter, texRight, vec4(f.x));
  107. //  return result;
  108. // }
  109.  
  110.  
  111. vec4 TextureSmooth(in sampler2D tex, in vec2 coord)
  112. {
  113.     int level = 0;
  114.     vec2 res = vec2(64.0f);
  115.     coord = coord * res;
  116.     vec2 i = floor(coord);
  117.     vec2 f = fract(coord);
  118.     f = f * f * (3.0f - 2.0f * f);
  119.     //f = 1.0f - (cos(f * 3.1415f) * 0.5f + 0.5f);
  120.  
  121.     //i -= vec2(0.5f);
  122.  
  123.     vec2 icoordCenter       = i / res;
  124.     vec2 icoordRight        = (i + vec2(1.0f, 0.0f)) / res;
  125.     vec2 icoordUp           = (i + vec2(0.0f, 1.0f)) / res;
  126.     vec2 icoordUpRight      = (i + vec2(1.0f, 1.0f)) / res;
  127.  
  128.  
  129.     vec4 texCenter  = texture2DLod(tex, icoordCenter,   level);
  130.     vec4 texRight   = texture2DLod(tex, icoordRight,    level);
  131.     vec4 texUp      = texture2DLod(tex, icoordUp,       level);
  132.     vec4 texUpRight = texture2DLod(tex, icoordUpRight,  level);
  133.  
  134.     texCenter = mix(texCenter, texUp, vec4(f.y));
  135.     texRight  = mix(texRight, texUpRight, vec4(f.y));
  136.  
  137.     vec4 result = mix(texCenter, texRight, vec4(f.x));
  138.     return result;
  139. }
  140.  
  141. float Impulse(in float x, in float k)
  142. {
  143.     float h = k*x;
  144.     return pow(h*exp(1.0f-h), 5.0f);
  145. }
  146.  
  147. float RepeatingImpulse(in float x, in float scale)
  148. {
  149.     float time = x;
  150.           time = mod(time, scale);
  151.  
  152.     return Impulse(time, 3.0f / scale);
  153. }
  154.  
  155. void main() {
  156.  
  157.  
  158.  
  159.     texcoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
  160.  
  161.     lmcoord = gl_TextureMatrix[1] * gl_MultiTexCoord1;
  162.    
  163.     vec4 fg = floor(gl_Vertex);
  164.     vec4 ff = fract(gl_Vertex);
  165.     float ffl = ff.x+ff.y+ff.z;
  166.    
  167.     //Trilinear filtering from nearest integer coordinates
  168.     vec4 p1,p2,p3,p4,p5,p6,p7,p8,p12,p34,p56,p78,p1234,p5678,p12345678;
  169.    
  170.     p1 = newpos(fg);
  171.     p2 = newpos(fg + vec4(1.0f, 0.0f, 0.0f, 0.0f));
  172.     p3 = newpos(fg + vec4(0.0f, 1.0f, 0.0f, 0.0f));
  173.     p4 = newpos(fg + vec4(1.0f, 1.0f, 0.0f, 0.0f));
  174.     p5 = newpos(fg + vec4(0.0f, 0.0f, 1.0f, 0.0f));
  175.     p6 = newpos(fg + vec4(1.0f, 0.0f, 1.0f, 0.0f));
  176.     p7 = newpos(fg + vec4(0.0f, 1.0f, 1.0f, 0.0f));
  177.     p8 = newpos(fg + vec4(1.0f, 1.0f, 1.0f, 0.0f));
  178.     p12 = p1 * (1.0f-ff.x) + p2 * (ff.x);
  179.     p34 = p3 * (1.0f-ff.x) + p4 * (ff.x);
  180.     p56 = p5 * (1.0f-ff.x) + p6 * (ff.x);
  181.     p78 = p7 * (1.0f-ff.x) + p8 * (ff.x);
  182.     p1234 = p12 * (1.0f-ff.y) + p34 * (ff.y);
  183.     p5678 = p56 * (1.0f-ff.y) + p78 * (ff.y);
  184.     p12345678 = p1234 * (1.0f-ff.z) + p5678*(ff.z);
  185.    
  186.    
  187.     vec4 viewpos = gbufferModelViewInverse * gl_ModelViewMatrix * (gl_Vertex + p12345678);
  188.     vec4 position = viewpos;
  189.  
  190.     worldPosition = viewpos.xyz + cameraPosition.xyz;
  191.  
  192.    
  193.     //Entity checker
  194.     // if (mc_Entity.x == 1920.0f)
  195.     // {
  196.     //  texcoord.st = vec2(0.2f);
  197.     // }
  198.    
  199.     //Gather materials
  200.     materialIDs = 1.0f;
  201.  
  202.     //Grass
  203.     if  (  mc_Entity.x == 31.0
  204.  
  205.         || mc_Entity.x == 38.0f     //Rose
  206.         || mc_Entity.x == 37.0f     //Flower
  207.         || mc_Entity.x == 1925.0f   //Biomes O Plenty: Medium Grass
  208.         || mc_Entity.x == 1920.0f   //Biomes O Plenty: Thorns, barley
  209.         || mc_Entity.x == 1921.0f   //Biomes O Plenty: Sunflower
  210.  
  211.         )
  212.     {
  213.         materialIDs = max(materialIDs, 2.0f);
  214.     }
  215.    
  216.     //Wheat
  217.     if (mc_Entity.x == 59.0) {
  218.         materialIDs = max(materialIDs, 2.0f);
  219.     }  
  220.    
  221.     //Leaves
  222.     if   ( mc_Entity.x == 18.0
  223.  
  224.         || mc_Entity.x == 1962.0f //Biomes O Plenty: Leaves
  225.         || mc_Entity.x == 1924.0f //Biomes O Plenty: Leaves
  226.         || mc_Entity.x == 1923.0f //Biomes O Plenty: Leaves
  227.         || mc_Entity.x == 1926.0f //Biomes O Plenty: Leaves
  228.         || mc_Entity.x == 1936.0f //Biomes O Plenty: Giant Flower Leaves
  229.  
  230.          ) {
  231.         materialIDs = max(materialIDs, 3.0f);
  232.     }  
  233.  
  234.    
  235.     //Gold block
  236.     if (mc_Entity.x == 41) {
  237.         materialIDs = max(materialIDs, 20.0f);
  238.     }
  239.    
  240.     //Iron block
  241.     if (mc_Entity.x == 42) {
  242.         materialIDs = max(materialIDs, 21.0f);
  243.     }
  244.    
  245.     //Diamond Block
  246.     if (mc_Entity.x == 57) {
  247.         materialIDs = max(materialIDs, 22.0f);
  248.     }
  249.    
  250.     //Emerald Block
  251.     if (mc_Entity.x == -123) {
  252.         materialIDs = max(materialIDs, 23.0f);
  253.     }
  254.    
  255.    
  256.    
  257.     //sand
  258.     if (mc_Entity.x == 12) {
  259.         materialIDs = max(materialIDs, 24.0f);
  260.     }
  261.  
  262.     //sandstone
  263.     if (mc_Entity.x == 24 || mc_Entity.x == -128) {
  264.         materialIDs = max(materialIDs, 25.0f);
  265.     }
  266.    
  267.     //stone
  268.     if (mc_Entity.x == 1) {
  269.         materialIDs = max(materialIDs, 26.0f);
  270.     }
  271.    
  272.     //cobblestone
  273.     if (mc_Entity.x == 4) {
  274.         materialIDs = max(materialIDs, 27.0f);
  275.     }
  276.    
  277.     //wool
  278.     if (mc_Entity.x == 35) {
  279.         materialIDs = max(materialIDs, 28.0f);
  280.     }
  281.  
  282.  
  283.     //torch
  284.     if (mc_Entity.x == 50) {
  285.         materialIDs = max(materialIDs, 30.0f);
  286.     }
  287.  
  288.     //lava
  289.     if (mc_Entity.x == 10 || mc_Entity.x == 11) {
  290.         materialIDs = max(materialIDs, 31.0f);
  291.     }
  292.  
  293.     //glowstone and lamp
  294.     if (mc_Entity.x == 89 || mc_Entity.x == 124) {
  295.         materialIDs = max(materialIDs, 32.0f);
  296.     }
  297.  
  298.     //fire
  299.     if (mc_Entity.x == 51) {
  300.         materialIDs = max(materialIDs, 33.0f);
  301.     }
  302.  
  303.  
  304.  
  305.     float tick = frameTimeCounter;
  306.    
  307.    
  308. float grassWeight = mod(texcoord.t * 16.0f, 1.0f / 16.0f);
  309.  
  310. float lightWeight = clamp((lmcoord.t * 33.05f / 32.0f) - 1.05f / 32.0f, 0.0f, 1.0f);
  311.       lightWeight *= 1.1f;
  312.       lightWeight -= 0.1f;
  313.       lightWeight = max(0.0f, lightWeight);
  314.       lightWeight = pow(lightWeight, 5.0f);
  315.      
  316.       // if (texcoord.t < 0.65f) {
  317.       //    grassWeight = 1.0f;
  318.       // } else {
  319.       //    grassWeight = 0.0f;
  320.       // }   
  321.  
  322.       if (grassWeight < 0.01f) {
  323.         grassWeight = 1.0f;
  324.       } else {
  325.         grassWeight = 0.0f;
  326.       }
  327.  
  328. const float pi = 3.14159265f;
  329.  
  330. position.xyz += cameraPosition.xyz;
  331.    
  332. #ifdef WAVING_GRASS
  333.     //Waving grass
  334.     if (materialIDs == 2.0f)
  335.     {
  336.         vec2 angleLight = vec2(0.0f);
  337.         vec2 angleHeavy = vec2(0.0f);
  338.         vec2 angle      = vec2(0.0f);
  339.  
  340.         vec3 pn0 = position.xyz;
  341.              pn0.x -= frameTimeCounter / 3.0f;
  342.  
  343.         vec3 stoch = BicubicTexture(noisetex, pn0.xz / 64.0f).xyz;
  344.         vec3 stochLarge = BicubicTexture(noisetex, position.xz / (64.0f * 6.0f)).xyz;
  345.  
  346.         vec3 pn = position.xyz;
  347.              pn.x *= 2.0f;
  348.              pn.x -= frameTimeCounter * 15.0f;
  349.              pn.z *= 8.0f;
  350.  
  351.         vec3 stochLargeMoving = BicubicTexture(noisetex, pn.xz / (64.0f * 10.0f)).xyz;
  352.  
  353.  
  354.  
  355.         vec3 p = position.xyz;
  356.              p.x += sin(p.z / 2.0f) * 1.0f;
  357.              p.xz += stochLarge.rg * 5.0f;
  358.  
  359.         float windStrength = mix(0.85f, 1.0f, rainStrength);
  360.         float windStrengthRandom = stochLargeMoving.x;
  361.               windStrengthRandom = pow(windStrengthRandom, mix(2.0f, 1.0f, rainStrength));
  362.               windStrength *= mix(windStrengthRandom, 0.5f, rainStrength * 0.25f);
  363.               //windStrength = 1.0f;
  364.  
  365.         //heavy wind
  366.         float heavyAxialFrequency           = 8.0f;
  367.         float heavyAxialWaveLocalization    = 0.9f;
  368.         float heavyAxialRandomization       = 13.0f;
  369.         float heavyAxialAmplitude           = 15.0f;
  370.         float heavyAxialOffset              = 15.0f;
  371.  
  372.         float heavyLateralFrequency         = 6.732f;
  373.         float heavyLateralWaveLocalization  = 1.274f;
  374.         float heavyLateralRandomization     = 1.0f;
  375.         float heavyLateralAmplitude         = 6.0f;
  376.         float heavyLateralOffset            = 0.0f;
  377.  
  378.         //light wind
  379.         float lightAxialFrequency           = 5.5f;
  380.         float lightAxialWaveLocalization    = 1.1f;
  381.         float lightAxialRandomization       = 21.0f;
  382.         float lightAxialAmplitude           = 5.0f;
  383.         float lightAxialOffset              = 5.0f;
  384.  
  385.         float lightLateralFrequency         = 5.9732f;
  386.         float lightLateralWaveLocalization  = 1.174f;
  387.         float lightLateralRandomization     = 0.0f;
  388.         float lightLateralAmplitude         = 1.0f;
  389.         float lightLateralOffset            = 0.0f;
  390.  
  391.         float windStrengthCrossfade = clamp(windStrength * 2.0f - 1.0f, 0.0f, 1.0f);
  392.         float lightWindFade = clamp(windStrength * 2.0f, 0.2f, 1.0f);
  393.  
  394.         angleLight.x += sin(frameTimeCounter * lightAxialFrequency      - p.x * lightAxialWaveLocalization      + stoch.x * lightAxialRandomization)    * lightAxialAmplitude       + lightAxialOffset;
  395.         angleLight.y += sin(frameTimeCounter * lightLateralFrequency    - p.x * lightLateralWaveLocalization    + stoch.x * lightLateralRandomization)  * lightLateralAmplitude     + lightLateralOffset;
  396.  
  397.         angleHeavy.x += sin(frameTimeCounter * heavyAxialFrequency      - p.x * heavyAxialWaveLocalization      + stoch.x * heavyAxialRandomization)    * heavyAxialAmplitude       + heavyAxialOffset;
  398.         angleHeavy.y += sin(frameTimeCounter * heavyLateralFrequency    - p.x * heavyLateralWaveLocalization    + stoch.x * heavyLateralRandomization)  * heavyLateralAmplitude     + heavyLateralOffset;
  399.  
  400.         angle = mix(angleLight * lightWindFade, angleHeavy, vec2(windStrengthCrossfade));
  401.         angle *= 2.0f;
  402.  
  403.         // //Rotate block pivoting from bottom based on angle
  404.         position.x += (sin((angle.x / 180.0f) * 3.141579f)) * grassWeight * lightWeight                     * 1.0f  ;
  405.         position.z += (sin((angle.y / 180.0f) * 3.141579f)) * grassWeight * lightWeight                     * 1.0f  ;
  406.         position.y += (cos(((angle.x + angle.y) / 180.0f) * 3.141579f) - 1.0f)  * grassWeight * lightWeight * 1.0f  ;
  407.     }
  408.    
  409. #endif 
  410.  
  411.  
  412.  
  413. #ifdef WAVING_WHEAT
  414. //Wheat//
  415.     if (mc_Entity.x == 59.0 && texcoord.t < 0.35) {
  416.         float speed = 0.1;
  417.        
  418.         float magnitude = sin((tick * pi / (28.0)) + position.x + position.z) * 0.12 + 0.02;
  419.               magnitude *= grassWeight * 0.2f;
  420.               magnitude *= lightWeight;
  421.         float d0 = sin(tick * pi / (122.0 * speed)) * 3.0 - 1.5 + position.z;
  422.         float d1 = sin(tick * pi / (152.0 * speed)) * 3.0 - 1.5 + position.x;
  423.         float d2 = sin(tick * pi / (122.0 * speed)) * 3.0 - 1.5 + position.x;
  424.         float d3 = sin(tick * pi / (152.0 * speed)) * 3.0 - 1.5 + position.z;
  425.         position.x += sin((tick * pi / (28.0 * speed)) + (position.x + d0) * 0.1 + (position.z + d1) * 0.1) * magnitude;
  426.         position.z += sin((tick * pi / (28.0 * speed)) + (position.z + d2) * 0.1 + (position.x + d3) * 0.1) * magnitude;
  427.     }
  428.    
  429.     //small leaf movement
  430.     if (mc_Entity.x == 59.0 && texcoord.t < 0.35) {
  431.         float speed = 0.04;
  432.        
  433.         float magnitude = (sin(((position.y + position.x)/2.0 + tick * pi / ((28.0)))) * 0.025 + 0.075) * 0.2;
  434.               magnitude *= grassWeight;
  435.               magnitude *= lightWeight;
  436.         float d0 = sin(tick * pi / (112.0 * speed)) * 3.0 - 1.5;
  437.         float d1 = sin(tick * pi / (142.0 * speed)) * 3.0 - 1.5;
  438.         float d2 = sin(tick * pi / (112.0 * speed)) * 3.0 - 1.5;
  439.         float d3 = sin(tick * pi / (142.0 * speed)) * 3.0 - 1.5;
  440.         position.x += sin((tick * pi / (18.0 * speed)) + (-position.x + d0)*1.6 + (position.z + d1)*1.6) * magnitude * (1.0f + rainStrength * 2.0f);
  441.         position.z += sin((tick * pi / (18.0 * speed)) + (position.z + d2)*1.6 + (-position.x + d3)*1.6) * magnitude * (1.0f + rainStrength * 2.0f);
  442.         position.y += sin((tick * pi / (11.0 * speed)) + (position.z + d2) + (position.x + d3)) * (magnitude/3.0) * (1.0f + rainStrength * 2.0f);
  443.     }
  444.  
  445.  
  446.  
  447. #endif
  448.    
  449.    
  450.  
  451. #ifdef WAVING_LEAVES
  452. //Leaves//
  453.        
  454.     if (materialIDs == 3.0f && texcoord.t < 1.90 && texcoord.t > -1.0) {
  455.         float speed = 0.05;
  456.  
  457.  
  458.               //lightWeight = max(0.0f, 1.0f - (lightWeight * 5.0f));
  459.        
  460.         float magnitude = (sin((position.y + position.x + tick * pi / ((28.0) * speed))) * 0.15 + 0.15) * 0.30 * lightWeight;
  461.               magnitude *= grassWeight;
  462.               magnitude *= lightWeight;
  463.         float d0 = sin(tick * pi / (112.0 * speed)) * 3.0 - 1.5;
  464.         float d1 = sin(tick * pi / (142.0 * speed)) * 3.0 - 1.5;
  465.         float d2 = sin(tick * pi / (132.0 * speed)) * 3.0 - 1.5;
  466.         float d3 = sin(tick * pi / (122.0 * speed)) * 3.0 - 1.5;
  467.         position.x += sin((tick * pi / (18.0 * speed)) + (-position.x + d0)*1.6 + (position.z + d1)*1.6) * magnitude * (1.0f + rainStrength * 1.0f);
  468.         position.z += sin((tick * pi / (17.0 * speed)) + (position.z + d2)*1.6 + (-position.x + d3)*1.6) * magnitude * (1.0f + rainStrength * 1.0f);
  469.         position.y += sin((tick * pi / (11.0 * speed)) + (position.z + d2) + (position.x + d3)) * (magnitude/2.0) * (1.0f + rainStrength * 1.0f);
  470.        
  471.     }
  472.    
  473.  
  474.     //lower leaf movement
  475.     if (materialIDs == 3.0f) {
  476.         float speed = 0.075;
  477.  
  478.  
  479.        
  480.         float magnitude = (sin((tick * pi / ((28.0) * speed))) * 0.05 + 0.15) * 0.075 * lightWeight;
  481.               magnitude *= 1.0f - grassWeight;
  482.               magnitude *= lightWeight;
  483.         float d0 = sin(tick * pi / (122.0 * speed)) * 3.0 - 1.5;
  484.         float d1 = sin(tick * pi / (142.0 * speed)) * 3.0 - 1.5;
  485.         float d2 = sin(tick * pi / (162.0 * speed)) * 3.0 - 1.5;
  486.         float d3 = sin(tick * pi / (112.0 * speed)) * 3.0 - 1.5;
  487.         position.x += sin((tick * pi / (13.0 * speed)) + (position.x + d0)*0.9 + (position.z + d1)*0.9) * magnitude;
  488.         position.z += sin((tick * pi / (16.0 * speed)) + (position.z + d2)*0.9 + (position.x + d3)*0.9) * magnitude;
  489.         position.y += sin((tick * pi / (15.0 * speed)) + (position.z + d2) + (position.x + d3)) * (magnitude/1.0);
  490.     }
  491.  
  492. #endif 
  493.  
  494.     vec4 locposition = gl_ModelViewMatrix * gl_Vertex;
  495.    
  496.     distance = sqrt(locposition.x * locposition.x + locposition.y * locposition.y + locposition.z * locposition.z);
  497.  
  498.     position.xyz -= cameraPosition.xyz;
  499.  
  500.  
  501.     gl_Position = gl_ProjectionMatrix * gbufferModelView * position;
  502.    
  503.  
  504.  
  505.  
  506.     color = gl_Color;
  507.  
  508.     // float colorDiff = abs(color.r - color.g);
  509.     //    colorDiff += abs(color.r - color.b);
  510.     //    colorDiff += abs(color.g - color.b);
  511.  
  512.     // if (colorDiff < 0.001f && mc_Entity.x != -1.0f && mc_Entity.x != 63 && mc_Entity.x != 68 && mc_Entity.x != 323) {
  513.  
  514.     //  float lum = color.r + color.g + color.b;
  515.     //        lum /= 3.0f;
  516.  
  517.     //  if (lum < 0.92f) {
  518.     //      color.rgb = vec3(1.0f);
  519.     //  }
  520.  
  521.     // }   
  522.    
  523.     gl_FogFragCoord = gl_Position.z;
  524.    
  525.    
  526.     normal = normalize(gl_NormalMatrix * gl_Normal);
  527.     worldNormal = gl_Normal;
  528.  
  529.     //if(distance < 80.0f){
  530.         if (gl_Normal.x > 0.5) {
  531.             //  1.0,  0.0,  0.0
  532.             tangent  = normalize(gl_NormalMatrix * vec3( 0.0,  0.0,  1.0));
  533.             binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0,  0.0));
  534.         } else if (gl_Normal.x < -0.5) {
  535.             // -1.0,  0.0,  0.0
  536.             tangent  = normalize(gl_NormalMatrix * vec3( 0.0,  0.0,  1.0));
  537.             binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0,  0.0));
  538.         } else if (gl_Normal.y > 0.5) {
  539.             //  0.0,  1.0,  0.0
  540.             tangent  = normalize(gl_NormalMatrix * vec3( 1.0,  0.0,  0.0));
  541.             binormal = normalize(gl_NormalMatrix * vec3( 0.0,  0.0,  1.0));
  542.         } else if (gl_Normal.y < -0.5) {
  543.             //  0.0, -1.0,  0.0
  544.             tangent  = normalize(gl_NormalMatrix * vec3( 1.0,  0.0,  0.0));
  545.             binormal = normalize(gl_NormalMatrix * vec3( 0.0,  0.0,  1.0));
  546.         } else if (gl_Normal.z > 0.5) {
  547.             //  0.0,  0.0,  1.0
  548.             tangent  = normalize(gl_NormalMatrix * vec3( 1.0,  0.0,  0.0));
  549.             binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0,  0.0));
  550.         } else if (gl_Normal.z < -0.5) {
  551.             //  0.0,  0.0, -1.0
  552.             tangent  = normalize(gl_NormalMatrix * vec3( 1.0,  0.0,  0.0));
  553.             binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0,  0.0));
  554.         }
  555.     //}
  556.  
  557.    
  558.     tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
  559.                      tangent.y, binormal.y, normal.y,
  560.                      tangent.z, binormal.z, normal.z);
  561.  
  562.     vertexPos = gl_Vertex; 
  563. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement