three_plus.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. THREE.HorizontalBlurShader = {
  2. uniforms: {
  3. tDiffuse: {
  4. type: 't',
  5. value: null,
  6. },
  7. h: {
  8. type: 'f',
  9. value: 1 / 512,
  10. },
  11. },
  12. vertexShader: ['varying vec2 vUv;', 'void main() {', 'vUv = uv;', 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}'].join('\n'),
  13. fragmentShader: [
  14. 'uniform sampler2D tDiffuse;',
  15. 'uniform float h;',
  16. 'varying vec2 vUv;',
  17. 'void main() {',
  18. 'vec4 sum = vec4( 0.0 );',
  19. 'sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * h, vUv.y ) ) * 0.051;',
  20. 'sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * h, vUv.y ) ) * 0.0918;',
  21. 'sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * h, vUv.y ) ) * 0.12245;',
  22. 'sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * h, vUv.y ) ) * 0.1531;',
  23. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;',
  24. 'sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * h, vUv.y ) ) * 0.1531;',
  25. 'sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * h, vUv.y ) ) * 0.12245;',
  26. 'sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * h, vUv.y ) ) * 0.0918;',
  27. 'sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * h, vUv.y ) ) * 0.051;',
  28. 'gl_FragColor = sum;',
  29. '}',
  30. ].join('\n'),
  31. }
  32. THREE.VerticalBlurShader = {
  33. uniforms: {
  34. tDiffuse: {
  35. type: 't',
  36. value: null,
  37. },
  38. v: {
  39. type: 'f',
  40. value: 1 / 512,
  41. },
  42. },
  43. vertexShader: ['varying vec2 vUv;', 'void main() {', 'vUv = uv;', 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}'].join('\n'),
  44. fragmentShader: [
  45. 'uniform sampler2D tDiffuse;',
  46. 'uniform float v;',
  47. 'varying vec2 vUv;',
  48. 'void main() {',
  49. 'vec4 sum = vec4( 0.0 );',
  50. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;',
  51. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;',
  52. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;',
  53. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;',
  54. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;',
  55. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;',
  56. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;',
  57. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;',
  58. 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;',
  59. 'gl_FragColor = sum;',
  60. '}',
  61. ].join('\n'),
  62. }
  63. THREE.ShaderPass = function (material, t) {
  64. this.textureID = void 0 !== t ? t : 'tDiffuse'
  65. if (material instanceof THREE.ShaderMaterial) {
  66. this.uniforms = material.uniforms
  67. this.material = material
  68. } else if (material) {
  69. this.uniforms = THREE.UniformsUtils.clone(material.uniforms)
  70. this.material = new THREE.ShaderMaterial({
  71. defines: material.defines || {},
  72. uniforms: this.uniforms,
  73. vertexShader: material.vertexShader,
  74. fragmentShader: material.fragmentShader,
  75. })
  76. }
  77. this.renderToScreen = !1
  78. this.enabled = !0
  79. this.needsSwap = !0
  80. this.clear = !1
  81. this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1)
  82. this.scene = new THREE.Scene()
  83. this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), null)
  84. this.scene.add(this.quad)
  85. }
  86. THREE.ShaderPass.prototype = {
  87. render:function(e, t, i, n) {
  88. this.uniforms[this.textureID] && (this.uniforms[this.textureID].value = i)
  89. this.quad.material = this.material
  90. if (this.renderToScreen) {
  91. e.render(this.scene, this.camera)
  92. } else {
  93. e.render(this.scene, this.camera, t, this.clear)
  94. }
  95. //this.renderToScreen ? e.render(this.scene, this.camera) : e.render(this.scene, this.camera, t, this.clear)
  96. },
  97. }
  98. THREE.ImageUtils.crossOrigin = 'anonymous'