src/util/sh.js
function projectEnvironmentMapGPU(renderer, envMap) {
    var shTexture = new Texture2D({
        width: 9,
        height: 1,
        type: Texture.FLOAT
    });
    var pass = new Pass({
        fragment: projectEnvMapShaderCode
    });
    pass.material.define('fragment', 'TEXTURE_SIZE', envMap.width);
    pass.setUniform('environmentMap', envMap);

    var framebuffer = new FrameBuffer();
    framebuffer.attach(shTexture);
    pass.render(renderer, framebuffer);

    framebuffer.bind(renderer);
    // TODO Only chrome and firefox support Float32Array
    var pixels = new vendor.Float32Array(9 * 4);
    renderer.gl.readPixels(0, 0, 9, 1, Texture.RGBA, Texture.FLOAT, pixels);

    var coeff = new vendor.Float32Array(9 * 3);
    for (var i = 0; i < 9; i++) {
        coeff[i * 3] = pixels[i * 4];
        coeff[i * 3 + 1] = pixels[i * 4 + 1];
        coeff[i * 3 + 2] = pixels[i * 4 + 2];
    }
    framebuffer.unbind(renderer);

    framebuffer.dispose(renderer);
    pass.dispose(renderer);
    return coeff;
}
function projectEnvironmentMapGPU(renderer, envMap) {
    var shTexture = new Texture2D({
        width: 9,
        height: 1,
        type: Texture.FLOAT
    });
    var pass = new Pass({
        fragment: projectEnvMapShaderCode
    });
    pass.material.define('fragment', 'TEXTURE_SIZE', envMap.width);
    pass.setUniform('environmentMap', envMap);

    var framebuffer = new FrameBuffer();
    framebuffer.attach(shTexture);
    pass.render(renderer, framebuffer);

    framebuffer.bind(renderer);
    // TODO Only chrome and firefox support Float32Array
    var pixels = new vendor.Float32Array(9 * 4);
    renderer.gl.readPixels(0, 0, 9, 1, Texture.RGBA, Texture.FLOAT, pixels);

    var coeff = new vendor.Float32Array(9 * 3);
    for (var i = 0; i < 9; i++) {
        coeff[i * 3] = pixels[i * 4];
        coeff[i * 3 + 1] = pixels[i * 4 + 1];
        coeff[i * 3 + 2] = pixels[i * 4 + 2];
    }
    framebuffer.unbind(renderer);

    framebuffer.dispose(renderer);
    pass.dispose(renderer);
    return coeff;
}
function projectEnvironmentMapGPU ( renderer , envMap ) { var shTexture = new Texture2D ( { width : 9 , height : 1 , type : Texture . FLOAT } ) ; var pass = new Pass ( { fragment : projectEnvMapShaderCode } ) ; pass . material . define ( 'fragment' , 'TEXTURE_SIZE' , envMap . width ) ; pass . setUniform ( 'environmentMap' , envMap ) ; var framebuffer = new FrameBuffer ( ) ; framebuffer . attach ( shTexture ) ; pass . render ( renderer , framebuffer ) ; framebuffer . bind ( renderer ) ; // TODO Only chrome and firefox support Float32Array var pixels = new vendor . Float32Array ( 9 * 4 ) ; renderer . gl . readPixels ( 0 , 0 , 9 , 1 , Texture . RGBA , Texture . FLOAT , pixels ) ; var coeff = new vendor . Float32Array ( 9 * 3 ) ; for ( var i = 0 ; i < 9 ; i ++ ) { coeff [ i * 3 ] = pixels [ i * 4 ] ; coeff [ i * 3 + 1 ] = pixels [ i * 4 + 1 ] ; coeff [ i * 3 + 2 ] = pixels [ i * 4 + 2 ] ; } framebuffer . unbind ( renderer ) ; framebuffer . dispose ( renderer ) ; pass . dispose ( renderer ) ; return coeff ; }
Project on gpu, but needs browser to support readPixels as Float32Array.
Project on gpu but needs browser to support readPixels as Float32Array .