Higer order filters as B-splines - Stanford...

140
Tim Foley Shading Languages

Transcript of Higer order filters as B-splines - Stanford...

Page 1: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

Tim Foley

Shading Languages

Page 2: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

2

Why Shading Languages? DSLs?

ProductivityPerformance

Page 3: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

3

Why Shading Languages? DSLs?

ProductivityPerformance

Page 4: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

4

► Productivity

► Build shaders from re-usable components

► Performance

► Specialize code to data

► Exploit specialized hardware

Page 5: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

5

► Productivity

► Build shaders from re-usable components

► Based on model of problem domain

► Performance

► Specialize code to data

► Exploit specialized hardware

► Based on model of solution domain

Page 6: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

6

► Productivity

► Build shaders from re-usable components

► Based on model of problem domain

► Performance

► Specialize code to data

► Exploit specialized hardware

► Based on model of solution domain

Shader Graphs

Rates of Computation

Page 7: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

7

Building Shaders from Components

Page 8: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

8

► What kinds of components are needed?

► What form do components take?

► How do we combine components?

Page 9: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

9

RenderMan Shader Types

Page 10: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

10

Shader Components in a Modern Game

► Materials (pattern generation / BSDFs)

► Lights / Shadows

► Volumes (e.g., fog)

► Animation

► Geometry (e.g, tessellation, displacement)

► “Camera” (rendering mode)

► 2D/cubemap/stereo, color/depth output

Page 11: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

11

► What kinds of components are needed?

► What form do components take?

► How do we combine components?

Page 12: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

12

What form do shader components take?

► Function/procedure?

► Dataflow graph?

► Class?

Page 13: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

13

► Make a shader look like a procedure

► Represent with a dataflow graph IR (shader graph)

► Compose and specialize using class-like concepts

Page 14: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

14

Shade Trees[Cook 1984]

Page 15: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

15

Page 16: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

16

Shade Trees

float a = 0.5, s = 0.5;float roughness = 0.1;float intensity;color metal_color = (1,1,1);intensity = a*ambient() +

s*specular(normal,viewer,roughness);final_color = intensity * metal_color;

Key:

typeconstant

Page 17: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

17

Shade Trees

float a = 0.5, s = 0.5;float roughness = 0.1;float intensity;color metal_color = (1,1,1);intensity = a*ambient() +

s*specular(normal,viewer,roughness);final_color = intensity * metal_color;

Key:

typeconstant

final_color

a

smetal_color

ambient()specular()

viewer

roughness

normal

intensity

Page 18: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

18

Shade Trees

float a = 0.5, s = 0.5;float roughness = 0.1;float intensity;color metal_color = (1,1,1);intensity = a*ambient() +

s*specular(normal,viewer,roughness);final_color = intensity * metal_color;

Key:

typeconstant

final_color

a

smetal_color

ambient()specular()

viewer

roughness

normal

+intensity

*

*

Page 19: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

19

Point Light

Shader Graphs are Composable

DisplacementDiffuse Material

...

Li

N

L

P

P

NdotLNfinal_color

Lidelta

L

lightPos

intensity

Page 20: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

20

Point Light

Shader Graphs are Composable

DisplacementDiffuse Material

...

Li

N

L

P

P

NdotLNfinal_color

Lidelta

L

lightPos

intensity

Page 21: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

21

Shader Graphs are Composable

DisplacementDiffuse Material

Point Light

P

NdotLNfinal_color

...

Lidelta

L

lightPos

intensity

Page 22: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

22

Exploiting Specialized Hardware

Specializing Code to Data

Page 23: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

23

RenderMan Shading Language[Hanrahan and Lawson 1990]

Page 24: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

24

uniform vector L;varying vector N;

...

L = normalize(L);

...

N = normalize(N);varying float NdotL = N . L;

Key:

typerate

RenderMan Shading Language

Page 25: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

25

uniform vector L;varying vector N;

...

L = normalize(L);

...

N = normalize(N);varying float NdotL = N . L;

computed per-batch

computed per-sample

Key:

typerate

RenderMan Shading Language

