refraction.fragment.fx 507 B

1234567891011121314151617181920212223
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4. // Samplers
  5. varying vec2 vUV;
  6. uniform sampler2D textureSampler;
  7. uniform sampler2D refractionSampler;
  8. // Parameters
  9. uniform vec3 baseColor;
  10. uniform float depth;
  11. uniform float colorLevel;
  12. void main() {
  13. float ref = 1.0 - texture2D(refractionSampler, vUV).r;
  14. vec2 uv = vUV - vec2(0.5);
  15. vec2 offset = uv * depth * ref;
  16. vec3 sourceColor = texture2D(textureSampler, vUV - offset).rgb;
  17. gl_FragColor = vec4(sourceColor + sourceColor * ref * colorLevel, 1.0);
  18. }