From f9a25256cfeec283a09ac17bda1d406a43decb0a Mon Sep 17 00:00:00 2001 From: Tarek Sherif Date: Mon, 14 Oct 2019 15:44:48 -0400 Subject: [PATCH] Remove core/multipass, main, wip folder (#1278) --- examples/glfx/canvas.js | 14 +- examples/glfx/index.html | 1 + examples/glfx/multipass.js | 387 ++++++++++ modules/core/src/index.js | 15 - modules/core/src/multipass/clear-mask-pass.js | 17 - modules/core/src/multipass/clear-pass.js | 21 - modules/core/src/multipass/composite-pass.js | 26 - modules/core/src/multipass/copy-pass.js | 47 -- modules/core/src/multipass/mask-pass.js | 46 -- .../core/src/multipass/multi-pass-renderer.js | 31 - modules/core/src/multipass/pass.js | 73 -- modules/core/src/multipass/render-pass.js | 21 - modules/core/src/multipass/render-state.js | 39 -- .../core/src/multipass/shader-module-pass.js | 151 ---- modules/core/src/multipass/stencil-pass.js | 74 -- modules/core/src/multipass/texture-pass.js | 48 -- .../test/multipass/clear-mask-pass.spec.js | 28 - .../core/test/multipass/clear-pass.spec.js | 24 - .../test/multipass/composite-pass.spec.js | 21 - modules/core/test/multipass/copy-pass.spec.js | 35 - modules/core/test/multipass/index.js | 11 - modules/core/test/multipass/mask-pass.spec.js | 24 - .../test/multipass/multi-pass-render.spec.js | 41 -- modules/core/test/multipass/pass.spec.js | 94 --- .../core/test/multipass/render-pass.spec.js | 23 - .../test/multipass/shader-module-pass.spec.js | 38 - .../core/test/multipass/stencil-pass.spec.js | 28 - .../core/test/multipass/texture-pass.spec.js | 44 -- modules/core/test/webgl-dependent-tests.js | 1 - .../src/experimental/passes/outline-pass.js | 58 -- .../src/experimental/passes/ssao-pass.js | 73 -- .../src/experimental/passes/ssao-pass.md | 15 - modules/effects/src/index.js | 2 - modules/glfx/LICENSE | 19 - modules/glfx/README.md | 21 - modules/glfx/bundle.js | 7 - modules/glfx/package.json | 30 - modules/glfx/src/docs/canvas.md | 106 --- modules/glfx/src/docs/shader-module-pass.md | 2 - modules/glfx/src/index.js | 1 - modules/glfx/test/index.js | 1 - modules/main/README.md | 10 - modules/main/addons.js | 3 - modules/main/bundle.js | 7 - modules/main/constants.js | 5 - modules/main/debug.js | 4 - modules/main/headless.js | 2 - modules/main/package.json | 35 - modules/main/src/addons.js | 3 - modules/main/src/index.js | 2 - modules/main/test/exports.spec.js | 24 - modules/main/test/index.js | 1 - modules/main/webgl1.js | 2 - modules/webgl/test/context/context.spec.js | 8 +- test/index.js | 2 +- test/modules.js | 4 - wip/docs/filters.md | 206 ------ wip/docs/picking-pass.md | 27 - wip/docs/sampler.md | 205 ------ wip/docs/texture-2d-array.md | 52 -- wip/src/effects/adjust-filters/unsharpmask.js | 57 -- wip/src/effects/blur-filters/lensblur.js | 146 ---- wip/src/effects/curve-filters/curves.js | 75 -- .../curve-filters/spline-interpolator.js | 76 -- wip/src/effects/warp-filters/matrix.js | 53 -- wip/src/effects/warp-filters/matrixwarp.js | 64 -- wip/src/effects/warp-filters/perspective.js | 18 - wip/src/io/index.js | 10 - wip/src/io/read-texture.js | 61 -- wip/src/mesh-model.js | 660 ------------------ wip/src/mesh.js | 34 - wip/src/pick-models.js | 76 -- wip/src/picking-pass.js | 44 -- wip/src/sampler.js | 58 -- wip/src/texture-2d-array.js | 13 - wip/src/track-context-creation.js | 28 - wip/test/sampler.spec.js | 31 - wip/test/texture-2d-array.spec.js | 45 -- 78 files changed, 399 insertions(+), 3510 deletions(-) create mode 100644 examples/glfx/multipass.js delete mode 100644 modules/core/src/multipass/clear-mask-pass.js delete mode 100644 modules/core/src/multipass/clear-pass.js delete mode 100644 modules/core/src/multipass/composite-pass.js delete mode 100644 modules/core/src/multipass/copy-pass.js delete mode 100644 modules/core/src/multipass/mask-pass.js delete mode 100644 modules/core/src/multipass/multi-pass-renderer.js delete mode 100644 modules/core/src/multipass/pass.js delete mode 100644 modules/core/src/multipass/render-pass.js delete mode 100644 modules/core/src/multipass/render-state.js delete mode 100644 modules/core/src/multipass/shader-module-pass.js delete mode 100644 modules/core/src/multipass/stencil-pass.js delete mode 100644 modules/core/src/multipass/texture-pass.js delete mode 100644 modules/core/test/multipass/clear-mask-pass.spec.js delete mode 100644 modules/core/test/multipass/clear-pass.spec.js delete mode 100644 modules/core/test/multipass/composite-pass.spec.js delete mode 100644 modules/core/test/multipass/copy-pass.spec.js delete mode 100644 modules/core/test/multipass/index.js delete mode 100644 modules/core/test/multipass/mask-pass.spec.js delete mode 100644 modules/core/test/multipass/multi-pass-render.spec.js delete mode 100644 modules/core/test/multipass/pass.spec.js delete mode 100644 modules/core/test/multipass/render-pass.spec.js delete mode 100644 modules/core/test/multipass/shader-module-pass.spec.js delete mode 100644 modules/core/test/multipass/stencil-pass.spec.js delete mode 100644 modules/core/test/multipass/texture-pass.spec.js delete mode 100644 modules/effects/src/experimental/passes/outline-pass.js delete mode 100644 modules/effects/src/experimental/passes/ssao-pass.js delete mode 100644 modules/effects/src/experimental/passes/ssao-pass.md delete mode 100644 modules/glfx/LICENSE delete mode 100644 modules/glfx/README.md delete mode 100644 modules/glfx/bundle.js delete mode 100644 modules/glfx/package.json delete mode 100644 modules/glfx/src/docs/canvas.md delete mode 100644 modules/glfx/src/docs/shader-module-pass.md delete mode 100644 modules/glfx/src/index.js delete mode 100644 modules/glfx/test/index.js delete mode 100644 modules/main/README.md delete mode 100644 modules/main/addons.js delete mode 100644 modules/main/bundle.js delete mode 100644 modules/main/constants.js delete mode 100644 modules/main/debug.js delete mode 100644 modules/main/headless.js delete mode 100644 modules/main/package.json delete mode 100644 modules/main/src/addons.js delete mode 100644 modules/main/src/index.js delete mode 100644 modules/main/test/exports.spec.js delete mode 100644 modules/main/test/index.js delete mode 100644 modules/main/webgl1.js delete mode 100644 wip/docs/filters.md delete mode 100644 wip/docs/picking-pass.md delete mode 100644 wip/docs/sampler.md delete mode 100644 wip/docs/texture-2d-array.md delete mode 100644 wip/src/effects/adjust-filters/unsharpmask.js delete mode 100644 wip/src/effects/blur-filters/lensblur.js delete mode 100644 wip/src/effects/curve-filters/curves.js delete mode 100644 wip/src/effects/curve-filters/spline-interpolator.js delete mode 100644 wip/src/effects/warp-filters/matrix.js delete mode 100644 wip/src/effects/warp-filters/matrixwarp.js delete mode 100644 wip/src/effects/warp-filters/perspective.js delete mode 100644 wip/src/io/index.js delete mode 100644 wip/src/io/read-texture.js delete mode 100644 wip/src/mesh-model.js delete mode 100644 wip/src/mesh.js delete mode 100644 wip/src/pick-models.js delete mode 100644 wip/src/picking-pass.js delete mode 100644 wip/src/sampler.js delete mode 100644 wip/src/texture-2d-array.js delete mode 100644 wip/src/track-context-creation.js delete mode 100644 wip/test/sampler.spec.js delete mode 100644 wip/test/texture-2d-array.spec.js diff --git a/examples/glfx/canvas.js b/examples/glfx/canvas.js index 6a77c04873..f952fe796f 100644 --- a/examples/glfx/canvas.js +++ b/examples/glfx/canvas.js @@ -1,14 +1,6 @@ -/* global document, luma */ -const { - createGLContext, - Texture2D, - Model, - _MultiPassRenderer: MultiPassRenderer, - _ClearPass: ClearPass, - _CopyPass: CopyPass, - _TexturePass: TexturePass, - _ShaderModulePass: ShaderModulePass -} = luma; +/* global document, luma, multipass */ +const {createGLContext, Texture2D, Model} = luma; +const {TexturePass, CopyPass, MultiPassRenderer, ClearPass, ShaderModulePass} = multipass; const DEFAULT_VS = `\ attribute vec2 vertex; diff --git a/examples/glfx/index.html b/examples/glfx/index.html index 1489395dc8..af20183717 100644 --- a/examples/glfx/index.html +++ b/examples/glfx/index.html @@ -11,6 +11,7 @@ crossorigin="anonymous"> + diff --git a/examples/glfx/multipass.js b/examples/glfx/multipass.js new file mode 100644 index 0000000000..721292a189 --- /dev/null +++ b/examples/glfx/multipass.js @@ -0,0 +1,387 @@ +/* global luma */ +const {Framebuffer, withParameters, normalizeShaderModule, ClipSpace} = luma; + +// eslint-disable-next-line +const multipass = (function multipass() { + class RenderState { + constructor(gl, props = {}) { + this.gl = gl; + + this.framebuffer1 = new Framebuffer(gl, {id: 'multi-pass-1', stencil: true}); + this.framebuffer2 = new Framebuffer(gl, {id: 'multi-pass-2', stencil: true}); + + this.reset(); + } + + reset() { + this.framebuffer1.resize(); + this.framebuffer2.resize(); + + this.writeBuffer = this.framebuffer1; + this.readBuffer = this.framebuffer2; + + this.maskActive = false; + } + + delete() { + this.framebuffer1.delete(); + this.framebuffer2.delete(); + } + + _swapFramebuffers() { + const tmp = this.readBuffer; + this.readBuffer = this.writeBuffer; + this.writeBuffer = tmp; + } + } + + class Pass { + constructor(gl, props = {}) { + const {id = 'pass'} = props; + this.id = id; // id of this pass + this.gl = gl; + this.props = {enabled: true, screen: false, swap: false}; + Object.assign(this.props, props); + } + + setProps(props) { + Object.assign(this.props, props); + } + + render(renderState, animationProps) { + if (!this.props.enabled) { + return; + } + + const gl = this.gl; + + const renderParams = { + gl, + outputBuffer: renderState.writeBuffer, + inputBuffer: renderState.readBuffer, + animationProps, + swapBuffers: () => renderState._swapFramebuffers() + }; + + // TODO: Calirfy/Fix : is `screen` or `swap` must be true at this point + // if so comment. We can also remove `enabled` from props and deduce that based on these two flags + if (this.props.screen) { + renderParams.inputBuffer = renderParams.outputBuffer; + renderParams.outputBuffer = Framebuffer.getDefaultFramebuffer(gl); + } else if (this.props.swap) { + renderParams.inputBuffer = renderState.writeBuffer; + renderParams.outputBuffer = renderState.readBuffer; + } + + withParameters(gl, {framebuffer: renderParams.outputBuffer}, () => + this._renderPass(renderParams) + ); + + if (this.props.debug) { + renderParams.outputBuffer.log(1, this.id); + } + + if (this.props.swap) { + renderState._swapFramebuffers(); + } + } + + delete() { + // Delete any resources crated + } + + /** + * Renders the effect. + * This is an abstract method that should be overridden. + * @param {Framebuffer} inputBuffer - Frame buffer that contains the result of the previous pass + * @param {Framebuffer} outputBuffer - Frame buffer that serves as the output render target + */ + _renderPass({gl, inputBuffer, outputBuffer, animationProps}) { + // assert(false, 'Draw/render methods not implemented!'); + } + } + + class CompositePass extends Pass { + constructor(gl, props = {}) { + props = Array.isArray(props) ? {passes: props} : props; + super(gl, Object.assign({id: 'composite-pass'}, props)); + } + + // Override render() to just forward the call + render(...args) { + const {passes = []} = this.props; + for (const pass of passes) { + pass.render(...args); + } + } + + delete() { + // Delete any resources crated + } + } + + class MultiPassRenderer extends CompositePass { + constructor(gl, props = {}) { + props = Array.isArray(props) ? {passes: props} : props; + super(gl, Object.assign({id: 'multi-pass'}, props)); + this.renderState = new RenderState(gl, props); + } + + // Override render() to just forward the call + render(animationProps) { + this.renderState.reset(); + const {passes = []} = this.props; + for (const pass of passes) { + pass.render(this.renderState, animationProps); + } + return this; + } + + delete() { + this.renderState.delete(); + super.delete(); + } + } + + class ShaderModuleSinglePass extends Pass { + constructor(gl, props = {}) { + super(gl, Object.assign({swap: true}, props)); + } + + _renderPass({inputBuffer, swapBuffers}) { + this.props.model.setUniforms(this.props); + + // swapBuffers(); + this.props.model.draw({ + uniforms: { + texture: inputBuffer, + texSize: [inputBuffer.width, inputBuffer.height] + }, + parameters: { + depthWrite: false, + depthTest: false + } + }); + } + } + + class ShaderModulePass extends CompositePass { + constructor(gl, module, props = {}) { + const id = `${module.name}-pass`; + normalizeShaderModule(module); + const passes = normalizePasses(gl, module, id, props); + super(gl, Object.assign({id, passes}, props)); + this.module = module; + } + + _renderPass({inputBuffer, swapBuffers}) { + let first = true; + for (const pass of this.props.passes) { + if (!first) { + swapBuffers(); + } + first = false; + const {uniforms, model} = pass.props; + if (uniforms) { + model.setUniforms(uniforms); + } + // swapBuffers(); + model.draw({ + uniforms: { + texture: inputBuffer, + texSize: [inputBuffer.width, inputBuffer.height] + }, + parameters: { + depthWrite: false, + depthTest: false + } + }); + } + } + } + + function normalizePasses(gl, module, id, props) { + if (module.filter || module.sampler) { + const fs = getFragmentShaderForRenderPass(module); + const pass = new ShaderModuleSinglePass(gl, { + id, + model: getModel(gl, module, fs, id, props), + uniforms: null + }); + return [pass]; + } + + const passes = module.passes || []; + return passes.map(pass => { + const fs = getFragmentShaderForRenderPass(module, pass); + const idn = `${id}-${passes.length + 1}`; + + return new ShaderModuleSinglePass( + gl, + Object.assign( + { + id: idn, + model: getModel(gl, module, fs, idn, props), + uniforms: pass.uniforms + }, + props + ) + ); + }); + } + + function getModel(gl, module, fs, id, props) { + const model = new ClipSpace(gl, {id, fs, modules: [module]}); + + const uniforms = Object.assign(module.getUniforms(), module.getUniforms(props)); + + model.setUniforms(uniforms); + return model; + } + + const FILTER_FS_TEMPLATE = func => `\ + uniform sampler2D texture; + uniform vec2 texSize; + + varying vec2 position; + varying vec2 coordinate; + varying vec2 uv; + + void main() { + vec2 texCoord = coordinate; + + gl_FragColor = texture2D(texture, texCoord); + gl_FragColor = ${func}(gl_FragColor, texSize, texCoord); + } + `; + + const SAMPLER_FS_TEMPLATE = func => `\ + uniform sampler2D texture; + uniform vec2 texSize; + + varying vec2 position; + varying vec2 coordinate; + varying vec2 uv; + + void main() { + vec2 texCoord = coordinate; + + gl_FragColor = ${func}(texture, texSize, texCoord); + } + `; + + function getFragmentShaderForRenderPass(module, pass = module) { + if (pass.filter) { + const func = typeof pass.filter === 'string' ? pass.filter : `${module.name}_filterColor`; + return FILTER_FS_TEMPLATE(func); + } + + if (pass.sampler) { + const func = typeof pass.sampler === 'string' ? pass.sampler : `${module.name}_sampleColor`; + return SAMPLER_FS_TEMPLATE(func); + } + + // console.error(`${module.name} no fragment shader generated`); + return null; + } + + class CopyPass extends Pass { + constructor(gl, props = {}) { + super(gl, Object.assign({id: 'copy-pass', swap: true}, props)); + this.clipspace = new ClipSpace(gl, { + id: 'copy-pass', + fs: `\ + uniform sampler2D uDiffuseSampler; + uniform float uOpacity; + + varying vec2 uv; + + void main() { + vec4 texel = texture2D(uDiffuseSampler, uv); + gl_FragColor = uOpacity * texel; + } + ` + }); + } + + delete() { + super.delete(); + this.clipspace.delete(); + } + + _renderPass({inputBuffer}) { + const {opacity = 1.0} = this.props; + + this.clipspace.draw({ + uniforms: { + uDiffuseSampler: inputBuffer, + uOpacity: opacity + }, + parameters: { + depthWrite: false, + depthTest: false + } + }); + } + } + + class TexturePass extends Pass { + constructor(gl, options = {}) { + super(gl, Object.assign({id: 'texture-pass'}, options)); + const {texture, opacity = 1.0} = options; + this.clipspace = new ClipSpace(gl, { + id: 'texture-pass', + fs: `\ + uniform sampler2D uDiffuseSampler; + uniform float uOpacity; + varying vec2 uv; + + void main() { + vec4 texel = texture2D(uDiffuseSampler, uv); + gl_FragColor = uOpacity * texel; + } + `, + uniforms: { + uDiffuseSampler: texture, + uOpacity: opacity + } + }); + } + + delete() { + this.clipspace.delete(); + super.delete(); + } + + _renderPass() { + this.clipspace.draw({ + parameters: { + depthWrite: false, + depthTest: false + } + }); + } + } + + class ClearPass extends Pass { + constructor(gl, props = {}) { + super(gl, Object.assign({id: 'clear-pass'}, props)); + } + + // TODO - add support for colors, align with model.clear and framebuffer.clear + // TODO - integrate with luma.gl clear, make sure right buffer is cleared + _renderPass() { + const {gl} = this; + const {clearBits = gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT} = this.props; + gl.clear(clearBits); + } + } + + return { + TexturePass, + CopyPass, + MultiPassRenderer, + ClearPass, + ShaderModulePass + }; +})(); diff --git a/modules/core/src/index.js b/modules/core/src/index.js index c750b744a7..77bebc3fa5 100644 --- a/modules/core/src/index.js +++ b/modules/core/src/index.js @@ -92,21 +92,6 @@ export {default as ProgramManager} from './resource-management/program-manager'; // Experimental core exports export {default as _AnimationLoopProxy} from './lib/animation-loop-proxy'; -// Multipass Rendering -export {default as _MultiPassRenderer} from './multipass/multi-pass-renderer'; -export {default as _RenderState} from './multipass/render-state'; -export {default as _Pass} from './multipass/pass'; -export {default as _CompositePass} from './multipass/composite-pass'; -export {default as _ClearPass} from './multipass/clear-pass'; -export {default as _RenderPass} from './multipass/render-pass'; -export {default as _CopyPass} from './multipass/copy-pass'; -export {default as _TexturePass} from './multipass/texture-pass'; -// export {default as _MaskPass} from './multipass/mask-pass'; -// export {default as _ClearMaskPass} from './multipass/clearmask-pass'; - -export {default as _ShaderModulePass} from './multipass/shader-module-pass'; -// export {default as _Canvas} from './multipass/canvas'; - // Geometries export {default as ConeGeometry} from './geometries/cone-geometry'; export {default as CubeGeometry} from './geometries/cube-geometry'; diff --git a/modules/core/src/multipass/clear-mask-pass.js b/modules/core/src/multipass/clear-mask-pass.js deleted file mode 100644 index 9a39b88268..0000000000 --- a/modules/core/src/multipass/clear-mask-pass.js +++ /dev/null @@ -1,17 +0,0 @@ -// -// A pass that disables stencil test. -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import Pass from './pass.js'; - -export default class ClearMaskPass extends Pass { - constructor(gl, props) { - super(gl, Object.assign({id: 'clear-mask-pass'}, props)); - } - - render(gl) { - gl.disable(gl.STENCIL_TEST); - } -} diff --git a/modules/core/src/multipass/clear-pass.js b/modules/core/src/multipass/clear-pass.js deleted file mode 100644 index f5282df251..0000000000 --- a/modules/core/src/multipass/clear-pass.js +++ /dev/null @@ -1,21 +0,0 @@ -// -// A pass that clears the input buffer or the screen. -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import Pass from './pass'; - -export default class ClearPass extends Pass { - constructor(gl, props = {}) { - super(gl, Object.assign({id: 'clear-pass'}, props)); - } - - // TODO - add support for colors, align with model.clear and framebuffer.clear - // TODO - integrate with luma.gl clear, make sure right buffer is cleared - _renderPass() { - const {gl} = this; - const {clearBits = gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT} = this.props; - gl.clear(clearBits); - } -} diff --git a/modules/core/src/multipass/composite-pass.js b/modules/core/src/multipass/composite-pass.js deleted file mode 100644 index 48226b72eb..0000000000 --- a/modules/core/src/multipass/composite-pass.js +++ /dev/null @@ -1,26 +0,0 @@ -// -// A composite render pass. -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import Pass from './pass'; - -export default class CompositePass extends Pass { - constructor(gl, props = {}) { - props = Array.isArray(props) ? {passes: props} : props; - super(gl, Object.assign({id: 'composite-pass'}, props)); - } - - // Override render() to just forward the call - render(...args) { - const {passes = []} = this.props; - for (const pass of passes) { - pass.render(...args); - } - } - - delete() { - // Delete any resources crated - } -} diff --git a/modules/core/src/multipass/copy-pass.js b/modules/core/src/multipass/copy-pass.js deleted file mode 100644 index 443d0e4a18..0000000000 --- a/modules/core/src/multipass/copy-pass.js +++ /dev/null @@ -1,47 +0,0 @@ -// -// A pass that disables stencil test. -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import ClipSpace from '../lib/clip-space'; -import Pass from './pass'; - -const fs = `\ -uniform sampler2D uDiffuseSampler; -uniform float uOpacity; - -varying vec2 uv; - -void main() { - vec4 texel = texture2D(uDiffuseSampler, uv); - gl_FragColor = uOpacity * texel; -} -`; - -export default class CopyPass extends Pass { - constructor(gl, props = {}) { - super(gl, Object.assign({id: 'copy-pass', swap: true}, props)); - this.clipspace = new ClipSpace(gl, {id: 'copy-pass', fs}); - } - - delete() { - super.delete(); - this.clipspace.delete(); - } - - _renderPass({inputBuffer}) { - const {opacity = 1.0} = this.props; - - this.clipspace.draw({ - uniforms: { - uDiffuseSampler: inputBuffer, - uOpacity: opacity - }, - parameters: { - depthWrite: false, - depthTest: false - } - }); - } -} diff --git a/modules/core/src/multipass/mask-pass.js b/modules/core/src/multipass/mask-pass.js deleted file mode 100644 index 4af1054b43..0000000000 --- a/modules/core/src/multipass/mask-pass.js +++ /dev/null @@ -1,46 +0,0 @@ -// -// A mask pass. -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import Pass from './pass'; - -export default class MaskPass extends Pass { - constructor(gl, props = {}) { - super(gl, Object.assign({id: 'mask-pass'}, props)); - this.inverse = false; - this.clearStencil = true; - } - - _renderPass({gl}) { - let writeValue = 1; - let clearValue = 0; - if (this.inverse) { - writeValue = 0; - clearValue = 1; - } - - // don't update color or depth - gl.colorMask(false, false, false, false); - gl.depthMask(false); - - // set up stencil - gl.enable(gl.STENCIL_TEST); - gl.stencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE); - gl.stencilFunc(gl.ALWAYS, writeValue, 0xffffffff); - gl.clearStencil(clearValue); - - // TODO - draw into the stencil buffers of the two framebuffers - // renderer.render(this.scene, this.camera, this.readBuffer, this.clear); - // renderer.render(this.scene, this.camera, this.writeBuffer, this.clear); - - // re-enable update of color and depth - gl.colorMask(true, true, true, true); - gl.depthMask(true); - - // only render where stencil is set to 1 - gl.stencilFunc(gl.EQUAL, 1, 0xffffffff); // draw if == 1 - gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP); - } -} diff --git a/modules/core/src/multipass/multi-pass-renderer.js b/modules/core/src/multipass/multi-pass-renderer.js deleted file mode 100644 index d314ca4a13..0000000000 --- a/modules/core/src/multipass/multi-pass-renderer.js +++ /dev/null @@ -1,31 +0,0 @@ -// -// A top-level composite render pass, that manages render state -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import CompositePass from './composite-pass'; -import RenderState from './render-state'; - -export default class MultiPassRenderer extends CompositePass { - constructor(gl, props = {}) { - props = Array.isArray(props) ? {passes: props} : props; - super(gl, Object.assign({id: 'multi-pass'}, props)); - this.renderState = new RenderState(gl, props); - } - - // Override render() to just forward the call - render(animationProps) { - this.renderState.reset(); - const {passes = []} = this.props; - for (const pass of passes) { - pass.render(this.renderState, animationProps); - } - return this; - } - - delete() { - this.renderState.delete(); - super.delete(); - } -} diff --git a/modules/core/src/multipass/pass.js b/modules/core/src/multipass/pass.js deleted file mode 100644 index 75ce7775a6..0000000000 --- a/modules/core/src/multipass/pass.js +++ /dev/null @@ -1,73 +0,0 @@ -// -// A base render pass. -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import {Framebuffer, withParameters} from '@luma.gl/webgl'; - -export default class Pass { - constructor(gl, props = {}) { - const {id = 'pass'} = props; - this.id = id; // id of this pass - this.gl = gl; - this.props = {enabled: true, screen: false, swap: false}; - Object.assign(this.props, props); - } - - setProps(props) { - Object.assign(this.props, props); - } - - render(renderState, animationProps) { - if (!this.props.enabled) { - return; - } - - const gl = this.gl; - - const renderParams = { - gl, - outputBuffer: renderState.writeBuffer, - inputBuffer: renderState.readBuffer, - animationProps, - swapBuffers: () => renderState._swapFramebuffers() - }; - - // TODO: Calirfy/Fix : is `screen` or `swap` must be true at this point - // if so comment. We can also remove `enabled` from props and deduce that based on these two flags - if (this.props.screen) { - renderParams.inputBuffer = renderParams.outputBuffer; - renderParams.outputBuffer = Framebuffer.getDefaultFramebuffer(gl); - } else if (this.props.swap) { - renderParams.inputBuffer = renderState.writeBuffer; - renderParams.outputBuffer = renderState.readBuffer; - } - - withParameters(gl, {framebuffer: renderParams.outputBuffer}, () => - this._renderPass(renderParams) - ); - - if (this.props.debug) { - renderParams.outputBuffer.log(1, this.id); - } - - if (this.props.swap) { - renderState._swapFramebuffers(); - } - } - - delete() { - // Delete any resources crated - } - - /** - * Renders the effect. - * This is an abstract method that should be overridden. - * @param {Framebuffer} inputBuffer - Frame buffer that contains the result of the previous pass - * @param {Framebuffer} outputBuffer - Frame buffer that serves as the output render target - */ - _renderPass({gl, inputBuffer, outputBuffer, animationProps}) { - // assert(false, 'Draw/render methods not implemented!'); - } -} diff --git a/modules/core/src/multipass/render-pass.js b/modules/core/src/multipass/render-pass.js deleted file mode 100644 index 8e8b5662d2..0000000000 --- a/modules/core/src/multipass/render-pass.js +++ /dev/null @@ -1,21 +0,0 @@ -// -// A pass that renders a given scene directly on screen or into the read buffer -// for further processing. -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import Pass from './pass'; - -export default class RenderPass extends Pass { - constructor(gl, props = {}) { - super(gl, Object.assign({id: 'render-pass'}, props)); - } - - _renderPass({animationProps}) { - const {models = [], drawParams} = this.props; - for (const model of models) { - model.draw(Object.assign({}, drawParams, {animationProps})); - } - } -} diff --git a/modules/core/src/multipass/render-state.js b/modules/core/src/multipass/render-state.js deleted file mode 100644 index 0d56bd924b..0000000000 --- a/modules/core/src/multipass/render-state.js +++ /dev/null @@ -1,39 +0,0 @@ -// -// Render state helper class for the multi pass system -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import {Framebuffer} from '@luma.gl/webgl'; - -export default class RenderState { - constructor(gl, props = {}) { - this.gl = gl; - - this.framebuffer1 = new Framebuffer(gl, {id: 'multi-pass-1', stencil: true}); - this.framebuffer2 = new Framebuffer(gl, {id: 'multi-pass-2', stencil: true}); - - this.reset(); - } - - reset() { - this.framebuffer1.resize(); - this.framebuffer2.resize(); - - this.writeBuffer = this.framebuffer1; - this.readBuffer = this.framebuffer2; - - this.maskActive = false; - } - - delete() { - this.framebuffer1.delete(); - this.framebuffer2.delete(); - } - - _swapFramebuffers() { - const tmp = this.readBuffer; - this.readBuffer = this.writeBuffer; - this.writeBuffer = tmp; - } -} diff --git a/modules/core/src/multipass/shader-module-pass.js b/modules/core/src/multipass/shader-module-pass.js deleted file mode 100644 index 5a8372cc47..0000000000 --- a/modules/core/src/multipass/shader-module-pass.js +++ /dev/null @@ -1,151 +0,0 @@ -// -// A pass that renders a given texture into screen space -// - -import Pass from './pass'; -import CompositePass from './composite-pass'; -import ClipSpace from '../lib/clip-space'; - -import {normalizeShaderModule} from '@luma.gl/shadertools'; - -class ShaderModuleSinglePass extends Pass { - constructor(gl, props = {}) { - super(gl, Object.assign({swap: true}, props)); - } - - _renderPass({inputBuffer, swapBuffers}) { - this.props.model.setUniforms(this.props); - - // swapBuffers(); - this.props.model.draw({ - uniforms: { - texture: inputBuffer, - texSize: [inputBuffer.width, inputBuffer.height] - }, - parameters: { - depthWrite: false, - depthTest: false - } - }); - } -} - -export default class ShaderModulePass extends CompositePass { - constructor(gl, module, props = {}) { - const id = `${module.name}-pass`; - normalizeShaderModule(module); - const passes = normalizePasses(gl, module, id, props); - super(gl, Object.assign({id, passes}, props)); - this.module = module; - } - - _renderPass({inputBuffer, swapBuffers}) { - let first = true; - for (const pass of this.props.passes) { - if (!first) { - swapBuffers(); - } - first = false; - const {uniforms, model} = pass.props; - if (uniforms) { - model.setUniforms(uniforms); - } - // swapBuffers(); - model.draw({ - uniforms: { - texture: inputBuffer, - texSize: [inputBuffer.width, inputBuffer.height] - }, - parameters: { - depthWrite: false, - depthTest: false - } - }); - } - } -} - -function normalizePasses(gl, module, id, props) { - if (module.filter || module.sampler) { - const fs = getFragmentShaderForRenderPass(module); - const pass = new ShaderModuleSinglePass(gl, { - id, - model: getModel(gl, module, fs, id, props), - uniforms: null - }); - return [pass]; - } - - const passes = module.passes || []; - return passes.map(pass => { - const fs = getFragmentShaderForRenderPass(module, pass); - const idn = `${id}-${passes.length + 1}`; - - return new ShaderModuleSinglePass( - gl, - Object.assign( - { - id: idn, - model: getModel(gl, module, fs, idn, props), - uniforms: pass.uniforms - }, - props - ) - ); - }); -} - -function getModel(gl, module, fs, id, props) { - const model = new ClipSpace(gl, {id, fs, modules: [module]}); - - const uniforms = Object.assign(module.getUniforms(), module.getUniforms(props)); - - model.setUniforms(uniforms); - return model; -} - -const FILTER_FS_TEMPLATE = func => `\ -uniform sampler2D texture; -uniform vec2 texSize; - -varying vec2 position; -varying vec2 coordinate; -varying vec2 uv; - -void main() { - vec2 texCoord = coordinate; - - gl_FragColor = texture2D(texture, texCoord); - gl_FragColor = ${func}(gl_FragColor, texSize, texCoord); -} -`; - -const SAMPLER_FS_TEMPLATE = func => `\ -uniform sampler2D texture; -uniform vec2 texSize; - -varying vec2 position; -varying vec2 coordinate; -varying vec2 uv; - -void main() { - vec2 texCoord = coordinate; - - gl_FragColor = ${func}(texture, texSize, texCoord); -} -`; - -function getFragmentShaderForRenderPass(module, pass = module) { - if (pass.filter) { - const func = typeof pass.filter === 'string' ? pass.filter : `${module.name}_filterColor`; - return FILTER_FS_TEMPLATE(func); - } - - if (pass.sampler) { - const func = typeof pass.sampler === 'string' ? pass.sampler : `${module.name}_sampleColor`; - return SAMPLER_FS_TEMPLATE(func); - } - - // console.error(`${module.name} no fragment shader generated`); - return null; -} diff --git a/modules/core/src/multipass/stencil-pass.js b/modules/core/src/multipass/stencil-pass.js deleted file mode 100644 index 2d99fad270..0000000000 --- a/modules/core/src/multipass/stencil-pass.js +++ /dev/null @@ -1,74 +0,0 @@ -// -// A composite stencil pass. -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import {withParameters, setParameters} from '@luma.gl/webgl'; -import Pass from './pass'; - -function getMask(indices = [], bits = 8) { - let mask = 0; - indices.forEach(index => { - // assert(index >= 0 && index < bits); - mask = mask & (1 >> index); - }); - return mask; -} - -export default class StencilPass extends Pass { - constructor(gl, props = {}) { - super(gl, Object.assign({id: 'simple-outline-pass', swap: false}, props)); - this.props = Object.assign({}, props); - this.setProps(props); - } - - _renderPass({inputBuffer, outputBuffer, animationPropst}) { - const {gl} = this; - const stencilReadMask = getMask(this.props.stencils); - const stencilWriteMask = getMask(this.props.updateStencil); - - withParameters( - gl, - { - stencilTest: stencilReadMask !== 0 && stencilWriteMask !== 0, // turn on stencil buffers - stencilOp: [gl.KEEP, gl.KEEP, gl.REPLACE] // update stencil if both stencil+depth tests pass - }, - () => { - if (stencilReadMask) { - setParameters(gl, { - stencilFunc: [gl.EQUAL, 0, stencilReadMask] - }); - } - - setParameters(gl, { - stencilMask: stencilWriteMask - }); - - if (this.props.clearStencil) { - gl.clear(gl.STENCIL_BUFFER_BIT); - } - - // draw - for (const model of this.props.models) { - model.setUniforms(this.props.normalUniforms); - model.draw(this.props.drawParams); - } - - // Disable stencil writing, mask to stencil plane 0 - setParameters(gl, { - stencilFunc: [gl.EQUAL, 0, stencilReadMask], - stencilMask: 0x00 // disable writing to the stencil buffer - }); - - for (const model of this.props.models) { - model.setUniforms(this.props.outlineUniforms); - model.draw(this.props.drawParams); - model.setUniforms(this.props.normalUniforms); - } - - // All gl settings will reset here... - } - ); - } -} diff --git a/modules/core/src/multipass/texture-pass.js b/modules/core/src/multipass/texture-pass.js deleted file mode 100644 index defc78afd0..0000000000 --- a/modules/core/src/multipass/texture-pass.js +++ /dev/null @@ -1,48 +0,0 @@ -// -// A pass that renders a given texture into screen space -// -// Attribution: This class and the multipass system were inspired by -// the THREE.js EffectComposer and *Pass classes - -import {default as ClipSpace} from '../lib/clip-space'; -import Pass from './pass'; - -const fs = `\ -uniform sampler2D uDiffuseSampler; -uniform float uOpacity; -varying vec2 uv; - -void main() { - vec4 texel = texture2D(uDiffuseSampler, uv); - gl_FragColor = uOpacity * texel; -} -`; - -export default class TexturePass extends Pass { - constructor(gl, options = {}) { - super(gl, Object.assign({id: 'texture-pass'}, options)); - const {texture, opacity = 1.0} = options; - this.clipspace = new ClipSpace(gl, { - id: 'texture-pass', - fs, - uniforms: { - uDiffuseSampler: texture, - uOpacity: opacity - } - }); - } - - delete() { - this.clipspace.delete(); - super.delete(); - } - - _renderPass() { - this.clipspace.draw({ - parameters: { - depthWrite: false, - depthTest: false - } - }); - } -} diff --git a/modules/core/test/multipass/clear-mask-pass.spec.js b/modules/core/test/multipass/clear-mask-pass.spec.js deleted file mode 100644 index 3e79bcea16..0000000000 --- a/modules/core/test/multipass/clear-mask-pass.spec.js +++ /dev/null @@ -1,28 +0,0 @@ -// import {_ClearMaskPass as ClearMaskPass} from '@luma.gl/core'; -import {default as ClearMaskPass} from '@luma.gl/core/multipass/clear-mask-pass'; -import test from 'tape-catch'; -import {fixture} from 'test/setup'; - -test('ClearMaskPass#constructor', t => { - const {gl} = fixture; - - let cms = new ClearMaskPass(gl); - t.ok(cms instanceof ClearMaskPass, 'should construct ClearMaskPass object'); - - cms = null; - cms = new ClearMaskPass( - gl, - {enable: false}, - 'should construct ClearMaskPass object with custom props' - ); - t.end(); -}); - -test('ClearMaskPass#render', t => { - const {gl} = fixture; - - const cms = new ClearMaskPass(gl); - - t.doesNotThrow(() => cms.render(gl), 'render should work'); - t.end(); -}); diff --git a/modules/core/test/multipass/clear-pass.spec.js b/modules/core/test/multipass/clear-pass.spec.js deleted file mode 100644 index 6fca59e220..0000000000 --- a/modules/core/test/multipass/clear-pass.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -// import {Model} from '@luma.gl/core'; -import {_ClearPass as ClearPass} from '@luma.gl/core'; -import test from 'tape-catch'; -import {fixture} from 'test/setup'; - -test('ClearPass#constructor', t => { - const {gl} = fixture; - - let cp = new ClearPass(gl); - t.ok(cp instanceof ClearPass, 'should construct TexturePass object'); - - cp = null; - cp = new ClearPass(gl, {enable: false}, 'should construct TexturePass object with custom props'); - t.end(); -}); - -test('ClearPass#_renderPass', t => { - const {gl} = fixture; - - const cp = new ClearPass(gl); - - t.doesNotThrow(() => cp._renderPass({}), 'render should work'); - t.end(); -}); diff --git a/modules/core/test/multipass/composite-pass.spec.js b/modules/core/test/multipass/composite-pass.spec.js deleted file mode 100644 index 1207159a15..0000000000 --- a/modules/core/test/multipass/composite-pass.spec.js +++ /dev/null @@ -1,21 +0,0 @@ -import {_CompositePass as CompositePass, _Pass as Pass} from '@luma.gl/core'; -import test from 'tape-catch'; -import {fixture} from 'test/setup'; - -test('CompositePass#constructor', t => { - const {gl} = fixture; - let cp = new CompositePass(gl); - t.ok(cp instanceof CompositePass, 'should construct CompositePass object'); - - cp = null; - cp = new CompositePass(gl, [new Pass(gl)]); - t.ok(cp instanceof CompositePass, 'should construct CompositePass object'); - t.end(); -}); - -test('CompositePass#render', t => { - const {gl} = fixture; - const cp = new CompositePass(gl, [new Pass(gl, {enabled: false})]); - t.doesNotThrow(() => cp.render(), 'render should work'); - t.end(); -}); diff --git a/modules/core/test/multipass/copy-pass.spec.js b/modules/core/test/multipass/copy-pass.spec.js deleted file mode 100644 index ffd07571ed..0000000000 --- a/modules/core/test/multipass/copy-pass.spec.js +++ /dev/null @@ -1,35 +0,0 @@ -import {_CopyPass as CopyPass, Framebuffer} from '@luma.gl/core'; -import test from 'tape-catch'; -import {fixture, getResourceCounts, getLeakedResources} from 'test/setup'; - -test('CopyPass#constructor', t => { - const {gl} = fixture; - let cp = new CopyPass(gl); - t.ok(cp instanceof CopyPass, 'should construct CopyPass object'); - - cp = null; - cp = new CopyPass(gl, {swap: false}); - t.ok(cp instanceof CopyPass, 'should construct CopyPass object with props'); - t.end(); -}); - -test('CopyPass#_renderPass', t => { - const {gl} = fixture; - const cp = new CopyPass(gl); - t.doesNotThrow(() => cp._renderPass({inputBuffer: new Framebuffer(gl)}), 'render should work'); - t.end(); -}); - -test('CopyPass#delete', t => { - const {gl} = fixture; - const startCounts = getResourceCounts(); - const cp = new CopyPass(gl); - cp.delete(); - const endCounts = getResourceCounts(); - const leakedResources = getLeakedResources(startCounts, endCounts); - t.ok( - !leakedResources, - `should delete all resources, ${!leakedResources ? '' : leakedResources.info}` - ); - t.end(); -}); diff --git a/modules/core/test/multipass/index.js b/modules/core/test/multipass/index.js deleted file mode 100644 index df6fcf39ad..0000000000 --- a/modules/core/test/multipass/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import './pass.spec'; -import './multi-pass-render.spec'; -import './clear-mask-pass.spec'; -import './composite-pass.spec'; -import './copy-pass.spec'; -import './mask-pass.spec'; -import './render-pass.spec'; -import './stencil-pass.spec'; -import './texture-pass.spec'; -import './clear-pass.spec'; -import './shader-module-pass.spec'; diff --git a/modules/core/test/multipass/mask-pass.spec.js b/modules/core/test/multipass/mask-pass.spec.js deleted file mode 100644 index 637fecb37d..0000000000 --- a/modules/core/test/multipass/mask-pass.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -// import {_ClearMaskPass as ClearMaskPass} from '@luma.gl/core'; -import {default as MaskPass} from '@luma.gl/core/multipass/clear-mask-pass'; -import test from 'tape-catch'; -import {fixture} from 'test/setup'; - -test('ClearMaskPass#constructor', t => { - const {gl} = fixture; - - let mp = new MaskPass(gl); - t.ok(mp instanceof MaskPass, 'should construct MaskPass object'); - - mp = null; - mp = new MaskPass(gl, {enable: false}, 'should construct MaskPass object with custom props'); - t.end(); -}); - -test('ClearMaskPass#render', t => { - const {gl} = fixture; - - const mp = new MaskPass(gl); - - t.doesNotThrow(() => mp._renderPass(gl), 'render should work'); - t.end(); -}); diff --git a/modules/core/test/multipass/multi-pass-render.spec.js b/modules/core/test/multipass/multi-pass-render.spec.js deleted file mode 100644 index 145cd98547..0000000000 --- a/modules/core/test/multipass/multi-pass-render.spec.js +++ /dev/null @@ -1,41 +0,0 @@ -import {_MultiPassRenderer as MultiPassRenderer, _Pass as Pass} from '@luma.gl/core'; -import test from 'tape-catch'; -import {fixture, getResourceCounts, getLeakedResources} from 'test/setup'; - -test('MultiPassRenderer#constructor', t => { - const {gl2} = fixture; - - if (!gl2) { - // RenderState is creating Framebuffer with depth/stencil attachment (requires FEATURES.TEXTURE_DEPTH) - t.comment('WebGL2 not available, skipping tests'); - t.end(); - return; - } - - let mPass = new MultiPassRenderer(gl2); - t.ok(mPass instanceof MultiPassRenderer, 'should construct MultiPassRenderer object'); - - mPass = null; - mPass = new MultiPassRenderer(gl2, [new Pass(gl2), new Pass(gl2)]); - t.end(); -}); - -test('MultiPassRenderer#delete', t => { - const {gl2} = fixture; - if (!gl2) { - // RenderState is creating Framebuffer with depth/stencil attachment (requires FEATURES.TEXTURE_DEPTH) - t.comment('WebGL2 not available, skipping tests'); - t.end(); - return; - } - const startCounts = getResourceCounts(); - const mPass = new MultiPassRenderer(gl2); - mPass.delete(); - const endCounts = getResourceCounts(); - const leakedResources = getLeakedResources(startCounts, endCounts); - t.ok( - !leakedResources, - `should delete all resources, ${!leakedResources ? '' : leakedResources.info}` - ); - t.end(); -}); diff --git a/modules/core/test/multipass/pass.spec.js b/modules/core/test/multipass/pass.spec.js deleted file mode 100644 index 29f7ec5f46..0000000000 --- a/modules/core/test/multipass/pass.spec.js +++ /dev/null @@ -1,94 +0,0 @@ -import {_Pass as Pass, Framebuffer} from '@luma.gl/core'; -import {makeSpy} from '@probe.gl/test-utils'; -import test from 'tape-catch'; -import {fixture} from 'test/setup'; - -const CUSTOM_PROPS = { - enabled: false, - screen: true, - swap: true -}; - -test('Pass#constructor', t => { - const {gl} = fixture; - const pass = new Pass(gl); - t.ok(pass instanceof Pass, 'should construct Pass object'); - const {enabled, screen, swap} = pass.props; - t.ok(enabled && !screen && !swap, 'should set default props'); - t.end(); -}); - -test('Pass#constructor#customProps', t => { - const {gl} = fixture; - const pass = new Pass(gl, CUSTOM_PROPS); - t.ok(pass instanceof Pass, 'should construct Pass object'); - for (const key in CUSTOM_PROPS) { - t.equal(pass.props[key], CUSTOM_PROPS[key], `should set custom prop for ${key}`); - } - t.end(); -}); - -test('Pass#setProps', t => { - const {gl} = fixture; - const pass = new Pass(gl); - pass.setProps(CUSTOM_PROPS); - for (const key in CUSTOM_PROPS) { - t.equal(pass.props[key], CUSTOM_PROPS[key], `should set custom prop for ${key}`); - } - t.end(); -}); - -test('Pass#render (disabled)', t => { - const {gl} = fixture; - const pass = new Pass(gl); - const renderPassSpy = makeSpy(pass, '_renderPass'); - pass.setProps({enabled: false}); - pass.render(); - t.equal(renderPassSpy.callCount, 0, 'should skip rendering when disabled'); - renderPassSpy.restore(); - t.end(); -}); - -test('Pass#render (screen)', t => { - const {gl} = fixture; - const pass = new Pass(gl); - const renderPassSpy = makeSpy(pass, '_renderPass'); - let swapBuffersCalled = 0; - const swapBuffers = () => { - swapBuffersCalled++; - }; - const renderState = { - writeBuffer: new Framebuffer(gl), - _swapFramebuffers: swapBuffers - }; - pass.setProps({enabled: true, screen: true}); - pass.render(renderState); - t.equal(renderPassSpy.callCount, 1, 'should skip rendering when disabled'); - t.equal(swapBuffersCalled, 0, 'should not call swap'); - renderPassSpy.restore(); - t.end(); -}); - -test('Pass#render (swap)', t => { - const {gl} = fixture; - const pass = new Pass(gl); - const renderPassSpy = makeSpy(pass, '_renderPass'); - let swapBuffersCalled = 0; - const swapBuffers = () => { - swapBuffersCalled++; - }; - const renderState = { - readBuffer: new Framebuffer(gl), - writeBuffer: new Framebuffer(gl), - _swapFramebuffers: swapBuffers - }; - // const outBufferLogSpy = makeSpy(renderState.writeBuffer, 'log'); - pass.setProps({enabled: true, swap: true, debug: true}); - pass.render(renderState); - t.equal(renderPassSpy.callCount, 1, 'should call _renderPass'); - // t.equal(outBufferLogSpy.callCount, 1, 'should log output buffer'); - t.equal(swapBuffersCalled, 1, 'should call swap'); - renderPassSpy.restore(); - // outBufferLogSpy.restore(); - t.end(); -}); diff --git a/modules/core/test/multipass/render-pass.spec.js b/modules/core/test/multipass/render-pass.spec.js deleted file mode 100644 index b20825bcb9..0000000000 --- a/modules/core/test/multipass/render-pass.spec.js +++ /dev/null @@ -1,23 +0,0 @@ -import {_RenderPass as RenderPass, Model} from '@luma.gl/core'; -import test from 'tape-catch'; -import {fixture} from 'test/setup'; - -test('RenderPass#constructor', t => { - const {gl} = fixture; - - let rp = new RenderPass(gl); - t.ok(rp instanceof RenderPass, 'should construct MaskPass object'); - - rp = null; - rp = new RenderPass(gl, {enable: false}, 'should construct MaskPass object with custom props'); - t.end(); -}); - -test('RenderPass#_renderPass', t => { - const {gl} = fixture; - - const rp = new RenderPass(gl, {models: [new Model(gl)]}); - - t.doesNotThrow(() => rp._renderPass({}), 'render should work'); - t.end(); -}); diff --git a/modules/core/test/multipass/shader-module-pass.spec.js b/modules/core/test/multipass/shader-module-pass.spec.js deleted file mode 100644 index d36157bf17..0000000000 --- a/modules/core/test/multipass/shader-module-pass.spec.js +++ /dev/null @@ -1,38 +0,0 @@ -// import {Model} from '@luma.gl/core'; -import {_ShaderModulePass as ShaderModulePass, Framebuffer} from '@luma.gl/core'; -import {edgeWork} from '@luma.gl/effects'; -// import {normalizeShaderModule} from '@luma.gl/shadertools'; -import test from 'tape-catch'; -import {fixture} from 'test/setup'; - -test('ShaderModulePass#constructor', t => { - const {gl} = fixture; - - let sp = new ShaderModulePass(gl, edgeWork); - t.ok(sp instanceof ShaderModulePass, 'should construct TexturePass object'); - - sp = null; - sp = new ShaderModulePass( - gl, - edgeWork, - {enable: false}, - 'should construct TexturePass object with custom props' - ); - t.end(); -}); - -test('ShaderModulePass#_renderPass', t => { - const {gl} = fixture; - - const sp = new ShaderModulePass(gl, edgeWork); - - t.doesNotThrow( - () => - sp._renderPass({ - inputBuffer: new Framebuffer(gl), - swapBuffers: () => {} - }), - 'render should work' - ); - t.end(); -}); diff --git a/modules/core/test/multipass/stencil-pass.spec.js b/modules/core/test/multipass/stencil-pass.spec.js deleted file mode 100644 index 416d3a3b60..0000000000 --- a/modules/core/test/multipass/stencil-pass.spec.js +++ /dev/null @@ -1,28 +0,0 @@ -import {Model} from '@luma.gl/core'; -import {default as StencilPass} from '@luma.gl/core/multipass/stencil-pass'; -import test from 'tape-catch'; -import {fixture} from 'test/setup'; - -test('StencilPass#constructor', t => { - const {gl} = fixture; - - let rp = new StencilPass(gl); - t.ok(rp instanceof StencilPass, 'should construct StencilPass object'); - - rp = null; - rp = new StencilPass( - gl, - {enable: false}, - 'should construct StencilPass object with custom props' - ); - t.end(); -}); - -test('StencilPass#_renderPass', t => { - const {gl} = fixture; - - const rp = new StencilPass(gl, {models: [new Model(gl)], stencils: [0], clearStencil: true}); - - t.doesNotThrow(() => rp._renderPass({}), 'render should work'); - t.end(); -}); diff --git a/modules/core/test/multipass/texture-pass.spec.js b/modules/core/test/multipass/texture-pass.spec.js deleted file mode 100644 index 3fc215fde3..0000000000 --- a/modules/core/test/multipass/texture-pass.spec.js +++ /dev/null @@ -1,44 +0,0 @@ -// import {Model} from '@luma.gl/core'; -import {default as TexturePass} from '@luma.gl/core/multipass/texture-pass'; -import test from 'tape-catch'; -import {fixture, getResourceCounts, getLeakedResources} from 'test/setup'; - -test('TexturePass#constructor', t => { - const {gl} = fixture; - - let tp = new TexturePass(gl); - t.ok(tp instanceof TexturePass, 'should construct TexturePass object'); - - tp = null; - tp = new TexturePass( - gl, - {enable: false}, - 'should construct TexturePass object with custom props' - ); - t.end(); -}); - -test('TexturePass#_renderPass', t => { - const {gl} = fixture; - - const tp = new TexturePass(gl); - - t.doesNotThrow(() => tp._renderPass({}), 'render should work'); - t.end(); -}); - -test('TexturePass#delete', t => { - const {gl} = fixture; - - const startCounts = getResourceCounts(); - const tp = new TexturePass(gl); - tp.delete(); - const endCounts = getResourceCounts(); - const leakedResources = getLeakedResources(startCounts, endCounts); - t.ok( - !leakedResources, - `should delete all resources, ${!leakedResources ? '' : leakedResources.info}` - ); - - t.end(); -}); diff --git a/modules/core/test/webgl-dependent-tests.js b/modules/core/test/webgl-dependent-tests.js index 5f96db1209..cf327e4971 100644 --- a/modules/core/test/webgl-dependent-tests.js +++ b/modules/core/test/webgl-dependent-tests.js @@ -1,2 +1 @@ import './lib'; -import './multipass'; diff --git a/modules/effects/src/experimental/passes/outline-pass.js b/modules/effects/src/experimental/passes/outline-pass.js deleted file mode 100644 index 61e99e98f7..0000000000 --- a/modules/effects/src/experimental/passes/outline-pass.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * A traditional stencil buffer based outline pass. - */ - -import GL from '@luma.gl/constants'; -import {_Pass as Pass, withParameters, setParameters} from '@luma.gl/core'; - -export default class OutlinePass extends Pass { - constructor(gl, props = {}) { - super(gl, Object.assign({id: 'simple-outline-pass'}, props)); - this.setProps(props); - } - - setProps(props) { - this.props = Object.assign(this.props, props); - // this.clipspace.setUniforms(pixelation.getUniforms(this.props)); - } - - _renderPass({gl, animationProps}) { - withParameters( - gl, - { - stencilTest: true, // turn on stencil buffers - stencilOp: [GL.KEEP, GL.KEEP, GL.REPLACE] // update stencil if both stencil+depth tests pass - }, - () => { - // Enable writing to stencil buffer plane 0 - setParameters(gl, { - stencilFunc: [GL.ALWAYS, 1, 0xff], // update stencil buffer, regardless of current value - stencilMask: 0x01 - }); - - gl.clear(GL.STENCIL_BUFFER_BIT); - - // draw - for (const model of this.props.models) { - model.setUniforms(this.props.normalUniforms); - model.draw(this.props.drawParams); - } - - // Disable stencil writing, mask to stencil plane 0 - setParameters(gl, { - stencilFunc: [GL.NOTEQUAL, 1, 0x01], - stencilMask: 0x00, // disable writing to the stencil buffer - depthTest: false - }); - - for (const model of this.props.models) { - model.setUniforms(this.props.outlineUniforms); - model.draw(this.props.drawParams); - model.setUniforms(this.props.normalUniforms); - } - - // All GL settings will reset here... - } - ); - } -} diff --git a/modules/effects/src/experimental/passes/ssao-pass.js b/modules/effects/src/experimental/passes/ssao-pass.js deleted file mode 100644 index 0ba9bb79ca..0000000000 --- a/modules/effects/src/experimental/passes/ssao-pass.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Screen-space ambient occlusion pass. - * - * Ported to luma.gl from THREE.js (MIT license). - * Attributions (per comments in original THREE.js files): - * @author alteredq / http://alteredqualia.com/ - * @author tentone - */ - -/* eslint-disable camelcase */ -import {_Pass as Pass, Framebuffer, ClipSpace, withParameters} from '@luma.gl/core'; -import ssao from '../shader-modules/ssao'; - -export default class SSAOPass extends Pass { - constructor(gl, props) { - super(gl, Object.assign({id: 'ssao-pass', swap: true}, ssao.DEFAULT_PROPS, props)); - - this.renderToScreen = false; - - // Depth render target, for `depth` shader module - this.depthFramebuffer = new Framebuffer(gl, {id: 'ssao-pass-depth-map'}); - - this.clipspace = new ClipSpace(gl, { - id: 'ssao-pass', - modules: [ssao], - fs: ` - varying vec2 uv; - void main() { - gl_FragColor = ssao_getColor(uv); - } - ` - }); - - this.setProps(props); - } - - setProps(props) { - super.setProps(props); - - const {width = 512, height = 512} = this.props; - this.depthFramebuffer.resize({width, height}); - this.clipspace.setUniforms(this.props); - - // Shader uniforms - // this.uniforms['cameraNear' ].value = this.camera2.near; - // this.uniforms[ 'cameraFar' ].value = this.camera2.far; - } - - _renderPass({inputBuffer, outputBuffer, animationProps}) { - const {width, height} = inputBuffer; - this.depthFramebuffer.resize({width, height}); - - // Render depth into depthRenderTarget - withParameters(this.gl, {framebuffer: this.depthFramebuffer}, () => { - this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT); - for (const model of this.props.models) { - model.setUniforms({depth_uEnabled: true}); - model.draw(Object.assign({}, this.props.drawParams, {animationProps})); - model.setUniforms({depth_uEnabled: false}); - } - }); - - this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT); - this.clipspace.draw({ - animationProps, - uniforms: { - tDepth: this.depthFramebuffer, - tDiffuse: inputBuffer, - size: [this.depthFramebuffer.width, this.depthFramebuffer.height] - } - }); - } -} diff --git a/modules/effects/src/experimental/passes/ssao-pass.md b/modules/effects/src/experimental/passes/ssao-pass.md deleted file mode 100644 index 00b8d1917c..0000000000 --- a/modules/effects/src/experimental/passes/ssao-pass.md +++ /dev/null @@ -1,15 +0,0 @@ -# SSAOPass (Experimental) - -A Screen Space Ambient Occlusion Render Pass - -References: - -* Based on SSAO shader module - - -## Properties - -* `radius` - Ambient occlusion shadow radius (numeric value). -* `onlyAO` - Display only ambient occlusion result (boolean value). -* `aoClamp` - Ambient occlusion clamp (numeric value). -* `lumInfluence` - Pixel luminosity influence in AO calculation (numeric value). diff --git a/modules/effects/src/index.js b/modules/effects/src/index.js index 37bc099490..ebe8375f46 100644 --- a/modules/effects/src/index.js +++ b/modules/effects/src/index.js @@ -31,5 +31,3 @@ export {default as fxaa} from './shader-modules/fxaa/fxaa'; // experimental shader modules and passes export {default as _depth} from './experimental/shader-modules/depth'; export {default as _convolution} from './experimental/shader-modules/convolution'; -export {default as _OutlinePass} from './experimental/passes/outline-pass'; -export {default as _SSAOPass} from './experimental/passes/ssao-pass'; diff --git a/modules/glfx/LICENSE b/modules/glfx/LICENSE deleted file mode 100644 index d8703df912..0000000000 --- a/modules/glfx/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (C) 2011 by Evan Wallace - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/modules/glfx/README.md b/modules/glfx/README.md deleted file mode 100644 index 43e3b263e4..0000000000 --- a/modules/glfx/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# glfx - A WebGL powered image effects library - -Adjust photos in your browser in realtime with glfx. It uses your graphics card for image effects that would be impossible to apply in real-time with JavaScript alone. - - -## Attributions / Credits - -This is a luma.gl port of [glfx.js](https://github.com/evanw/glfx.js/), Ewan Wallace's WebGL powered image effects library. It includes improvements made by @daviestar in [glfx-es6](https://github.com/daviestar/glfx-es6). - - -## Remarks - -There are two caveats to glfx.js. - -* It requires WebGL, which is now ubiquitous. -* Due to the same origin policy, JavaScript is only allowed to read images that originate from the same domain as the script reading them, so you may have to host the images you modify. - - -## License - -Both the [glfx.js](https://github.com/evanw/glfx.js/LICENSE) and [glfx-es6](https://github.com/daviestar/glfx-es6/LICENSE) packages are MIT licensed, as is luma.gl. diff --git a/modules/glfx/bundle.js b/modules/glfx/bundle.js deleted file mode 100644 index 9607486698..0000000000 --- a/modules/glfx/bundle.js +++ /dev/null @@ -1,7 +0,0 @@ -/* global window, global */ -const moduleExports = require('./src'); - -const _global = typeof window === 'undefined' ? global : window; -_global.loaders = _global.luma || {}; - -module.exports = Object.assign(_global.luma, moduleExports); diff --git a/modules/glfx/package.json b/modules/glfx/package.json deleted file mode 100644 index aa9d76504f..0000000000 --- a/modules/glfx/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@luma.gl/glfx", - "description": "glfx - image processing packaged as composable shader modules", - "version": "7.4.0-alpha.2", - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/uber/luma.gl" - }, - "publishConfig": { - "access": "public" - }, - "main": "dist/es5/index.js", - "module": "dist/esm/index.js", - "esnext": "dist/es6/index.js", - "files": [ - "src", - "dist", - "README.md" - ], - "sideEffects": false, - "scripts": { - "pre-build": "npm run build-bundle && npm run build-bundle -- --env.dev", - "build-bundle": "webpack --display=minimal --config ../../scripts/bundle.config.js" - }, - "peerDependencies": { - "@luma.gl/core": "^7.1.0", - "@luma.gl/effects": "^7.1.0" - } -} diff --git a/modules/glfx/src/docs/canvas.md b/modules/glfx/src/docs/canvas.md deleted file mode 100644 index 2ffb60b01a..0000000000 --- a/modules/glfx/src/docs/canvas.md +++ /dev/null @@ -1,106 +0,0 @@ -# Canvas (Experimental) - -> This document is still being written. - -`Canvas` is a unique class that makes it possible to use filter-style image processing shader modules in a standard JavaScript application, without using the rest of the luma.gl API. - -The `Canvas` class was inspired by the `canvas` class in the glfx API. - - -## Usage - - -```js - - - -``` - -## Methods - -### Canvas Constructor - -var canvas = new Canvas(); - -Before you can apply any filters you will need a canvas, which stores the result of the filters you apply. Canvas creation is done through `new Canvas()`, which creates and returns a new WebGL tag with additional methods specific to glfx.js. This call will throw an error message if the browser doesn't support WebGL. - -### Canvas.destroy() - -Textures will be garbage collected eventually when they are no longer referenced, but this method will free GPU resources immediately. - - -### installFiltersAsMethods(filters : Object) - -Installs a map of shader filters as methods on the `Canvas` instance, as an alternative to calling them using `Canvas.filter`. - -### replace(node : HTMLElement) - - -### setTexture(element) - -Creates a texture that initially stores the image from an HTML element. Notice that texture() is a method on a canvas object, which means if you want to use the same image on two canvas objects you will need two different textures, one for each canvas. - -* `element` - The HTML element to store in the texture, either an , a , or a