Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Novice's Guide to WebGL

A Novice's Guide to WebGL

Introduction to 3D, shaders and WebGL.

krzychukula

April 26, 2017
Tweet

More Decks by krzychukula

Other Decks in Programming

Transcript

  1. Plan 1. Intro 2. How it all works 3. Triangle

    4. Multiple colours 5. Matrix 6. Learn
  2. gl_Position = vec4(0.0, 0.5, 0.0, 1.0); gl_Position = vec4(-0.5, -0.5,

    0.0, 1.0); gl_Position = vec4(0.5, -0.5, 0.0, 1.0); -0.5, -0.5 0, 0.5 -0.5, 0.5
  3. var positions = new Float32Array([ 0.0, 0.5, 0.0, 1.0, -0.5,

    -0.5, 0.0, 1.0, 0.5, -0.5, 0.0, 1.0 ]);
  4. var positions = new Float32Array([ 0.0, 0.5, 0.0, 1.0, -0.5,

    -0.5, 0.0, 1.0, 0.5, -0.5, 0.0, 1.0 ]);
  5. Vertex Shader attribute vec4 a_Position; attribute vec4 a_Color; varying vec4

    v_Color; void main() { gl_Position = a_Position; v_Color = a_Color; }
  6. Vertex Shader void main(vec4 a_Position, vec4 a_Color) { return {

    gl_Position: a_Position, v_Color: a_Color }; }
  7. v_Color = vec4(1.0, 0.0, 0.0, 1.0); v_Color = vec4(0.0, 1.0,

    0.0, 1.0); v_Color = vec4(0.0, 0.0, 1.0, 1.0);
  8. var colors = new Float32Array([ 1.0, 0.0, 0.0, 1.0, 0.0,

    1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0 ]);
  9. https:/ /hacks.mozilla.org/2017 /01/webgl-2-lands-in-firefox/ https:/ /www.chromeexperiments.com/globe https:/ /codepen.io/krzychukula/pen/qmZaMz?editors=0010 Triangle https:/ /codepen.io/krzychukula/pen/OmXgKe?editors=0010

    Triangle 3 colors https:/ /codepen.io/krzychukula/pen/OmXgKe?editors=0010 Triangle 3 colors in one buffer https:/ /www.packtpub.com/game-development/webgl-beginners-guide https:/ /www.udacity.com/course/interactive-3d-graphics--cs291 https:/ /sites.google.com/site/webglbook/
  10. QA (ideas) Libraries? How shadertoy works? How to use one

    buffer for vertex and colors data? How textures work? How many lines of code those examples have?