opengl shading language - khronos group · opengl shading language •in a sentimental mood ... in...

36
© Copyright Khronos Group, 2011 - Page 1 OpenGL Shading Language Bill Licea-Kane Chair OpenGL Shading Language Workgroup AMD

Upload: dangtuong

Post on 21-Jul-2018

302 views

Category:

Documents


0 download

TRANSCRIPT

© Copyright Khronos Group, 2011 - Page 1

OpenGL Shading Language

Bill Licea-KaneChair OpenGL Shading Language Workgroup

AMD

© Copyright Khronos Group, 2011 - Page 2

OpenGL Shading Language

• In a Sentimental Mood

• Back to the Future

• Hints/Kinks

© Copyright Khronos Group, 2011 - Page 3

In a Sentimental Mood - 20 years ago!

• April 1991 - Iris GL

- SGI and Microsoft (and IBM)

© Copyright Khronos Group, 2011 - Page 4

In a Sentimental Mood - 20 years ago!

• April 1991 - Iris GL

- SGI and Microsoft (and IBM)

• April 1991 - ACE (Advanced Computing Environment)

- Compaq, Digital Equipment Corporation, Microsoft, MIPS, SCO

- Many other members including SGI

© Copyright Khronos Group, 2011 - Page 5

In a Sentimental Mood - 20 years ago!

• April 1991 - Iris GL

- SGI and Microsoft (and IBM)

• April 1991 - ACE (Advanced Computing Environment)

- Compaq, Digital Equipment Corporation, Microsoft, MIPS, SCO

- Many other members including SGI

- Scott McNealy, Sun Microsystems

- “Those who can, do. Those who can’t, consort.” [1]

[1] Los Angeles Times, April 13, 1991, Sun Microsystems Aims at New Market Segment, Jonathan Weber

© Copyright Khronos Group, 2011 - Page 6

In a Sentimental Mood - 20 years ago!

• April 1991 - Iris GL

- SGI and Microsoft (and IBM)

• April 1991 - ACE (Advanced Computing Environment)

- Compaq, Digital Equipment Corporation, Microsoft, MIPS, SCO

- Many other members including SGI

- Scott McNealy, Sun Microsystems

- “Those who can, do. Those who can’t, consort.” [1]

- Scott Cook, Intuit

- “There has never been a technology product fostered by a coalition that

has been successful.” [2]

[1] Los Angeles Times, April 13, 1991, Sun Microsystems Aims at New Market Segment, Jonathan Weber

[2] Los Angeles Times, April 10, 1991, Consortium Seeks to Develop Faster Desktop Computer, Jonathan Weber

© Copyright Khronos Group, 2011 - Page 7

20 years ago!

• September 1991

- SILICON GRAPHICS OPENS IRIS GRAPHICS LIBRARY FOR GENERAL LICENSING

- Compaq, Digital Equipment Corporation, Intel and Microsoft [1]

• June 30, 1992

- The OpenGL Graphics System: A Specification, Version 1.0

- “This document describes the OpenGL graphics system: what it is, how it

acts, and what is required to implement it.” [2]

- OpenGL does not provide a programming language.

...

Programmability would conflict with keeping the API close to the hardware

and thus with the goal of maximum performance.” [3]

[1] SGI press release, 1991-09-17, www.sgistuff.net/hardware/graphics/documents/iris-gl-announce.txt

[2] The OpenGL Graphics System: A Specification, Version 1.0 June 30, 1992, Segal, Akeley

[3] The Design of the OpenGL Graphics Interface, 1994, Segal, Akeley

© Copyright Khronos Group, 2011 - Page 8

First question about Shading….

[email protected] (William C. Archibald) writes:

|>

|> A couple of quick queries:

|>

|> 1)Quite a few modern rendering techniques and renderers support

|> shader function calls at arbitrary points across a surface

|> being rendered. Most marble textures, for example, are

|> rendered this way with Perlin-ish noise functions.... Is there _any_ way

|> to do this kind of thing in OpenGL?

Not with the current API. One could extend OpenGL in this manner…

