Skip to content

npny/webgpgpu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

License MIT ES6 WebGL2 OpenGL ES 3.0

WebGPGPU, or WGU for short, is a WebGL2 based library enabling general purpose computation on the GPU.

Examples

const WGU = WebGPGPU(context);
new WGU.VertexFeedbackComputer({

	units: 8e5,
	struct: {
		position: "vec2",
		velocity: "vec2",
		mass: "float",
		color: "vec3"
	},

	initialize: (i, buffer) => {...}

	updateStep: {
		glsl: `
			void main() {
				o_position = i_position + i_velocity;
				o_velocity = i_velocity - 0.001 * i_position / i_mass;
				o_mass = i_mass;
				o_color = i_color;
			}
		`
	},

	renderStep: {
		glsl: `
			void main() {
				gl_Position = vec4(i_position, 0.0, 1.0);
				vertexColor = vec4(i_color, .5);
				gl_PointSize = i_mass/2.0;
			}
		`
	}

});

See this example in action here

The code above uses a VertexFeedbackComputer (a particular way of computing stuff provided by the library, relying on Vertex Buffers and OpenGL ES 3.0's Transform Feedback) to simulate a simple 800,000 particle system. Each particle has its own position, velocity, mass, and color, initially random, and is represented by a coloured point as it falls toward the origin.

Documentation

Documentation is available online here or in markdown form at master/build/docs

Download

Include the library from rawgit.com or download it locally

<script src="https://rawgit.com/npny/webgpgpu/master/src/webgpgpu.js"></script>
<script src="src/webgpgu.js"></script>

In order to use WebGPGPU in your page, you then need to initialize it with an existing, valid WebGL2 context:

<canvas id="canvas"></canvas>
<script>
	const canvas = document.getElementById("canvas");
	const context = canvas.getContext("webgl2");
	const WGU = WebGPGPU(context);

	// Let's get rolling
	new WGU.VertexFeedbackComputer();
</script>

License

WebGPGPU is released under the MIT license. Pierre Boyer, 2017.

Releases

No releases published

Packages

No packages published