123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- THREE.HorizontalBlurShader = {
- uniforms: {
- tDiffuse: {
- type: 't',
- value: null,
- },
- h: {
- type: 'f',
- value: 1 / 512,
- },
- },
- vertexShader: ['varying vec2 vUv;', 'void main() {', 'vUv = uv;', 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}'].join('\n'),
- fragmentShader: [
- 'uniform sampler2D tDiffuse;',
- 'uniform float h;',
- 'varying vec2 vUv;',
- 'void main() {',
- 'vec4 sum = vec4( 0.0 );',
- 'sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * h, vUv.y ) ) * 0.051;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * h, vUv.y ) ) * 0.0918;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * h, vUv.y ) ) * 0.12245;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * h, vUv.y ) ) * 0.1531;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * h, vUv.y ) ) * 0.1531;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * h, vUv.y ) ) * 0.12245;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * h, vUv.y ) ) * 0.0918;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * h, vUv.y ) ) * 0.051;',
- 'gl_FragColor = sum;',
- '}',
- ].join('\n'),
- }
- THREE.VerticalBlurShader = {
- uniforms: {
- tDiffuse: {
- type: 't',
- value: null,
- },
- v: {
- type: 'f',
- value: 1 / 512,
- },
- },
- vertexShader: ['varying vec2 vUv;', 'void main() {', 'vUv = uv;', 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}'].join('\n'),
- fragmentShader: [
- 'uniform sampler2D tDiffuse;',
- 'uniform float v;',
- 'varying vec2 vUv;',
- 'void main() {',
- 'vec4 sum = vec4( 0.0 );',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;',
- 'sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;',
- 'gl_FragColor = sum;',
- '}',
- ].join('\n'),
- }
- THREE.ShaderPass = function (material, t) {
- this.textureID = void 0 !== t ? t : 'tDiffuse'
- if (material instanceof THREE.ShaderMaterial) {
- this.uniforms = material.uniforms
- this.material = material
- } else if (material) {
- this.uniforms = THREE.UniformsUtils.clone(material.uniforms)
- this.material = new THREE.ShaderMaterial({
- defines: material.defines || {},
- uniforms: this.uniforms,
- vertexShader: material.vertexShader,
- fragmentShader: material.fragmentShader,
- })
- }
- this.renderToScreen = !1
- this.enabled = !0
- this.needsSwap = !0
- this.clear = !1
- this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1)
- this.scene = new THREE.Scene()
- this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), null)
- this.scene.add(this.quad)
- }
- THREE.ShaderPass.prototype = {
- render:function(e, t, i, n) {
- this.uniforms[this.textureID] && (this.uniforms[this.textureID].value = i)
- this.quad.material = this.material
- if (this.renderToScreen) {
- e.render(this.scene, this.camera)
- } else {
- e.render(this.scene, this.camera, t, this.clear)
- }
- //this.renderToScreen ? e.render(this.scene, this.camera) : e.render(this.scene, this.camera, t, this.clear)
- },
- }
- THREE.ImageUtils.crossOrigin = 'anonymous'
|