Page 26: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

26

Split shader into uniform and varying parts

uniformcode

varyingcode

shader

Page 27: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

27

Create an instance of the shader class

shader

uniform

args

instance

uniformcode

varyingcode

Page 28: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

28

Create an instance of the shader class

shader

uniform

args

instance

uniformcode

varyingcode

shader parameters are instance variables

shader class has multiple methods

Page 29: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

29

Specialize as more information becomes known

shader

uniform

args

instance

geometry

boundinstance

vertex

args

elaboratedinstance

uniformcode

varyingcode

Page 30: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

30

Specialize as more information becomes known

shader

uniform

args

instance

geometry

boundinstance

vertex

args

elaboratedinstance

uniformcode

varyingcode

find parameter values using prototype chain

Page 31: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

31

Intermission:

Let’s Talk About Staging

Page 32: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

32

Staging Transformations

► Given a function of two parameters f(x,y)

► Where x might represent information known “before” y

► Compute functions f1(x) and f2(t,y)

► Such that f2(f1(x),y) = f(x,y)

► Can generalize to N stages

[Jørring and Scherlis 1986]

Page 33: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

33

Examples of f(x,y)

► Regular expression matching

► x is regular expression, y is string to match against

► RenderMan Shading Language

► x is uniform parameters, y is varying parameters

Page 34: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

34

Examples of f(x,y)

► Regular expression matching

► x is regular expression, y is string to match against

► RenderMan Shading Language

► x is uniform parameters, y is varying parameters

want to

compute

f(x, a)

f(x, b)

f(x, c)

Page 35: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

35

Goal

► Try to do “as much as possible” in f1

Page 36: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

36

A Trivial Solution

function f(x,y)...

end

function f1(x)return x

end

function f2(t, y)return f(t, y);

end

Page 37: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

37

A Trivial Solution

function f(x,y)...

end

function f1(x)return x

end

function f2(t, y)return f(t, y);

end

this isn’t “as much as possible”

Page 38: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

38

Another Trivial Solution

function f(x,y)...

end

function f1(x)return function(y)

return f(x,y)end

end

function f2(t, y)return t(y);

end

Page 39: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

39

Another Trivial Solution

function f(x,y)...

end

function f1(x)return function(y)

return f(x,y)end

end

function f2(t, y)return t(y);

end

first step returns a closure

second step applies it

Page 40: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

40

A Terra Solution

terra f(x,y)...

end

function f1(x)return terra(y)

return f(x,y)end

end

function f2(t, y)return t(y);

end

Page 41: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

41

A Terra Solution

terra f(x,y)...

end

function f1(x)return terra(y)

return f(x,y)end

end

function f2(t, y)return t(y);

end

compiler might do inlining,

constant folding, etc.

Page 42: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

42

More Idiomatic Terra

function f_staged(x,y)...

end

function f1(x)return terra(y)

return [f_staged(x,y)]end

end

function f2(t, y)return t(y);

end

Page 43: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

43

More Idiomatic Terra

function pow_staged(n,y)if n == 0 then return `1.0else return `(y * [pow_staged(n-1,y)]) end

end

function make_pow(n)return terra(y)

return [pow_staged(n,y)]end

end

function f2(t, y)return t(y);

end

Page 44: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

44

Explicit Staging Annotations

function pow_staged(n,y)if n == 0 then return `1.0else return `(y * [pow_staged(n-1,y)]) end

end

Page 45: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

45

Staged vs. Unstaged

function pow (n,y)if n == 0 then return 1.0else return (y * pow (n-1,y) ) end

end

Page 46: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

46

Staged Programmingbut not

Staged Metaprogramming

Page 47: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

47

Old Goal

► Try to do “as much as possible” in f1

Page 48: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

48

Revised Goals

► Try to do “as little as possible” in f2

► Then, try to do “as little as possible” in f1

► Then, try to do “as much as possible” when generating f1, f2

Page 49: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

49

Explicit Staging Annotations

► Quote and splice are one option

► Delay and force is another

► Rate qualifiers are yet another

► uniform and varying

