• Stars
    star
    317
  • Rank 132,216 (Top 3 %)
  • Language
    JavaScript
  • License
    The Unlicense
  • Created almost 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A WebGL voxel path tracer

Vixel

A WebGL path tracing voxel renderer built with regl.

vixel screenshot

vixel screenshot

Live demo

There's a voxel scene editor you can view 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.

Parameter Type Description
canvas Canvas object The canvas to render to.
width integer The width of the voxel grid (x-coordinate).
height integer The height of the voxel grid (y-coordinate).
depth integer The 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.

Parameter Type Description
x integer The x-coordinate of the voxel.
y integer The y-coordinate of the voxel.
z integer The z-coordinate of the voxel.
options Object Configuration of the voxel. See options below.
options
Option Type Default Description
red float 1.0 The red component of the voxel color.
green float 1.0 The green component of the voxel color.
blue float 1.0 The blue component of the voxel color.
rough float 1.0 The roughness of the voxel surface. Zero is perfectly smooth, one is completely rough.
metal float 0.0 The metalness of the voxel surface. Zero is completely nonmetallic, one is fully metallic.
transparent float 0.0 The transparency of the voxel. Zero is completely opaque, one is completely clear.
refract float 1.0 The refraction index of the voxel. Air has a value of 1.0, glass is around 1.333.
emit float 0.0 The 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.

Parameter Type Description
x integer The x-coordinate of the voxel.
y integer The y-coordinate of the voxel.
z integer The z-coordinate of the voxel.

vixel.clear()**

Clears the voxel grid.

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

Configures the camera.

Parameter Type Description
eye float array [x, y, z] The position of the camera.
center float array [x, y, z] The point the camera is facing.
up float array [x, y, z] The up direction. Typically [0, 1, 0].
fov float The field of view in radians. Typically around PI/3.

vixel.ground(color, rough, metal)*

Configures the ground. Cannot currently be disabled.

Parameter Type Description
color float array [red, green, blue] The red, green, and blue color components of the ground.
rough float The roughness of the ground. Zero is perfectly smooth, one is completely rough.
metal float The metalness of the ground. Zero is completely nonmetallic, one is fully metallic.

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

Configures the sky and sun.

Parameter Type Description
time float Time of day in hours, 0 to 24. 6.0 is sunrise, 18.0 is sunset.
azimuth float The angle of the sun on the horizon in radians. 0.0 places the sun in the positive-x direction.
radius float The radius of the sun. 1.0 represents a physically-accurate sun radius.
intensity float The intensity of sunlight.

vixel.dof(distance, magnitude)*

Configures depth of field.

Parameter Type Description
distance float The 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.
magnitude float The 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.

More Repositories

1

cryptico

An easy-to-use encryption system utilizing RSA and AES for javascript.
JavaScript
1,174
star
2

glsl-atmosphere

Renders sky colors with Rayleigh and Mie scattering.
GLSL
583
star
3

Astray

A WebGL maze game built with Three.js and Box2dWeb.
JavaScript
503
star
4

space-3d

Quickly generate procedural 3D space scenes in your browser with WebGL
JavaScript
500
star
5

candygraph

Fast by default, flexible 2D plotting library.
TypeScript
434
star
6

badlands

procedural badlands
JavaScript
417
star
7

speck

Browser-based WebGL molecule renderer with the goal of producing figures that are as attractive as they are practical.
JavaScript
397
star
8

instanced-lines-demos

This is the source for the demos in my blog post Instanced Line Rendering.
JavaScript
226
star
9

keyzen

A touch typing trainer geared towards programmers and others that need to practice with all the symbols on the keyboard.
JavaScript
195
star
10

sdf-csg

Generate meshes from signed distance functions and constructive solid geometry operations.
JavaScript
178
star
11

dis-gui

An extensible, styleable, & React-based controller library inspired by the venerable dat-gui.
JavaScript
176
star
12

map-tile-lighting-demo

JavaScript
172
star
13

geo-ambient-occlusion

Generates a per-vertex ambient occlusion array for arbitrary meshes.
JavaScript
165
star
14

planet-3d

Procedural 3D planet texture and 2D planet sprite generator.
JavaScript
139
star
15

canvas-video-generator

Capture HTML5 canvas frames and render high quality video with FFMPEG.
JavaScript
137
star
16

space-2d

Fast procedural 2D space scene generation on the GPU.
JavaScript
133
star
17

procedural.js

JavaScript
106
star
18

space-scene-2d

Procedural generator for 2D space scenes.
JavaScript
96
star
19

caffeine

Path tracing demo
JavaScript
95
star
20

astray-2

A real-time WebGL path tracing maze game proof-of-concept
JavaScript
73
star
21

perlin.js

A javascript 1, 2, and 3-dimensional perlin noise generator.
JavaScript
72
star
22

vixel-editor

A javascript & webgl voxel path tracer.
JavaScript
52
star
23

python-ovrsdk

