BlendShader.js 815 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. *
  4. * Blend two textures
  5. */
  6. THREE.BlendShader = {
  7. uniforms: {
  8. "tDiffuse1": { value: null },
  9. "tDiffuse2": { value: null },
  10. "mixRatio": { value: 0.5 },
  11. "opacity": { value: 1.0 }
  12. },
  13. vertexShader: [
  14. "varying vec2 vUv;",
  15. "void main() {",
  16. "vUv = uv;",
  17. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  18. "}"
  19. ].join( "\n" ),
  20. fragmentShader: [
  21. "uniform float opacity;",
  22. "uniform float mixRatio;",
  23. "uniform sampler2D tDiffuse1;",
  24. "uniform sampler2D tDiffuse2;",
  25. "varying vec2 vUv;",
  26. "void main() {",
  27. "vec4 texel1 = texture2D( tDiffuse1, vUv );",
  28. "vec4 texel2 = texture2D( tDiffuse2, vUv );",
  29. "gl_FragColor = opacity * mix( texel1, texel2, mixRatio );",
  30. "}"
  31. ].join( "\n" )
  32. };