BlendShader.js 751 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Blend two textures
  3. */
  4. const BlendShader = {
  5. uniforms: {
  6. 'tDiffuse1': { value: null },
  7. 'tDiffuse2': { value: null },
  8. 'mixRatio': { value: 0.5 },
  9. 'opacity': { value: 1.0 }
  10. },
  11. vertexShader: /* glsl */`
  12. varying vec2 vUv;
  13. void main() {
  14. vUv = uv;
  15. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  16. }`,
  17. fragmentShader: /* glsl */`
  18. uniform float opacity;
  19. uniform float mixRatio;
  20. uniform sampler2D tDiffuse1;
  21. uniform sampler2D tDiffuse2;
  22. varying vec2 vUv;
  23. void main() {
  24. vec4 texel1 = texture2D( tDiffuse1, vUv );
  25. vec4 texel2 = texture2D( tDiffuse2, vUv );
  26. gl_FragColor = mix( texel1, texel2, mixRatio );
  27. gl_FragColor.a *= opacity;
  28. }`
  29. };
  30. export { BlendShader };