Cross-platform Python wrapper for the Oculus VR SDK C API
Python
49
star
24

three-vr-renderer

VR renderer for THREE.js utilizing the upcoming VR APIs in popular browsers.
JavaScript
43
star
25

rounded-box-figures

TypeScript
38
star
26

rounded-box

Generates a rounded box mesh centered on the origin with configurable dimensions, corner and edge radius, and resolution.
TypeScript
37
star
27

instanced-lines-2

TypeScript
35
star
28

isosurface-generator

A JS generator function that returns a list of vertices describing an isosuface given a density and level.
JavaScript
35
star
29

flameout

JavaScript
33
star
30

proceduro

A collection of procedural generation tools in a desktop application.
JavaScript
31
star
31

regl-atmosphere-envmap

Easily generate an environment map, or skybox, of Earth atmosphere given a 3D vector representing the direction of the sun.
JavaScript
30
star
32

cellophane

A dead simple web terminal that gets all of the boilerplate out of the way and lets you do 100% of your work on the server side and in python.
Python
28
star
33

regl-irradiance-envmap

Easily generate an irradiance environment map from an existing environment map.
JavaScript
27
star
34

nw-ovrsdk-helloworld

A bare-bones example of using node-webkit, THREE.js, and node-ovrsdk to make an Oculus Rift application.
JavaScript
26
star
35

brownie.js

A javascript library for creating and rendering (with THREE.js) voxel objects.
JavaScript
18
star
36

node-ovrsdk

Node FFI wrapper for the 0.3.2 Oculus VR SDK C API
JavaScript
18
star
37

spaceship-2d

Create 2D spaceship diffuse, normal, depth, and position sprites with ambient occlusion through directed evolution.
JavaScript
18
star
38

conway3d.js

Conway's Game of Life, in 3D, in Javascript.
JavaScript
16
star
39

toothless

HTML
16
star
40

trackball-controller

Captures mouse events on an element and translates them to trackball-like motion.
JavaScript
16
star
41

pyrift

Python wrapper for the Oculus Rift SDK
C++
12
star
42

geo-3d-transform-mat4

Transform geometry positions with a 4x4 transformation matrix.
JavaScript
12
star
43

geo-center

Centers vertices around a point.
JavaScript
11
star
44

stackgl-shader-experiment

Generates boilerplate for experimenting with a fragment shader.
JavaScript
10
star
45

webrift

An Oculus Rift websocket server
Python
10
star
46

regl-render-envmap

A simple tool for rendering environment maps with regl.
JavaScript
9
star
47

gl-skybox

Draws a skybox into a 3D scene.
JavaScript
9
star
48

webgpu-prng-example

A WebGPU example demonstrating pseudorandom number generation.
TypeScript
8
star
49

gl-render-cubemap

Renders a scene to a cubemap.
JavaScript
7
star
50

regl-webxr-example

Bare-bones example of using WebXR with regl.
JavaScript
6
star
51

gl-format-compiler-error

Formats a webgl glsl compiler error.
JavaScript
6
star
52

cmdy

A tool for managing your utility scripts. Supports subcommands.
Python
6
star
53

wwwtyro.github.io

HTML
5
star
54

webgl-perlin2d-example

JavaScript
4
star
55

gl-texture-cube

Wraps WebGL's cube texture object.
JavaScript
4
star
56

tumblebluff

JavaScript
3
star
57

AegisLuna

Game entry for pyweek September 2013
Python
3
star
58

latexyt

A clone of the popular Mac OS program latexit for GTK/linux.
Python
3
star
59

simple-pan

JavaScript
2
star
60

game-off-2022-public

My Game Off 2022 Entry, public repo with assets removed.
TypeScript
2
star
61

gl-cubemap-placeholder

Simple debug cubemap generator.
JavaScript
2
star
62

jjviz

JavaScript
2
star
63

geo-convert-position-format

Converts between a few common geometry position formats.
JavaScript
2
star
64

gevent-websocket

Python
2
star
65

kdb-viewer

A simple webgl xyz file renderer for the [KDB](http://theory.cm.utexas.edu/KDB/) project.
JavaScript
2
star
66

geo-identify-position-format

Identifies geometry position format as flat array, array of arrays, typed array, or 1D ndarray.
JavaScript
2
star
67

share

Things I want to share.
Python
1
star
68

tests

JavaScript
1
star
69

juju-status

Compact, no-wrap, colored Juju status.
Python
1
star
70

bins

1
star
71

retired

JavaScript
1
star
72

geogame

JavaScript
1
star
73

layer-freeciv-server

Charm layer for a freeciv server.
Python
1
star
74

k8s-snap-bot-test

Makefile
1
star
75

cdk-cli

A command line utility for performing various tasks related to the management of the Canonical Distribution of Kubernetes.
Python
1
star
76

media

1
star
77

toothless-pkg

Packaging utilities for Toothless
Makefile
1
star
78

widgiverse-editor-demo

Demo for the Widgiverse editor.
1
star