CompositeShader.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @author bhouston / http://clara.io/
  3. *
  4. * Multi-Sample Anti-aliasing shader - for blending together sample buffers
  5. */
  6. THREE.CompositeShader = {
  7. shaderID: "composite",
  8. uniforms: {
  9. // "tBackground": { type: "t", value: null },
  10. "tForeground": { type: "t", value: null },
  11. "scale": { type: "f", 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. "varying vec2 vUv;",
  22. // "uniform sampler2D tBackground;",
  23. "uniform sampler2D tForeground;",
  24. "uniform float scale;",
  25. "vec4 composite( vec4 foreground, vec4 background ) {",
  26. "return vec4( mix( background.rgb * background.a, foreground.rgb, foreground.a ), background.a * ( 1.0 - foreground.a ) + foreground.a );",
  27. "}",
  28. "void main() {",
  29. // "vec4 background = texture2D( tBackground, vUv );",
  30. "vec4 foreground = texture2D( tForeground, vUv );",
  31. "gl_FragColor = foreground * scale;//composite( foreground, background ) * scale;",
  32. "}"
  33. ].join("\n")
  34. };