► Appear to be related to “world” type in modal type theories

delay(exp) <-> function() return exp endforce(exp) <-> exp()

[“Modal Types for Mobile Code” Muphy 2008]

Page 50: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

50

Real-Time Shading Language[Proudfoot et al. 2001]

Page 51: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

51

surface shader float4 Simple( ... ){

constant float3 L_world = normalize({1, 1, 1});

primitivegroup matrix4 viewProj = view * proj;

vertex float4 P_proj = P_world * viewProj;vertex float NdotL = max(dot(N_world, L_world), 0);

fragment float4 diffuse = texture(diffuseTex, uv);fragment float4 color = diffuse * NdotL;

return color;}

Key:

keywordtypeconstantrate

Page 52: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

52

surface shader float4 Simple( ... ){

constant float3 L_world = normalize({1, 1, 1});

primitivegroup matrix4 viewProj = view * proj;

vertex float4 P_proj = P_world * viewProj;vertex float NdotL = max(dot(N_world, L_world), 0);

fragment float4 diffuse = texture(diffuseTex, uv);fragment float4 color = diffuse * NdotL;

return color;}

Key:

keywordtypeconstantrate

Page 53: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

53

surface shader float4 Simple( ... ){

constant float3 L_world = normalize({1, 1, 1});

primitivegroup matrix4 viewProj = view * proj;

vertex float4 P_proj = P_world * viewProj;vertex float NdotL = max(dot(N_world, L_world), 0);

fragment float4 diffuse = texture(diffuseTex, uv);fragment float4 color = diffuse * NdotL;

return color;}

Key:

keywordtypeconstantrate

Page 54: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

54

surface shader float4 Simple( ... ){

constant float3 L_world = normalize({1, 1, 1});

primitivegroup matrix4 viewProj = view * proj;

vertex float4 P_proj = P_world * viewProj;vertex float NdotL = max(dot(N_world, L_world), 0);

fragment float4 diffuse = texture(diffuseTex, uv);fragment float4 color = diffuse * NdotL;

return color;}

Key:

keywordtypeconstantrate

Page 55: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

55

surface shader float4 Simple( ... ){

constant float3 L_world = normalize({1, 1, 1});

primitivegroup matrix4 viewProj = view * proj;

vertex float4 P_proj = P_world * viewProj;vertex float NdotL = max(dot(N_world, L_world), 0);

fragment float4 diffuse = texture(diffuseTex, uv);fragment float4 color = diffuse * NdotL;

return color;}

Key:

keywordtypeconstantrate

Page 56: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

56

Map to Shader Graph

color

diffuse

NdotL

P_proj

viewProj

view

projN_world

L_world

diffuseTex

uv

P_world

Page 57: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

57

Color by Rates

color

diffuse

NdotL

P_proj

viewProj

view

projN_world

L_world

diffuseTex

uv

P_world

Page 58: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

58

Color by Rates

constant

color

diffuse

NdotL

P_proj

viewProj

view

projN_world

L_world

diffuseTex

uv

P_world

Page 59: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

59

Color by Rates

constant primitive group

color

diffuse

NdotL

P_proj

viewProj

view

projN_world

L_world

diffuseTex

uv

P_world

Page 60: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

60

Color by Rates

constant vertexprimitive group

color

diffuse

NdotL

P_proj

viewProj

view

projN_world

L_world

diffuseTex

uv

P_world

Page 61: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

61

Color by Rates

constant fragmentvertexprimitive group

color

diffuse

NdotL

P_proj

viewProj

view

projN_world

L_world

diffuseTex

uv

P_world

Page 62: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

62

Partition

constant fragmentvertexprimitive group

color

diffuse

NdotL

P_proj

viewProj

view

projN_world

L_world

diffuseTex

uv

P_world

Page 63: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

63

Partition

constant fragmentvertexprimitive group

color

diffuse

NdotL

P_proj

viewProj

view

projN_world

L_world

diffuseTex

uv

P_world

Page 64: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

64

Spark[Foley and Hanrahan 2011]

Page 65: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

65

