1.0.8 • Published 3 years ago

vixel v1.0.8

Weekly downloads
2
License
Unlicense
Repository
github
Last release
3 years ago

Vixel

A WebGL path tracing voxel renderer built with regl.

vixel screenshot

vixel screenshot

Live demo

There's a voxel scene editor you can play with here that shows Vixel in action.

Example

const Vixel = require("vixel");

const canvas = document.createElement("canvas");
document.body.appendChild(canvas);

// Create a vixel object with a canvas and a width (x), height (y), and depth (z).
const vixel = new Vixel(canvas, 1, 1, 1);

vixel.camera(
  [2, 2, 2], // Camera position
  [0.5, 0.5, 0.5], // Camera target
  [0, 1, 0], // Up
  Math.PI / 4 // Field of view
);

vixel.set(
  0, // x
  0, // y
  0, // z
  {
    red: 1, // Red component
    green: 0.5, // Green component
    blue: 0.25 // Blue component
  }
);

// Take 1024 path traced samples per pixel
vixel.sample(1024);

// Show the result on the canvas
vixel.display();

The code in the example above will result in the following image:

Installation

npm i --save vixel

API

const Vixel = require('vixel')

Constructor

const vixel = new Vixel(canvas, width, height, depth)

Returns a new Vixel object.

ParameterTypeDescription
canvasCanvas objectThe canvas to render to.
widthintegerThe width of the voxel grid (x-coordinate).
heightintegerThe height of the voxel grid (y-coordinate).
depthintegerThe depth of the voxel grid (z-coordinate).

Methods

Methods marked with an asterisk (*) will reset the renderer. This will clear the collected samples and require new samples to converge the scene.

Methods marked with a double asterisk (**) will reset both the renderer and require the voxel grid to be reuploaded to the GPU on the next call to vixel.sample. Reuploading can be slow depending on the size of the voxel grid.

vixel.set(x, y, z, options)**

Sets a voxel at coordinates x, y, z with configuration options.

ParameterTypeDescription
xintegerThe x-coordinate of the voxel.
yintegerThe y-coordinate of the voxel.
zintegerThe z-coordinate of the voxel.
optionsObjectConfiguration of the voxel. See options below.
options
OptionTypeDefaultDescription
redfloat1.0The red component of the voxel color.
greenfloat1.0The green component of the voxel color.
bluefloat1.0The blue component of the voxel color.
roughfloat1.0The roughness of the voxel surface. Zero is perfectly smooth, one is completely rough.
metalfloat0.0The metalness of the voxel surface. Zero is completely nonmetallic, one is fully metallic.
transparentfloat0.0The transparency of the voxel. Zero is completely opaque, one is completely clear.
refractfloat1.0The refraction index of the voxel. Air has a value of 1.0, glass is around 1.333.
emitfloat0.0The amount of light the voxel emits. If this is nonzero, rough, metal, transparent, and refract will be ignored.

vixel.unset(x, y, z)**

Unsets the voxel at coordinates x, y, z.

vixel.get(x, y, z)

Returns the configuration of the voxel at coordinates x, y, z. See the options definition of vixel.set for information about the returned configuration object. Returns undefined if the voxel at the given coordinates is not set.

ParameterTypeDescription
xintegerThe x-coordinate of the voxel.
yintegerThe y-coordinate of the voxel.
zintegerThe z-coordinate of the voxel.

vixel.clear()**

Clears the voxel grid.

vixel.camera(eye, center, up, fov)*

Configures the camera.

ParameterTypeDescription
eyefloat array x, y, zThe position of the camera.
centerfloat array x, y, zThe point the camera is facing.
upfloat array x, y, zThe up direction. Typically 0, 1, 0.
fovfloatThe field of view in radians. Typically around PI/3.

vixel.ground(color, rough, metal)*

Configures the ground. Cannot currently be disabled.

ParameterTypeDescription
colorfloat array red, green, blueThe red, green, and blue color components of the ground.
roughfloatThe roughness of the ground. Zero is perfectly smooth, one is completely rough.
metalfloatThe metalness of the ground. Zero is completely nonmetallic, one is fully metallic.

vixel.sun(time, azimuth, radius, intensity)*

Configures the sky and sun.

ParameterTypeDescription
timefloatTime of day in hours, 0 to 24. 6.0 is sunrise, 18.0 is sunset.
azimuthfloatThe angle of the sun on the horizon in radians. 0.0 places the sun in the positive-x direction.
radiusfloatThe radius of the sun. 1.0 represents a physically-accurate sun radius.
intensityfloatThe intensity of sunlight.

vixel.dof(distance, magnitude)*

Configures depth of field.

ParameterTypeDescription
distancefloatThe distance at which the focus plane exists, in terms of the size of the voxel grid. Zero is the nearest point, 0.5 is halfway through the grid, one is at the far side of the grid.
magnitudefloatThe magnitude of the depth of field effect. Zero disables the effect.

vixel.sample(count)

Takes count path traced samples of the scene.

vixel.display()

Displays the scene sampled with vixel.sample on the Canvas provided to the constructor.

vixel.serialize()

Returns an object representing the populated voxel grid that can be deserialized with the vixel.deserialize function.

vixel.deserialize(data)

Populates the voxel grid with data from the vixel.serialize function.

Members

vixel.sampleCount

The number of samples that have been collected since the last time the renderer was reset.

1.0.2

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

5 years ago

1.0.0

5 years ago