Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #ifdef WATER_REFRACT
  2. if (iswater > 0.9) {
  3. vec3 posxz = worldposition.xyz + cameraPosition.xyz;
  4. posxz.x += sin(posxz.z+frameTimeCounter)*0.25;
  5. posxz.z += cos(posxz.x+frameTimeCounter*0.5)*0.25;
  6.  
  7. float deltaPos = 0.2;
  8. float h0 = waterH(posxz.xz);
  9. float h1 = waterH(posxz.xz + vec2(deltaPos,0.0));
  10. float h2 = waterH(posxz.xz + vec2(-deltaPos,0.0));
  11. float h3 = waterH(posxz.xz + vec2(0.0,deltaPos));
  12. float h4 = waterH(posxz.xz + vec2(0.0,-deltaPos));
  13.  
  14. float xDelta = (h1-h0)+(h0-h2);
  15. float yDelta = (h3-h0)+(h0-h4);
  16.  
  17. float depth = getDepth(pixeldepth);
  18. float depth2 = getDepth(pixeldepth2);
  19.  
  20. float wDepth = depth - depth2;
  21.  
  22. float rMult = 5.0;
  23. rMult = clamp(wDepth,0.0,1.0);
  24. rMult /= (depth2);
  25.  
  26. float refMult = REFRACT_MULT-dot(normal,normalize(fragposition).xyz)*0.003;
  27.  
  28. //refMult = rMult + refractMult;
  29.  
  30. vec3 refract = normalize(vec3(xDelta,yDelta,1.0-pow(abs(xDelta+yDelta),2.0)));
  31.  
  32. vec4 rA = texture2D(gcolor, newtc.st + refract.xy* refMult* rMult);
  33. rA.rgb = pow(rA.rgb,vec3(2.2));
  34. vec4 rB = texture2D(gcolor, newtc.st);
  35. rB.rgb = pow(rB.rgb,vec3(2.2));
  36.  
  37. float mask = texture2D(gaux1, newtc.st + refract.xy* refMult* rMult).g;
  38. mask = float(mask > 0.04 && mask < 0.07);
  39. newtc = (newtc.st + refract.xy* refMult* rMult)*mask + texcoord.xy*(1-mask);
  40.  
  41. color.rgb = pow(texture2D(gcolor,newtc.xy).rgb,vec3(2.2));
  42.  
  43. float uDepth = texture2D(depthtex1,newtc.xy).x;
  44. uPos = nvec3(gbufferProjectionInverse * nvec4(vec3(newtc.xy,uDepth) * 2.0 - 1.0));
  45.  
  46. }
  47. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement