SlideShare a Scribd company logo
@g33konaut
Creative experiments
With WebGL
@g33konaut
Our plan for today...
1. What is WebGL?
@g33konaut
Our plan for today...
1. What is WebGL?
2. Shaders ftw
@g33konaut
Our plan for today...
1. What is WebGL?
2. Shaders ftw
3. Let’s write some shaders!
@g33konaut
What is WebGL?
@g33konaut
Why do we need a GPU?
CPU GPU
@g33konaut
Why do we need a GPU?
CPU GPU
for(var i=0; i<10; i++) {
if(data[i] == MAGIC_VALUE) {
data[i+offset] = data[i] / data[i+1]
}
}
@g33konaut
Why do we need a GPU?
CPU GPU
@g33konaut
This is what WebGL can do...
@g33konaut
What do we need for our WebGL laboratory?
1. A <canvas>
@g33konaut
What do we need for our WebGL laboratory?
1. A <canvas>
2. A WebGL context
canvas.getContext(‘webgl’);
@g33konaut
What do we need for our WebGL laboratory?
1. A <canvas>
2. A WebGL context
canvas.getContext(‘webgl’);
3. Vertices, Shaders, ...
@g33konaut
@g33konaut
This is how WebGL works
Vertices GLBuffers
Vertex
Shader
Fragment
Shader
Pixels
GLSL code
@g33konaut
Vertices? Buffers? Shaders? GLSL? WAT?!
@g33konaut
Breathe. It will be fine. I promise.
@g33konaut
Breathe. It will be fine. I promise.
@g33konaut
Breathe. It will be fine. I promise.
@g33konaut
Okay, let’s talk about vertices
@g33konaut
Vertices are points in 3D space.
@g33konaut
We can also use 2D coordinates.
(1,1)
(-1,1)
(-1,-1) (1,-1)
@g33konaut
(1,1)
(-1,1)
(-1,-1) (1,-1)
We put them into a TypedArray
const vertices = new Float32Array([
-1.0, 1.0,
1.0, 1.0,
1.0, -1.0,
-1.0, -1.0
]);
@g33konaut
A buffer moves the data to the GPU memory
// create an empty buffer
const vBuf = gl.createBuffer();
@g33konaut
A buffer moves the data to the GPU memory
// create an empty buffer
const vBuf = gl.createBuffer();
// select vBuf as the current ARRAY_BUFFER
gl.bindBuffer(gl.ARRAY_BUFFER, vBuf);
@g33konaut
A buffer moves the data to the GPU memory
// create an empty buffer
const vBuf = gl.createBuffer();
// select vBuf as the current ARRAY_BUFFER
gl.bindBuffer(gl.ARRAY_BUFFER, vBuf);
// copy the TypedArray into the buffer
gl.bufferData(gl.ARRAY_BUFFER, vrtx, gl.STATIC_DRAW);
@g33konaut
So what happens here?
A.x
A.y
B.x
B.y
...
...
...
GL
Buffer
(Vertices)
@g33konaut
So what happens here?
A.x
A.y
B.x
B.y
...
...
...
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
@g33konaut
So what happens here?
A.x
A.y
B.x
B.y
...
...
...
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Fragment
shader
Fragment
shader
Fragment
shader
Fragment
shader
@g33konaut
So what happens here?
A.x
A.y
B.x
B.y
...
...
...
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Vertex
shader
Fragment
shader
Fragment
shader
Fragment
shader
Fragment
shader
@g33konaut
Let’s make some shaders!
@g33konaut
A shader is a function, run on the GPU
function (x, y, p1, p2, ...) {
}
@g33konaut
A vertex shader returns coordinates to draw at
function (x, y, p1, p2, ...) {
// do stuff
return [x, y];
}
@g33konaut
A fragment shader returns the colour to draw
function (x, y, p1, p2, ...) {
// do stuff
return [red, green, blue, alpha];
}
@g33konaut
The 4 types of inputs for shaders
● const A constant
@g33konaut
The 4 types of inputs for shaders
● const A constant
● uniform A “global” variable
@g33konaut
The 4 types of inputs for shaders
● const A constant
● uniform A “global” variable
● attribute A per-vertex variable
@g33konaut
The 4 types of inputs for shaders
● const A constant
● uniform A “global” variable
● attribute A per-vertex variable
● varying Interpolated variable
(vertex write, fragment read)
@g33konaut
Enough talking, time to code!
avgp.github.io/shaderpad
@g33konaut
Go and play with shaders!

More Related Content

