Index

skparallelreduce.js/skparallelreduce.js

JavaScript/GLSL parallel reduction for Three.js
Version:
  • 1.0.3
Author:
Source:

Example

//create a parallel reducer
var textureRes = 1024;
var reductionStopRes = 1;
var pr = new SKPR.ParallelReducer(threejsWebGLRenderer, textureRes, reductionStopRes);

//reduce a given texture / render target
var reductionOp = 'sum';
var textureChannel = 'r';
pr.reduce(threejsRenderTargetToReduce, reductionOp, textureChannel);

//if you want to read the resulting float data from the GPU to the CPU (expensive operation):
var resultFloat32Array = pr.getPixelFloatData(textureChannel);
var sum = 0;
var i, len;
for (i = 0, len = resultFloat32Array.length; i < len; i++) {
    sum += resultFloat32Array[i];
}