Shader Components in a Modern Game

► Materials (pattern generation / BSDFs)

► Lights / Shadows

► Volumes (e.g., fog)

► Animation

► Geometry (e.g, tessellation, displacement)

► “Camera” (rendering mode)

► 2D/cubemap/stereo, color/depth output

Page 66: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

66

define shader graphs as classes

compose with inheritance

Page 67: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

67

Define Shader Graphs as Classes

abstract mixin shader class SimpleDiffuse : D3D11DrawPass{

input @Uniform float3 L_world;abstract @FineVertex float3 N_world;virtual @Fragment float4 diffuse = float4(1.0f);

@Fragment float NdotL = max(dot(L_world, N_world), 0.0f);@Fragment float4 color = diffuse * NdotL;

output @Pixel float4 target = color;}

Key:

keywordtypeconstantrate

Page 68: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

68

Define Shader Graphs as Classes

abstract mixin shader class SimpleDiffuse : D3D11DrawPass{

input @Uniform float3 L_world;abstract @FineVertex float3 N_world;virtual @Fragment float4 diffuse = float4(1.0f);

@Fragment float NdotL = max(dot(L_world, N_world), 0.0f);@Fragment float4 color = diffuse * NdotL;

output @Pixel float4 target = color;}

N_world

diffuse

NdotL

color

L_world

Page 69: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

69

Define Shader Graphs as Classes

shader class SimpleDiffuse{

...}

shader class CubicGregoryACC { ... } shader class MyTextureMapping { ... }shader class ScalarDisplacement { ... }...

Page 70: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

70

Compose With Inheritance

shader class Composedextends SimpleDiffuse

{}

Page 71: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

71

Compose With Inheritance

shader class Composedextends SimpleDiffuse,

CubicGregoryACC

{}

Page 72: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

72

Compose With Inheritance

shader class Composedextends SimpleDiffuse,

CubicGregoryACC,TextureMapping

{}

Page 73: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

73

Compose With Inheritance

shader class Composedextends SimpleDiffuse,

CubicGregoryACC,TextureMapping,ScalarDisplacement

{}

Page 74: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

74

Cg, HLSL, GLSL, etc.[Mark et al. 2003]

[Microsoft]

[OpenGL ARB]

[Sony, Apple, …]

Page 75: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

75

Assumption so far…

► Decompose program according to problem domain

► Material, lights, animation, etc.

► Compiler uses rates/staging to map to solution domain

► Specialization

► SIMD, GPU

Page 76: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

76

New assumption

► Decompose program according to solution domain

► Programmable stages of the GPU graphics pipeline

► Programmer must use ??? to align with problem domain

► Procedural abstraction?

► Object-oriented programming?

► Preprocessor?

Page 77: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

77

New assumption

► Decompose program according to solution domain

► Programmable stages of the GPU graphics pipeline

► Programmer must use ??? to align with problem domain

► Procedural abstraction?

► Object-oriented programming?

► Preprocessor?

Page 78: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

78

Looking Ahead

Page 79: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

79

“Just write shaders in C++”

Page 80: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

80

“Just write shaders in C++”

the same language as your application

Page 81: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

81

Most shader code is “just code”

Page 82: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

82

Most shader code is “just code”

Works for CPU, GPU compute, graphics

Page 83: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

83

Write “just code” part in language X

Write shader-specific parts in EDSL,implemented in language X

Page 84: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

84

Write “just code” part in Terra

Write shader-specific parts in EDSL,implemented in Terra

Page 85: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

85

Conclusion

► Productivity

► Decompose program according to problem domain

► Performance

► Use rates (staging) to guide code generation

► Generality

► Embed shaders into applications languages as EDSLs

Page 86: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

86

Thank [email protected]

Page 87: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

87

ReferencesShade Trees

[Robert L. Cook 1984]

A Language for Shading and Lighting Calculations

[Pat Hanrahan and Jim Lawson 190]

Compilers and Staging Transformations

[Ulrik Jørring and William L. Scherlis 1986]

A Real-Time Procedural Shading System for Programmable Graphics Hardware

