https://github.com/hughsk/voxel-glslgen
Push voxel.js terrain generation to the GPU using a GLSL shader
https://github.com/hughsk/voxel-glslgen
Last synced: 3 months ago
JSON representation
Push voxel.js terrain generation to the GPU using a GLSL shader
- Host: GitHub
- URL: https://github.com/hughsk/voxel-glslgen
- Owner: hughsk
- Created: 2013-02-17T01:13:43.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-02-20T13:12:25.000Z (over 12 years ago)
- Last Synced: 2024-10-17T16:37:27.561Z (8 months ago)
- Language: JavaScript
- Homepage: http://hughsk.github.com/voxel-glslgen/demo
- Size: 717 KB
- Stars: 17
- Watchers: 8
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# voxel-glslgen #
Push voxel terrain generation to the GPU using a GLSL shader. This is just
a WIP and an experiment with offloading computation to a shader, so no
guarantees that it is *actually* faster than vanilla JavaScript - but feel
free to submit a Pull Request with performance/API improvements.*Note: this currently only works on the master branches for voxel and
voxel-engine*## Installation ##
``` bash
npm install voxel-glslgen
```## Usage ##
**glslgen(shader, [options], [setup])**
Takes a string fragment shader and returns a generate function.
``` javascript
var createGame = require('voxel-engine')
, glslgen = require('voxel-glslgen')var game({
generate: glslgen([
'void main() {'
, 'vec3 pos = voxelPosition();'
, 'voxelBlock(pos.y < 0.0 ? 1.0 : 0.0);'
, '}'
].join('\n'))
})
```The module exposes two GLSL functions:
* `vec3 voxelPosition()` - returns the x,y,z coordinates of the current voxel.
* `void voxelBlock(n)` - set the voxel block index.You can also pass the following parameters to the `options` object:
* `cacheSize`: Amount of chunks to store at any one time. Defaults to 4.
* `chunkSize`: The size of each chunk in voxels - defaults to `game.chunkSize`
and limited to a maximum of 32.The `setup` argument is a callback which supplies the shader used by the
generator. You can use this if you want to extend the shader somehow.