0
0

BlendShader.js 731 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 = opacity * mix( texel1, texel2, mixRatio );
  27. }`
  28. };
  29. export { BlendShader };