[Kekoa Proudfoot, William R. Mark, Svetoslav Tvetkov, and Pat Hanrahan 2001]

Spark: Modular, Composable Shaders for Graphics Hardware

[Tim Foley and Pat Hanrahan 2011]

Cg: A System for Programming Graphics Hardware in a C-like Language

[William R. Mark, R. Steven Glanville, Kurt Akeley, and Mark J. Kilgard 2003]

Mobile Types for Mobile Code

[Tom Murphy VII 2008]

Page 88: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

88

Page 89: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

89

Backup

Page 90: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

90

Cg, HLSL, GLSL

Page 91: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

91

Output

Merger

The Direct3D 11 Pipeline

Fragment

ShaderRasterizer

Geometry

Shader

Domain

ShaderTessellator

Hull

Shader

Vertex

Shader

Input

Assembler

Page 92: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

92

Programmable Stages

Fragment

Shader

Geometry

Shader

Domain

Shader

Hull

Shader

Vertex

Shader

Page 93: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

93

Programmable Stages

Fragment ShaderGeometry ShaderDomain ShaderHull ShaderVertex Shader

Page 94: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

94

Problem-Domain Components

Fragment ShaderGeometry ShaderDomain ShaderHull ShaderVertex Shader

Page 95: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

95

Problem-Domain Components

Fragment ShaderGeometry ShaderDomain ShaderHull ShaderVertex Shader

SimpleDiffuse

CubicGregoryACC

ScalarDisplacement

TextureMapping

Page 96: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

96

Problem-Domain Components

Fragment ShaderGeometry ShaderDomain ShaderHull ShaderVertex Shader

SimpleDiffuse

CubicGregoryACC

ScalarDisplacement

TextureMapping

PointLightRenderToCubeMap

Page 97: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

97

Cross-Cutting Concerns

Fragment ShaderGeometry ShaderDomain ShaderHull ShaderVertex Shader

SimpleDiffuse

CubicGregoryACC

ScalarDisplacement

TextureMapping

PointLightRenderToCubeMapCubicGregoryACC

TextureMappingTextureMapping TextureMapping TextureMapping

Page 98: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

98

Coupling

Fragment ShaderGeometry ShaderDomain ShaderHull ShaderVertex Shader

SimpleDiffuse

CubicGregoryACC

ScalarDisplacement

TextureMapping

PointLightRenderToCubeMapCubicGregoryACC

TextureMappingTextureMapping TextureMapping TextureMapping

Page 99: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

99

Combinatorial Explosion

Fragment ShaderGeometry ShaderDomain ShaderHull ShaderVertex Shader

SimpleDiffuse

CubicGregoryACC

ScalarDisplacement

TextureMapping

PointLightRenderToCubeMapCubicGregoryACC

TextureMappingTextureMapping TextureMapping TextureMapping

Page 100: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

100

Terra-Integrated Shaders

Page 101: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

101

local pipeline ToyPipeline {uniform Uniforms {

mvp : mat4;}input P_model : vec3;input N_model : vec3;output C : vec4;

varying N = N_model;

vertex codegl_Position = mvp * make_vec4(P_model, 1.0);

end

fragment codeC= make_vec4(normalize(N), 1.0);

end}

Key:

keywordtypeconstantrate

Page 102: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

102

local pipeline ToyPipeline {...

}

terra init()...GL.glShaderSource(vertexShader, 1, [ToyPipeline.vertex.glsl], nil);...

end

terra render()GL.glVertexAttribPointer([ToyPipeline.P_model.__location], ...);GL.glBindBufferBase(

GL.GL_UNIFORM_BUFFER,[ToyPipeline.Uniforms.__binding],uniformBuffer);

end

Key:

keywordtypeconstantrate

Page 103: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

103

local pipeline ToyPipeline {...

}

terra init()...toyPipeline = ToyPipeline.new();toyPipeline.P_model.set( vertexData, ... );

end

terra render()toyPipeline.Uniforms.mvp.set( camera.modelViewProj );Gfx.push(toyPipeline);Gfx.draw();

