Home

Awesome

geo-ambient-occlusion

Generates a per-vertex ambient occlusion array for arbitrary meshes.

<p align="center"> <img src="https://github.com/wwwtyro/media/raw/master/geo-ambient-occlusion-000.png" width="25%"> </p>

Demo

Support notes

How does it work?

geo-ambient-occlusion renders multiple shadow maps for your mesh from random viewpoints. It averages the occlusion for each vertex across all the shadow maps to calculate an ambient occlusion value for each. This data is converted into a Float32Array of occlusion values and returned to you for immediate use as an attribute in your shader program.

geo-ambient-occlusion is built on top of the disgustingly good regl WebGL library.

Install

npm install geo-ambient-occlusion

Example

let dragon = require('stanford-dragon/2');
const geoao = require('geo-ambient-occlusion');

const aoSampler = geoao(dragon.positions, { cells: dragon.cells });

for (let i = 0; i < 256; i++) {
  aoSampler.sample();
}

const ao = aoSampler.report();

aoSampler.dispose();

API

const geoao = require('geo-ambient-occlusion')

Constructor

const aoSampler = geoao(positions[, opts])

positions is the vertex array for your mesh. It can be any of:

opts is an object that can have the following properties:

Methods

aoSampler.sample()

Collects a single sample of ambient occlusion data. Run this several hundred times to reach a useful average.

const ao = aoSampler.report()

Returns the average ambient occlusion, per vertex, sampled so far. Format is a Float32Array.

aoSampler.dispose()

Disposes of all resources used for this sampling. Does not dispose of the internal regl context if it was provided by the user. Behavior of aoSampler after calling this function is undefined.