comp.graphics.opengl, 1993-10-13, Kurt Akeley

© Copyright Khronos Group, 2011 - Page 9

Brief Extension Digression

• “One disadvantage of using procedure calls on such a fine grain is that it

may result in poor performance if procedure calls are costly….

”If it turns out that fine-grained procedure calls are too expensive, then it

may be necessary to add a few popular block formats to the OpenGL API

or to provide a mechanism for defining such formats.” [1]

• OpenGL 1.1

- InterleavedArrays (meh, “popular block formats” – just a helper function)

- Vertex Arrays (successful)

[1] The Design of the OpenGL Graphics Interface, 1994, Segal, Akeley

© Copyright Khronos Group, 2011 - Page 10

Mechanism, Not Policy

© Copyright Khronos Group, 2011 - Page 11

Digression – meanwhile, at the movies

• “Shading is an important part of computer imagery, but shaders have

been based on fixed models to which all surfaces must conform. As

computer imagery becomes more sophisticated, surfaces have more

complex shading characteristics and thus require a less rigid shading

model.” [1]

[1] Shade Trees, SIGGRAPH 1984, Cook

© Copyright Khronos Group, 2011 - Page 12

Digression – meanwhile, at the movies

• “Shading is an important part of computer imagery, but shaders have

been based on fixed models to which all surfaces must conform. As

computer imagery becomes more sophisticated, surfaces have more

complex shading characteristics and thus require a less rigid shading

model.” [1]

• “We introduce the concept of a Pixel Stream Editor. This forms the basis

of an interactive synthesizer for designing highly realistic Computer

Generated Imagery.” [2]

[1] Shade Trees, SIGGRAPH 1984, Cook

[2] An Image Synthesizer, SIGGRAPH 1985, Perlin

© Copyright Khronos Group, 2011 - Page 13

Digression – meanwhile, at the movies

• “Shading is an important part of computer imagery, but shaders have

been based on fixed models to which all surfaces must conform. As

computer imagery becomes more sophisticated, surfaces have more

complex shading characteristics and thus require a less rigid shading

model.” [1]

• “We introduce the concept of a Pixel Stream Editor. This forms the basis

of an interactive synthesizer for designing highly realistic Computer

Generated Imagery.” [2]

• “A shading language provides a means to extend the shading and lighting

formulae used by a rendering system.” [3]

[1] Shade Trees, SIGGRAPH 1984, Cook

[2] An Image Synthesizer, SIGGRAPH 1985, Perlin

[3] A Language for Shading and Lighting Calculations, SIGGRAPH 1990, Hanrahan, Lawson

© Copyright Khronos Group, 2011 - Page 14

In a Sentimental Mood – Bottom Line

• “Off-line” rendering evolved from “fixed function” to shaders

• OpenGL evolving as well

© Copyright Khronos Group, 2011 - Page 15

Back to the Future

© Copyright Khronos Group, 2011 - Page 16

OpenGL 1.x

Pri

mit

ive

Asse

mb

ly

Ve

rte

x

Ra

ste

riza

tio

n

Fra

gm

en

t

Pe

r-Fra

gm

en

tO

pe

rati

on

s

Texture

State

© Copyright Khronos Group, 2011 - Page 17

OpenGL 2.x

Pri

mit

ive

Asse

mb

ly

Ve

rte

x

Ra

ste

riza

tio

n

Fra

gm

en

t

Pe

r-Fra

gm

en

tO

pe

rati

on

s

Texture

StateUniforms

© Copyright Khronos Group, 2011 - Page 18

OpenGL 3.x

Pri

mit

ive

Asse

mb

ly

Ve

rte

x

Ge

om

etr

y

Pri

mit

ive

Asse

mb

ly

Fe

ed

ba

ck

an

d/o

rR

aste

riza

tio

n

Fra

gm

en

t

Pe

r-Fra

gm

en

tO

pe

rati

on

s

TextureTexture Buffers

StateUniform Buffers

© Copyright Khronos Group, 2011 - Page 19

OpenGL 4.x

Pri

mit

ive

