Vous êtes sur la page 1sur 22

http://adrien.

io
OpenGL Tutorials
Codex

Buffer Object
Memory managed by OpenGL
GL_ARRAY_BUFFER,
GL_ELEMENT_ARRAY_BUFFER, ..
glGenBuffers, glBindBuffer, glBufferData

Vertex Array Object


Specify where data is located and layout
GL_ARRAY_BUFFER,
GL_ELEMENT_ARRAY_BUFFER, ..
glGenVertexArrays, glBindVertexArray,
glVertexAttribPointer, glEnableVertexAttribArray

Framebuffer Object
Specify how draw buffers are stored
glGenFramebuffers glBindFramebuffer
Framebuffer Object 0 is created automatically

Attach Renderbuffer Objects : glFramebufferTexture2D


Attach Textures : glFramebufferTexture2D
Attach to Draw Buffers GL_COLOR_ATTACHMENTX
Special Attachments Depth and Stencil

Clear buffers before use : glClear

Programmable stages

Vertex
Tessellation Control
Tessellation Evaluation
Geometry
Fragment

Compute

Vertex Shading
For each vertex issued by a drawing command a vertex
shader is called
gl_VertexId gl_InstanceID
Output vertex positions in screen space
Mandatory

Tessellation Shading
Two stages : Control and Evaluation
Patches instead of points/lines/triangles
Optional stage

Geometry Shading
Process and emit individual geometry primitives
Optional Stage
gl_PrimitiveIDIn

Fragment Shading
Compute fragment color and depth
Texture sampling
Mandatory Stage
gl_FragCoord

Texture Units, Samplers, and Textures


Only one texture can be bound for each Texture Unit
glActiveTexture selects the current Texture Unit
glBindTexture binds the texture to the current Texture
Unit
A sampler uniform is associated to a Texture Unit
Shaders read textures through a sampler.

B
A

AB = B-A
AB
AB =

||AB||

BAC = acos(ABAC)
C

ABAC = cos(BAC)

Blinn-Phong Shading
float ndotl = clamp(dot(n, l), 0.0, 1.0);
vec3 h = normalize(l-v);
float ndoth = clamp(dot(n, h), 0.0,
1.0);
vec3 specularColor = specularColor *
pow(ndoth, specularPower);
vec3 color = specularColor +
diffuseColor * ndotl;

Point Light
ep

lp
n
v

l
p

l = lp-p

Directional Light
ld
ep
n
v

l
p

l = -ld

Spot Light
lp
ep

langle
n

ld

l
p

l = lp-p

-lld > cos(langle)

Geometry Spaces

World Space : Useful for transformations and lighting

Object Space : useful for object transformations

Camera Space : Useful for lighting

Light Space : Useful for shadow mapping

Forward Shading
Lights[]

Transforms

Rasterization

Uniforms
Material

Transforms

Material

Deferred Shading
G-Buffer
Rasterization

Normals

Material

Depth

Shadow Mapping
lp

ep

langle
dblocker

dlight
p2

p1

shadow = dblocker < dlight + bias

Post-FX pipeline

glFramebufferTexture2D T0
glClear
Render

T0

Post-FX pipeline
T0
glFramebufferTexture2D T1
glClear
glBindTexture T0
Render

T0

T1

Post-FX pipeline
T0

T1
glFramebufferTexture2D T0
glClear
glBindTexture T1
Render

T0

T1

T0