hemisphere-sample
Version:
Uniform and cosinus hemisphere sampling using hammersley point set
35 lines (28 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hemisphereSampleUniform = hemisphereSampleUniform;
exports.hemisphereSampleCos = hemisphereSampleCos;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _hammersley = require("hammersley");
var _hammersley2 = _interopRequireDefault(_hammersley);
var PI = Math.PI;
function hemisphereSampleUniform(i, N) {
var hPoint = (0, _hammersley2["default"])(i, N);
var u = hPoint[0];
var v = hPoint[1];
var phi = v * 2.0 * PI;
var cosTheta = 1.0 - u;
var sinTheta = Math.sqrt(1.0 - cosTheta * cosTheta);
return [Math.cos(phi) * sinTheta, Math.sin(phi) * sinTheta, cosTheta];
}
function hemisphereSampleCos(i, N) {
var hPoint = (0, _hammersley2["default"])(i, N);
var u = hPoint[0];
var v = hPoint[1];
var phi = v * 2.0 * PI;
var cosTheta = Math.sqrt(1.0 - u);
var sinTheta = Math.sqrt(1.0 - cosTheta * cosTheta);
return [Math.cos(phi) * sinTheta, Math.sin(phi) * sinTheta, cosTheta];
}