end

Key:

keywordtypeconstantrate

Page 104: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

104

local pipeline Camera { ... }local pipeline SkeletalAnimation { ... }local pipeline PhongMaterial { ... }local pipeline PointLight { ... }...

terra render()for m = 0,materialCount do

var mat = &materials[m];Gfx.push(mat.pipeline);for n = 0,mat.meshCount do

Gfx.push(mat.meshes[n].pipeline);Gfx.draw();Gfx.pop();

endGfx.pop();

endend

Key:

keywordtypeconstantrate

Page 105: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

105

Staging Isn’t Always For Performance

Page 106: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

106

Shade Trees

DisplacementDiffuse Material

Point Light

P

NdotLNfinal_color

...

Lidelta

L

lightPos

intensity

Page 107: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

107

Point Light

Lidelta

L

lightPos

intensity

What if we have multiple lights?

DisplacementDiffuse Material

Point Light

P

NdotLNfinal_color

...

Lidelta

L

lightPos

intensity

Page 108: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

108

Displacement

Point Light

Lidelta

L

lightPos

intensity

Diffuse Material

What if we have multiple lights?

Point Light

P

Nfinal_color

...

Lidelta

L

lightPos

intensity

NdotL+

NdotL

Page 109: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

109

RenderMan Shading Language

Page 110: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

110

Surface and Light Shaders

Page 111: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

111

Linkage via control-flow constructs

color C = 0;illuminance( P, N, Pi/2 ) {

L = normalize(L);C += Kd * Cd * Cl * length(L ^ T);

}

Key:

keywordtypeconstant

illuminate( P, N, beamangle ) {Cl = (intensity*lightcolor)/(L . L);

}

surface shader light shader(s)

illuminate( P, N, beamangle ) {...

}

Page 112: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

112

Linkage via control-flow constructs

color C = 0;illuminance( P, N, Pi/2 ) {

L = normalize(L);C += Kd * Cd * Cl * length(L ^ T);

}

Key:

keywordtypeconstant

illuminate( P, N, beamangle ) {Cl = (intensity*lightcolor)/(L . L);

}

surface shader light shader(s)

illuminate( P, N, beamangle ) {...

}

Page 113: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

113

Linkage via control-flow constructs

color C = 0;illuminance( P, N, Pi/2 ) {

L = normalize(L);C += Kd * Cd * Cl * length(L ^ T);

}

Key:

keywordtypeconstant

illuminate( P, N, beamangle ) {Cl = (intensity*lightcolor)/(L . L);

}

surface shader light shader(s)

illuminate( P, N, beamangle ) {...

}

Page 114: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

114

Linkage via control-flow constructs

color C = 0;illuminance( P, N, Pi/2 ) {

L = normalize(L);C += Kd * Cd * Cl * length(L ^ T);

}

Key:

keywordtypeconstant

illuminate( P, N, beamangle ) {Cl = (intensity*lightcolor)/(L . L);

}

surface shader light shader(s)

illuminate( P, N, beamangle ) {...

}

Page 115: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

115

Linkage via control-flow constructs

color C = 0;illuminance( P, N, Pi/2 ) {

L = normalize(L);C += Kd * Cd * Cl * length(L ^ T);

}

Key:

keywordtypeconstant

illuminate( P, N, beamangle ) {Cl = (intensity*lightcolor)/(L . L);

}

surface shader light shader(s)

illuminate( P, N, beamangle ) {...

}

Page 116: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

116

Could re-cast as higher-order functions

color C = 0;illuminance( P, N, Pi/2 ) {

L = normalize(L);C += Kd * Cd * Cl * length(L ^ T);

}

Key:

keywordtypeconstant

illuminate( P, N, beamangle ) {Cl = (intensity*lightcolor)/(L . L);

}

surface shader light shader(s)

Page 117: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

117

Could re-cast as higher-order functions

color C = 0;illuminance( P, N, Pi/2, function(L, Cl) {

L = normalize(L);C += Kd * Cd * Cl * length(L ^ T);

});

Key:

keywordtypeconstant

