Shaders Jeremy Nicholson COMP30019: Graphics and Interaction 05 - - PowerPoint PPT Presentation

shaders
SMART_READER_LITE
LIVE PREVIEW

Shaders Jeremy Nicholson COMP30019: Graphics and Interaction 05 - - PowerPoint PPT Presentation

Shaders Jeremy Nicholson COMP30019: Graphics and Interaction 05 Sep 2011 Jeremy Nicholson Shaders Rendering Pipeline (Foley Figure 14.41) Jeremy Nicholson Shaders Rendering Pipeline (OpenGL Red Book, section 1) Jeremy Nicholson Shaders


slide-1
SLIDE 1

Shaders

Jeremy Nicholson COMP30019: Graphics and Interaction 05 Sep 2011

Jeremy Nicholson Shaders

slide-2
SLIDE 2

Rendering Pipeline

(Foley Figure 14.41)

Jeremy Nicholson Shaders

slide-3
SLIDE 3

Rendering Pipeline

(OpenGL Red Book, section 1)

Jeremy Nicholson Shaders

slide-4
SLIDE 4

Rendering Pipeline

(Angel Figure 1.38)

Jeremy Nicholson Shaders

slide-5
SLIDE 5

Rendering Pipeline

Vertex processing: Vertex position: co-ordinate transformations (model) projection transformations Vertex colour: Illumination model

Jeremy Nicholson Shaders

slide-6
SLIDE 6

Rendering Pipeline

Clipping and primitive assembly: Clipping: Clipping volume (based on viewing frustum) projection transformations Primitive assembly Vertices → line segments, polygons, etc.

Jeremy Nicholson Shaders

slide-7
SLIDE 7

Rendering Pipeline

Rasterisation: Scan conversion of polygons Line segment → fragments Fragments: ”potential pixels” Position and colour to be entered into frame buffer

Jeremy Nicholson Shaders

slide-8
SLIDE 8

Rendering Pipeline

Fragment processing: Hidden surface removal Some fragments may not be visible because they are behind

  • ther fragments

Texturing, blending, etc.

Jeremy Nicholson Shaders

slide-9
SLIDE 9

Shaders

Loosely speaking, programming on the GPU itself Typically high-powered processor, lots of RAM Parallel processing plays an important part not massively parallel typically only a couple of simple mathematical operations e.g. matrix multiplication of a single transformation matrix to many vertices Don’t typically do any “shading”

Jeremy Nicholson Shaders

slide-10
SLIDE 10

Types of Shaders

Vertex Shader: Input: set of primitives (vertices) Output: set of primitives Operate on vertex values and associated data Normals Colour Material properties Texture?

Jeremy Nicholson Shaders

slide-11
SLIDE 11

Types of Shaders

Geometry Shader: Input: set of primitives Output: set of primitives Add/remove vertices or other primitives Triangulation (why?) Hidden surface removal? Shadow volumes etc.

Jeremy Nicholson Shaders

slide-12
SLIDE 12

Types of Shaders

Fragment Shader: Input: set of fragments Output: set of fragments Apply operations to viewport pixels (primarily colour) Texture mapping Bump mapping Potentially lighting model Rasterisation/anti-aliasing?

Jeremy Nicholson Shaders

slide-13
SLIDE 13

Types of Shaders

Pixel Shader: Input: set of fragments Output: set of pixel values Actually rendering images to the display Depth testing/occlusion/blending Hardware conversion: dithering, γ-correction Double buffering

Jeremy Nicholson Shaders

slide-14
SLIDE 14

Shaders and the Rendering Pipeline

Vertex processing: Vertex Shader Clipping and primitive assembly: Geometry Shader Rasterisation: Fragment Shader Fragment processing: Pixel Shader (Loosely)

Jeremy Nicholson Shaders

slide-15
SLIDE 15

Shaders and the Rendering Pipeline

Vertex Shader: ??? Geometry Shader: ??? Fragment Shader: ??? Pixel Shader: ???

Jeremy Nicholson Shaders

slide-16
SLIDE 16

Shaders and the Rendering Pipeline

Vertex Shader: Modelling transform, Lighting, Viewing transform Geometry Shader: Trivial accept/reject, some Lighting Fragment Shader: Rasterisation Pixel Shader: Display (Typically, but Clipping and Map to 3D viewport are ”missing”)

Jeremy Nicholson Shaders

slide-17
SLIDE 17

Shaders in OpenGL

Contrast with ”legacy” OpenGL Gives you the power (and hassle) of specifying your own modelling/viewing operations, illumination model, shading model Only Vertex/Geometry/Fragment Shaders implemented in OpenGL And geometry only recently! Manipulated using a pared-down programming language...

Jeremy Nicholson Shaders

slide-18
SLIDE 18

GLSL: The OpenGL shading language

”GL slang” Reference: Orange book Not many in-builts Some mathematical functions (e.g. Trigonometric) I/O partly limited: specific streams for vertex position, colour, etc.

Jeremy Nicholson Shaders

slide-19
SLIDE 19

GLSL: The OpenGL shading language

Common key words: in - input (from OpenGL or earlier in the Shader pipeline)

  • ut - output (to next Shader in the pipeline, or occasionally

OpenGL) uniform - ”constant” variable: same across many inputs (iterationsof Shader) — allowing preprocessing and optimisation varying - actual variable: for intermediate calculation etc.

Jeremy Nicholson Shaders

slide-20
SLIDE 20

Examples

Trivial Example (Angel 2.2)

Jeremy Nicholson Shaders

slide-21
SLIDE 21

Examples

Illumination Model (in Vertex Shader) (Angel 5.3)

Jeremy Nicholson Shaders

slide-22
SLIDE 22

Examples

Illumination Model (in Fragment Shader) (Angel 5.6)

Jeremy Nicholson Shaders