Demystifying shaders

10
Demystifying Shaders Bruno Opsenica @BruOps

Transcript of Demystifying shaders

Page 1: Demystifying shaders

Demystifying Shaders

Bruno Opsenica @BruOps

Page 2: Demystifying shaders

- WebGL Shaders are written in GLSL-ES- High level shading language- C like syntax- Strongly typed!

- We pass them in as strings to our application

Open GL Shading Language (GLSL)

Page 3: Demystifying shaders

Basics - Vertices

Page 4: Demystifying shaders

The simplest quadThese coordinates are in

Model SpaceThey are defined to the

model’s own origin

system

Our vertex shader must

transform these

coordinates to clip space

Page 5: Demystifying shaders

Our Goal:

Page 6: Demystifying shaders

Projection Transform

Page 7: Demystifying shaders

Fragment / Pixel Shader

Page 8: Demystifying shaders

- Vertex Shader acts on each vertex to transform our

points into clip space:- model space -> view space -> clip space- must set vec4 gl_Position;

- Fragment Shader sets the color of each pixel/fragment- must set vec4 gl_FragColor;

- We use uniforms, attributes and varyings to calculate

these values

Summary

Page 9: Demystifying shaders

- Shader School -

https://github.com/stackgl/shader-school- www.thebookofshaders.com by Patricio Gonzalez Vivo- www.clicktorelease.com/blog/ by Jaume Sanchez- www.shadertoy.com

- Figures taken from:- Real Time Rendering by Adenine-Moller et al- Wikipedia- http://www.codinglabs.net/- OpenGL Documentation

Resources and Further Reading

Page 10: Demystifying shaders

Functional Imperative

functionalimperative.com(647) 405-8994@func_i