By day
By night
Basically
Caveat: I approach WebGL from a mathematical, progamming perspective rather than a web design perspective
† the verb form is the only correct use of “math” all other forms are an abomination before man and God
meetup.com/WebGL-Workshop-London | |
[email protected] | |
@CarlBateman |
• For the pizza & beer
• With whom I am affiliated
• Venue
• With whom I am in no way affiliated
• 45% discount "WebGL Programming Guide" eBook edition
• Check out the MeetUp page
After workshop drinkies and
further networking
Ask questions
Takes photos
Tweet!!!
#WebGLWorkshop
GLSL part 2
Website
WebGLWorkshop.com/22
Download
WebGLWorkshop.com/22/workshop22.zip
“WebGL is a royalty-free, cross-platform API that brings OpenGL ES 2.0 to the web as a 3D drawing context within HTML, exposed as low-level Document Object Model interfaces.
“It uses the OpenGL shading language, GLSL ES, and can be cleanly combined with other web content that is layered on top or underneath the 3D content.
“It is ideally suited for dynamic 3D web applications in the JavaScript programming language, and will be fully integrated in leading web browsers.”
Khronos.org
“Just” a renderer / rasteriser, but can be bent to our will
e.g. image processing
JavaScriptCreate Context/Canvas Draw commands Data control GLSLShader program Vertex shader transform vertices Fragment (pixel) shader transform pixels |
Simple vertex shader
Simple fragment shader
C-like
Strongly typed
Optimised for geometry
Native support of vectors and matrices (no quaternions)
Built-in geometry functions e.g. cos, sin, dot, cross, reflect
Swizzle:
vec3 v1, v2;
v1[0] = v2.r;
v1.xyz = v2.rgb;
v1.zyx = v2.bbb;
Textures via sampler2D and texture2D (no 1D or 3D textures)
var camera, scene, renderer, mesh;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 400;
scene = new THREE.Scene();
var texture = THREE.ImageUtils.loadTexture( 'textures/crate.gif' );
var geometry = new THREE.BoxGeometry( 200, 200, 200 );
var material = new THREE.MeshBasicMaterial( { map: texture } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
mesh.rotation.x += 0.005;
mesh.rotation.y += 0.01;
renderer.render( scene, camera );
}