Asse

mb

ly

Ve

rte

x

Ge

om

etr

y

Pri

mit

ive

Asse

mb

ly

Fe

ed

ba

ck

an

d/o

rR

aste

riza

tio

n

Fra

gm

en

t

Pe

r-Fra

gm

en

tO

pe

rati

on

s

TextureTexture Buffers

StateUniform Buffers

Pri

mit

ive

Asse

mb

ly

Te

sse

lla

tio

nC

on

tro

l

Pri

mit

ive

Asse

mb

ly

Te

sse

lla

tio

nE

va

lua

tio

n

Te

sse

lla

tio

n

© Copyright Khronos Group, 2011 - Page 20

Hints/Kinks

© Copyright Khronos Group, 2011 - Page 21

“Dusty Deck” shaders

• Yes, they work

• But…

© Copyright Khronos Group, 2011 - Page 22

“Dusty Deck” shaders

• Yes, they work

• But…

varying float Texcoord;

sampler1D idMap;

//...

vec2 texel = texture1D( idMap, Texcoord ).xy;

texel = floor( texel * 255.0 + 0.125/256.0 );

int i = int( dot( texel, vec2( 1.0, 256.0 ) ) );

© Copyright Khronos Group, 2011 - Page 23

“Dusty Deck” shaders

• Yes, they work

• But…

varying float Texcoord;

sampler1D idMap;

//...

vec2 texel = texture1D( idMap, Texcoord ).xy;

texel = floor( texel * 255.0 + 0.125/256.0 );

int i = int( dot( texel, vec2( 1.0, 256.0 ) ) );

© Copyright Khronos Group, 2011 - Page 24

“Dusty Deck” shaders

• Yes, they work

• But…

in float Texcoord;

sampler1D idMap;

//...

vec2 texel = texture1D( idMap, Texcoord ).xy;

texel = floor( texel * 255.0 + 0.125/256.0 );

int i = int( dot( texel, vec2( 1.0, 256.0 ) ) );

© Copyright Khronos Group, 2011 - Page 25

“Dusty Deck” shaders

• Yes, they work

• But…

in float Texcoord;

sampler1D idMap;

//...

vec2 texel = texture1D( idMap, Texcoord ).xy;

texel = floor( texel * 255.0 + 0.125/256.0 );

int i = int( dot( texel, vec2( 1.0, 256.0 ) ) );

© Copyright Khronos Group, 2011 - Page 26

“Dusty Deck” shaders

• Yes, they work

• But…

in float Texcoord;

isampler2D idMap;

//...

int i = texture1D( idMap, Texcoord ).x;

© Copyright Khronos Group, 2011 - Page 27

“Dusty Deck” shaders

• Yes, they work

• But…

in float Texcoord;

isampler2D idMap;

//...

int i = texture1D( idMap, Texcoord ).x;

© Copyright Khronos Group, 2011 - Page 28

“Dusty Deck” shaders

• Yes, they work

• But, simple example

in float Texcoord;

isampler2D idMap;

//...

int i = texture( idMap, Texcoord ).x;

© Copyright Khronos Group, 2011 - Page 29

WIN/FAIL?

© Copyright Khronos Group, 2011 - Page 30

WIN/FAIL?

• goto?

© Copyright Khronos Group, 2011 - Page 31

WIN/FAIL

• goto – WIN!

© Copyright Khronos Group, 2011 - Page 32

WIN/FAIL

• goto – WIN!

• noise?

© Copyright Khronos Group, 2011 - Page 33

WIN/FAIL

• goto – WIN!

• noise – FAIL!

© Copyright Khronos Group, 2011 - Page 34

WIN/FAIL

• goto – WIN!

• noise – FAIL!

• Shading language function man pages?

© Copyright Khronos Group, 2011 - Page 35

WIN/FAIL

• goto – WIN!

• noise – FAIL!

• Shading language function man pages – WIN!

- www.opengl.org/sdk/docs/manglsl/

- (Thank you to Graham Sellers)

© Copyright Khronos Group, 2011 - Page 36

Questions?