PDF
WebGL - 3D in your Browser
PDF
WebGL and three.js
KEY
Leaving Flatland: getting started with WebGL
PDF
Making Games in WebGL - Aro Wierzbowski & Tomasz Szepczyński
PDF
A Novice's Guide to WebGL
PDF
Leaving Flatland: Getting Started with WebGL- SXSW 2012
PPT
Rendering: Vertices, Indices, UVs and Shaders
PDF
Open gl
WebGL - 3D in your Browser
WebGL and three.js
Leaving Flatland: getting started with WebGL
Making Games in WebGL - Aro Wierzbowski & Tomasz Szepczyński
A Novice's Guide to WebGL
Leaving Flatland: Getting Started with WebGL- SXSW 2012
Rendering: Vertices, Indices, UVs and Shaders
Open gl

Similar to "Graphical fun With WebGL shaders", Martin Splitt (20)

PPTX
OpenGL - Bringing the 3D World into the Android
PDF
Intro to OpenGL ES 2.0
PDF
lectureAll-OpenGL-complete-Guide-Tutorial.pdf
PDF
Computer Graphics - Lecture 01 - 3D Programming I
PPTX
HTML5DevConf 2013 (October): WebGL is a game changer!
PPTX
Penn graphics
PDF
Installing Games Sucks, Learn WebGL
PDF
From Experimentation to Production: The Future of WebGL
PPT
CS 354 Programmable Shading
PDF
Webgl para JavaScripters
PDF
iOS Visual F/X Using GLSL
PDF
Introduction to Computing on GPU
PDF
PPTX
OpenGL Introduction
PPT
Building Models
PPTX
WebGL - It's GO Time
PPT
CS 354 Blending, Compositing, Anti-aliasing
PPT
Praseed Pai
PPTX
Cg shaders with Unity3D
OpenGL - Bringing the 3D World into the Android
Intro to OpenGL ES 2.0
lectureAll-OpenGL-complete-Guide-Tutorial.pdf
Computer Graphics - Lecture 01 - 3D Programming I
HTML5DevConf 2013 (October): WebGL is a game changer!
Penn graphics
Installing Games Sucks, Learn WebGL
From Experimentation to Production: The Future of WebGL
CS 354 Programmable Shading
Webgl para JavaScripters
iOS Visual F/X Using GLSL
Introduction to Computing on GPU
OpenGL Introduction
Building Models
WebGL - It's GO Time
CS 354 Blending, Compositing, Anti-aliasing
Praseed Pai
Cg shaders with Unity3D
Ad

More from Fwdays (20)

PDF
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
PDF
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
PPTX
"Computer Use Agents: From SFT to Classic RL", Maksym Shamrai
PPTX
"Як ми переписали Сільпо на Angular", Євген Русаков
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
PDF
"Validation and Observability of AI Agents", Oleksandr Denisyuk
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
PPTX
"Co-Authoring with a Machine: What I Learned from Writing a Book on Generativ...
PPTX
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
PDF
"AI is already here. What will happen to your team (and your role) tomorrow?"...
PPTX
"Is it worth investing in AI in 2025?", Alexander Sharko
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
PDF
"Database isolation: how we deal with hundreds of direct connections to the d...
PDF
"Scaling in space and time with Temporal", Andriy Lupa .pdf
PPTX
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
PPTX
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
PPTX
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
"Computer Use Agents: From SFT to Classic RL", Maksym Shamrai
"Як ми переписали Сільпо на Angular", Євген Русаков
"AI Transformation: Directions and Challenges", Pavlo Shaternik
"Validation and Observability of AI Agents", Oleksandr Denisyuk
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
"Co-Authoring with a Machine: What I Learned from Writing a Book on Generativ...
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
"AI is already here. What will happen to your team (and your role) tomorrow?"...
"Is it worth investing in AI in 2025?", Alexander Sharko
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Database isolation: how we deal with hundreds of direct connections to the d...
"Scaling in space and time with Temporal", Andriy Lupa .pdf
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Approach and Philosophy of On baking technology
PDF
cuic standard and advanced reporting.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Empathic Computing: Creating Shared Understanding
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
cuic standard and advanced reporting.pdf
A Presentation on Artificial Intelligence
Reach Out and Touch Someone: Haptics and Empathic Computing
KodekX | Application Modernization Development
NewMind AI Weekly Chronicles - August'25 Week I
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Empathic Computing: Creating Shared Understanding
Building Integrated photovoltaic BIPV_UPV.pdf
Spectral efficient network and resource selection model in 5G networks
Digital-Transformation-Roadmap-for-Companies.pptx
Big Data Technologies - Introduction.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

"Graphical fun With WebGL shaders", Martin Splitt