illuminate( P, N, beamangle, function(L) {Cl = (intensity*lightcolor)/(L . L);

});

surface shader light shader(s)

Page 118: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

118

Could re-cast as higher-order functions

color C = 0;illuminance( P, N, Pi/2, function(L, Cl) {

L = normalize(L);C += Kd * Cd * Cl * length(L ^ T);

});

Key:

keywordtypeconstant

illuminate( P, N, beamangle, function(L) {Cl = (intensity*lightcolor)/(L . L);

});

surface shader light shader(s)

closure to apply to each illumination sample

Page 119: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

119

RTSL perlight rate

► Computations that depend on both surface and light

► System instantiates this sub-graph for each light

► Sums results when converting per-light to fragment

► In Spark, can implement @Light in user space

Page 120: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

120

Modern renderers need different decomposition

► Physically-based rendering

► Want to guarantee energy conservation, etc. of BSDFs

► Ray tracing

► Renderer wants to control sampling, integration, scheduling of rays

Page 121: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

121

Decompose surface shader into

► Pattern generation

► May be authored by artists

► Might not even need a language

► BSDF evaluation, integration, etc.

► Authored by programmers, or technical artists

► Typically only need a few (diffuse, dielectric, skin, …)

Page 122: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

122

Unity Standard Shader

► Artist only sets textures, colors

► Covers most use cases

Page 123: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

123

Unreal Engine Material Editor

► Graphical DSL

► Also used for

► Animation

► Scripting

► Audio mixing

► …

Page 124: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

124

Open Shading Language (OSL)

surface Glass(color Kd = 0.8,float ior = 1.45,output closure color bsdf = 0)

{float fr = FresnelDieletric(I, N, ior);bsdf = Kd * (fr*reflection(N) + (1-fr)*refraction(N, ior));

}

Page 125: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

125

Open Shading Language (OSL)

surface Glass(color Kd = 0.8,float ior = 1.45,output closure color bsdf = 0)

{float fr = FresnelDieletric(I, N, ior);bsdf = Kd * (fr*reflection(N) + (1-fr)*refraction(N, ior));

}

shader outputs a “radiance closure,”

to be scheduled by renderer

closures created with built-in functions,

then combined with operators like +

Page 126: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

126

Two-Stage Material Shading Pipeline

BSDF

EvaluationIntegrator

Pattern

Generation

Page 127: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

127

Automatic Rate Placement

Page 128: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

128

Rates are a way to express scheduling

Page 129: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

129

Decouple algorithm from schedule?

Automatically generate a good schedule?

Page 130: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

130

A System for Rapid, AutomaticShader Level-of-Detail

[He, Foley, Tatarchuk, Fatahalian 2015]

Page 131: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

131

Shader Simplification

1.7ms/frame 0.8ms/frame

Page 132: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

132

Observation:

The best simplifications tend to come from reducing the rate at which a term is computed

Page 133: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

133

Move fragment code to vertex shader

Move vertex code to “parameter” shader

Page 134: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

134

Project started with vertex+fragment shaders

Next step is “rate-less” pipeline shaders

Page 135: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

135

Encoding algorithm choice

Page 136: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

136

expensive = computeExpensiveBRDF(N, L, p1, p2, ...)

color = expensive

Page 137: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

137

expensive = computeExpensiveBRDF(N, L, p1, p2, ...)cheap = computeCheapBRDF(N, L, param)color = [choice(`cheap, `expensive)]

Page 138: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

138

expensive = computeExpensiveBRDF(N, L, p1, p2, ...)

color = [choice(`expensive, moveToVertex(`expensive))]

Page 139: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

139

expensive = computeExpensiveBRDF(N, L, p1, p2, ...)cheap = computeCheapBRDF(N, L, [fitParameter(`expensive)])color = [choice(`cheap, `expensive)]

Page 140: Higer order filters as B-splines - Stanford Universitycs448h.stanford.edu/shading-languages-with-backup.pdf · 2015-12-02 · 6 Productivity Build shaders from re-usable components

140

Explicit choices can makeauto-tuning tractable