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

Introduction to WebGL

krzychukula
November 28, 2017

Introduction to WebGL

Basics of WebGL extended with Shadertoy new project description.

krzychukula

November 28, 2017
Tweet

More Decks by krzychukula

Other Decks in Programming

Transcript

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

    in WebGL 4. Multiple colours 5. Our own Shadertoy 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.5, -0.5, 0.0, 1.0, 0.5,

    -0.5, 0.0, 1.0, 0.0, 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. var vertices = new Float32Array([ // X, Y, -1.0, 1.0,

    1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, ]) In JavaScript
  10. void mainImage( out vec4 fragColor, in vec2 fragCoord ) {

    fragColor = vec4(0.0,0.0,1.0,1.0); }
  11. void mainImage( out vec4 fragColor, in vec2 fragCoord ) {

    vec2 uv = fragCoord.xy / iResolution.xy; fragColor = vec4(uv,0.5+0.5*sin(iTime),1.0); }
  12. void mainImage( out vec4 fragColor, in vec2 fragCoord ) {

    vec2 uv = fragCoord.xy / iResolution.xy; fragColor = vec4(uv, 0.5+0.5*sin(iTime),1.0); }
  13. void mainImage( out vec4 fragColor, in vec2 fragCoord ) {

    vec2 uv = fragCoord.xy / iResolution.xy; fragColor = vec4(uv, 0.5+0.5*sin(iTime), 1.0); }
  14. https:/ /hacks.mozilla.org/2017 /01/webgl-2-lands-in-firefox/ https:/ /www.chromeexperiments.com/globe https:/ /handmadehero.org/ 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:/ /codepen.io/krzychukula/pen/qVrLww Similar to new Shadertoy in WebGL https:/ /www.shadertoy.com/new https:/ /www.packtpub.com/game-development/webgl-beginners-guide https:/ /www.udacity.com/course/interactive-3d-graphics--cs291 https:/ /sites.google.com/site/webglbook/