refraction.fragment.fx 481 B

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