Paper Summaries Any takers? Procedural Shading Announcement - - PDF document

paper summaries
SMART_READER_LITE
LIVE PREVIEW

Paper Summaries Any takers? Procedural Shading Announcement - - PDF document

Paper Summaries Any takers? Procedural Shading Announcement Logistics Checkpoint 2 SIGGRAPH animation screenings Due last Thursday!!! Every Monday Checkpoint 3 12:30pm -- 2pm Due Today 07-1315 Checkpoint 4


slide-1
SLIDE 1

1

Procedural Shading

Paper Summaries

 Any takers?

Announcement

 SIGGRAPH animation screenings

 Every Monday  12:30pm -- 2pm  07-1315  Sponsored by RIT digital studio program

(College Imaging Arts and Sciences) and Rochester Chapter of SIGGRAPH.

Logistics

 Checkpoint 2

 Due last Thursday!!!

 Checkpoint 3

 Due Today

 Checkpoint 4

 To be given today

 Project Proposals

 All should have received e-mail feedback.  Please address issues (if any)

Projects

 Approx 22 projects  Listing of projects now on Web  Presentation schedule

 Presentations (15 min max)  Last 3 classes (week 10 + finals week)  Sign up  Email me with 1st , 2nd , 3rd choices  First come first served.

The plan for today

 Procedural Shading  A short history

 Cook’s Shade Trees  Ken Perlin: PSE and Noise

 Shader Languages  Example  Checkpoint 4

slide-2
SLIDE 2

2 Remember this?

 Bi-directional Reflectance Function

) , , , (

r r i i r

f BRDF

  • =

At a given point, gives relative reflected illumination in any direction with respect to incoming illumination coming from any direction

In the beginning…

 There was Phong…  …and Phong was good

 As long as everything in your world was

plastic!

 Physics purists said…

 Not close enough to reality  Cook / Torrance

In the beginning…

 Practical 3Ders said

 Too hard to use  Strauss model

 …too isotropic

 Ward model…

 Not complex enough…  Blah..blah…blah

So then came…

 Texture Mapping

 Developed in 1974 by Ed Catmull, currently

president of Pixar

 Goal: Make Phong shading less plastic looking  And texture maps were good…

But…

 They were static  They were fixed in resolution  Too much aliasing.  Took up too much space  Blah…blah…blah…

What if…

 We could roll your own illumination

models with…

 Flexibility  Resolution independence  Compactness  Parameterizable

 Enter the Procedural Shader

slide-3
SLIDE 3

3 Procedural Shading

Advantages

 Compact  Resolution

Independent

 Unlimited Extent  Parameterizable ->

class of textures Blah…Blah…Blah…

 Programming=>

debugging

 Unpredictable results  Time vs. space

tradeoff (can take a long time)

Shading (and/or texture) determined by a function

 First procedural shading system  Allowed use of different shading model for each

surface as well as light sources and atmospheric considerations, i.e., light and atmosphere trees

 Traditional shading techniques could be combined  Handled complexity and simplicity in same image

 Color and transparency  Textures  Reflection mapping  Displacement mapping  Solid texturing

Shade Trees [Cook84]

 Shading calculated by combining basic functional

  • perations using appearance parameters

 Operations are organized in a tree (directed acyclic

graph).

 Nodes – Operations

 Uses zero or more appearance parameters as input  Produces one or more appearance parameters as output

 Children – operands – basic geometric info: normals,

location, etc.

 Result of shade tree evaluation is a color  Evaluating equivalent to parsing tree (post order -

compiler design)

Shade Trees [Cook84]

Procedural Shading – Shade Trees

 Basic operations include

 Vector operations (normalize, dot product / cross

product)

 Arithmetic operations  Interpolation / “mix”  stochastic functions  Variables (points in eye or world)  Expandable dynamically

 Basis for Renderman Shading Language

Procedural Shading – Shade Trees

[Cook84]

Procedural Shading – Shade Trees

 Shade trees - Phong model specular diffuse ambient

V) R ( N) S ( ) (

∑ ∑

  • +
  • +

=

i k i i s i i i d a a

e

L k L k L k V L

+ ambient diffuse specular ka kd S N ks R V ke

slide-4
SLIDE 4

4

Procedural Shading – Shade Trees

 Shade Trees - example…copper [Cook84]

Procedural Shading – Shade Trees

Shade trees - example code: for “metal” shade tree

[Cook84]

Surface Command – designates shade tree for object (overrides default values)

Built into language

Procedural Shading – Shade Trees

 Shade trees – “mix” uses one of inputs to interpolate

between the other two

[Cook84]

Procedural Shading – Shade Trees

 Are parameterizable  Have access to “important” attributes of the

point in question

 Hooks into the 3d world  Normals, viewer vector, light vectors

 Can be functionally combined

 Output of one shade tree can be input to another

by attaching as a branch

 Nothing more that a parse tree for a function  Functional Programming (LISP)

Procedural Shading – Shade Trees

 Effectively using shade trees is more of an

art than a science.

[Cook84]  Attempt to create a language around functional

shade generation

 C like language  Included control structures

 Originally designed to work on pixels of an image

as a postprocessor

 Input image -> PSE (filter) -> output image  Input image has variable list: surface identifiers, point –

location, normal, etc.

Perlin’s Pixel Stream Editor (PSE)

slide-5
SLIDE 5

5

Procedural Shading – Perlin’s PSE

 Example if surface == 1 color = [1 0 0] * max(0.1, dot(normal,[1 0 0]) else color = [0 0 0.1]

Produces diffusely shaded red object lit from positive x direction on a dark blue background.

color normal Variable related to input image; others point, normal

Procedural Shading – Perlin’s PSE

 Any space function can be thought of as

representing a solid material

 If evaluated at visible surface points, get sculpture!

 Shape and texture independent  Small code!

 PSE programs are evaluated in 3D space to

produce such solid textures

 Hooks into the 3d world  Knowledge of x,y,z coordinates  Knowledge of important “vectors” at surface

Procedural Shading – Perlin’s PSE

 But the biggest contribution from the PSE

was

 THE NOISE For, tom orrow, he knew, all the W ho girls and boys W ould wake bright and early. They'd rush for their toys! And then! Oh, the noise! Oh, the noise! Oh, the Noise! Noise! Noise! Noise! That's one thing he hated! The NOISE! NOISE! NOISE! NOISE! How the Grinch Stole Christm as

Procedural Shading – Perlin Noise

 Observation:

 Most things in the world have some sort of

random or stochastic component to them

 A procedural shading system requires the

use of randomness (“noise”) for realism.

 Need more than simple random number

generator.

Procedural Shading – Perlin Noise

 What is noise

 Random signal with rich frequency distribution  Types of noise:

 White – uniform frequency  Pink – filtered  Gaussian – based on Gaussian distribution

 None appropriate for shader use

Procedural Shading – Perlin Noise

 Perlin on noise:

 “Noise appears random but it is not. If it were really

random, then you’d get a different result each time you call it. Instead it is “pseudo-random” – it gives the appearance of randomness”

 “Noise is a mapping from Rn→ R – you input an n-

dimensional point with real coordinates and it gives you a real value. Currently, the most common uses is for n=1, 2, and 3. The first is used for animation, the second for cheap texture hacks, and the third for less-cheap texture hacks.”

slide-6
SLIDE 6

6

Procedural Shading-Noise Properties

 Repeatable  Known range [-1, 1]  Band limited / scalable  Doesn’t exhibit obvious periodicities  Statistically invariant under translation  Statistically invariant under rotation

Procedural Shading-Perlin Noise

 Controllable random number generator  Emphasized importance of stochastic

functions in texture design

 Very efficient in time and space  Implemented as a basic operation in the

MMX chipset and other graphics hardware

 Won Ken an Academy Award

Procedural Shading-Perlin Noise

 “Controlled” Noise function

 White noise = noise at all frequencies  Control the frequency of the noise used  e.g. noise (2x) will contain twice as

much frequency (detail) as noise(x)

Procedural Shading-Perlin Noise

 Noise frequency and detail

Procedural Shading-Perlin Noise

 Perlin Noise

 Returns a scalar value between -1 and 1  takes a 3d vector as an argument  float noise3 (float [3] vec)

Procedural Shading-Perlin Noise

 3D lattice (3D array) with 4 pseudorandom real

numbers per point in the array

 for each point (x0,y0,z0) we assign a set of 4

pseudorandom numbers (a, b, c, d).

 Compute d’ = d - (ax0+by0+cz0)  noise (x,y,z)

 if (x, y, z) is on the lattice, noise (x,y,z) = d  if (x,y,z) is NOT on the lattice, the values of (a,b,c,d)

are interpolated from the (a,b,c,d) values of neighboring lattice points. Then noise(x,y,z) = ax + bx +cz +d’ using the interpolated (a,b,c,d)

slide-7
SLIDE 7

7

Procedural Shading-Perlin Noise

 Perlin noise - Lattice

Procedural Shading-Perlin Noise

 Perlin has further optimized using look up tables  Complete “C” code (approx 150 lines) on Web

at:

 http://mrl.nyu.edu/~perlin/doc/oscar.html#noise

 Perlin has since revised the basic noise

algorithm in order for efficiency, functionality, and ease of hardware implementation.

 Perlin has since applied same paradigm to:

 Solid Modeling  Animation / Gesturing

Procedural Shading – Perlin Noise

Paul Burke, 2000

Increasing harmonics of 1-D Perlin noise Sum of 1st 8 harmonics

Paul Burke, 2000

Procedural Shading – Perlin Noise

Sum

Procedural Shading-Perlin Noise

 Example 1 – Spotted Donut -No detail outside

certain size range

Color = white * noise (point)

[Perlin85]

Vector

Procedural Shading-Perlin Noise

 Example 2 – Bozo’s Donut

Color = Colorful(noise (k*point))

[Perlin85]

Constant multiplier

slide-8
SLIDE 8

8

Procedural Shading-Perlin Noise

 Dnoise – Vector valued differential of

noise signal, i.e., gradiant/derivative of noise function

 Dnoise (x,y,z) = (dNoise/dx, dNoise/dy,

dNoise/dz)

 Good for modifying normal vector

(bump mapping)

Procedural Shading-Perlin Noise

 Dnoise example – Bumpy Donut

Normal += Dnoise (point)

[Perlin85]

Creating Wrinkles

 Adding successive noise at different but

regular frequencies

 1/f, self-similar quality (Fractal-like…more

  • n fractals later)

= =

=

N-1 i i i i x

x a ) b Noise( ) NOISE(

Creating Wrinkles

 Perlin example: Wrinkled Donut [Perlin85]

Procedural Shading - Perlin

 Turbulence used to model – stocastic components

 Water  Clouds  Bubbles  Falling leaves  Swaying trees  Flocks of birds  Rippling muscles

Procedural Shading - Perlin

 Perlin - turbulence example Function marble(point) x = point[1] + turbulence (point) return marble_color(sin x) [Perlin85] Perturbs the layer

slide-9
SLIDE 9

9 Procedural Shading-Perlin Noise

 Perlin Noise Demo Applet

http://mrl.nyu.edu/~perlin/noise/

 Perlin Noise Applied to Animation

http://mrl.nyu.edu/~perlin/facedemo/

Procedural Shading - Perlin

 Summary

 Compact, functional shading specifications  Efficient “controllable” noise function  Noise adds to complexity and realism  Building good procedural textures is more

  • f an art than a science.

Procedural Shading - Noise

 For a discussion on other noise

functions see:

 Ebert, et al, Texture and Modeling: A

Procedural Approach, Chapter 2

 A nice discussion on Perlin Turbulence:

 http://astronomy.swin.edu.au/~pbourke/texture/p

erlin/

Shading Languages

 Renderman Shading Language

 Grew out of shade trees  Goals

 Abstract shading language based on ray optics.

Independent of any specific algorithm or implementation

 Interface between rendering program and

shading model

 High level language that is easy to use.

Shading Language

 RenderMan shaders

 Renderman provides a complete

programmable model of light transport.

 More next time

 Surface reflectance shaders

 Compute the light reflected from a surface in a

given direction, i.e., programmable BRDFs .

Runtime architecture

 Renderman consists of three parts:

 Functional scene description mechanism (API

for C)

 RenderMan is an Interface Specification!  State Model Description – Maintains a current

graphics state that can be placed onto a stack.

 Geometry is drawn by utilizing the current graphics

state.

 File format - RenderMan Interface Bytestream

(RIB)

 Shading Language and Compiler.

slide-10
SLIDE 10

10

Runtime architecture

Rendering application

RenderMan

Graphics state Shader 1 Shader 2 Shader 3

slc

Shader / render link

Shader “object” file Shader “object” file Shader “object” file

Shading Languages

 Many commercial renderers (e.g. Ray

Dream 3D / Lightwave) now come with a shading / plugin API.

 Allows shaders to be written using a

native programming language (like C or C++).

 Using these APIs effectively is more of

an art than a science.

Real Time Shaders

 Programmable shading capability is now built in to

current graphics hardware (GPU)

 Same flavor as Renderman shaders.

 However, model is far less comprehensive.

 Examples

 Cg – nVidia  RenderMonkey – ATI  HLSL – Microsoft only  OpenGL Shader language – hardware independent

 Using real time shaders effectively is more of an art than

a science.

Real Time Shaders

 In case you haven’t guessed:

 Creating effective shaders with any

Shading system is more of an art than a science.

 You can spend an entire 10 weeks on

procedural shading alone…

 And in fact, if you want to  Spring 2007 – Procedural Shading special

topic course

Break Shading

 So far we have considered:

 BRDFs  Shading & Illumination Models  Texture Maps

 Procedural Shading

 Surface characteristics are defined by a function

 Shading model – simulates behavior of surface material

w.r.t. diffuse and specular reflection

 Pattern generation - texture pattern and sets surface

property values

slide-11
SLIDE 11

11 Procedural Textures

 Textures generated on the fly.

 All the advantages of texture mapping

without the blah..blah..blah..

 Not static  Can be defined at infinite resolution  Parameterizable

Procedural Textures – basic brick

Procedural Textures – better brick

Shader takes diffuse using perturbed normal

Procedural Textures

 How they work

Texture defined in terms of (u,v) No need to determine “texel” Can be built in

Example: Building a Brick Shader

 Brick shader will be defined as a

procedural texture that is mapped onto a surface

 Texture coordinates s, t

Building a brick shader

BRICKWIDTH BRICKHEIGHT MORTARTHICKNESS

1 1

slide-12
SLIDE 12

12 Building a brick shader

#define BRICKWIDTH 0.25 #define BRICKHEIGHT 0.08 #define MORTARTHICKNESS 0.01 #define BMHEIGHT (BRICKHEIGHT + MORTARTHICKNESS) #define BMWIDTH (BRICKWIDTH + MORTARTHICKNESS)

Building a brick shader

surface brick ( uniform Color Cbrick = color (0.5, 0.15, 0.1); uniform Color Cmortar = color (0.5, 0.5, 0.5) ) { // What row is the point in question on float row = t / BMHEIGHT; // If even, offset length by a half if ( row % 2 == 0) s += (BMWIDTH/2);

Building a brick shader

// wrap texture coords to see where on given brick // you are s = s % BRICKWIDTH; t = t % BRICKHEIGHT; // Set the color based on where you are Color Ct = Cbrick; if (s < MORTARTHICKNESS || t < MORTARTTHICKNESS) Ct = Cmortar // Return correct color Cs = Ct; }

Building a better brick shader

 Let’s use noise to discolor individual

bricks

Building a better brick shader

// Set the color based on where you are // Let the brick color change based on noise float noiseChange = 0.1; float row = s / BMWIDTH; Color Ct = Cbrick + (noise (row,col) * noiseChange); if (s < MORTARTHICKNESS || t < MORTARTTHICKNESS) Ct = Cmortar // Return correct color Cs = Ct; }

Building an even better brick shader

 Other possible additions

 Bump mapping to have normal dip in

mortar and rise on side of brick

 Add noise to individual points on each brick  Add graininess

slide-13
SLIDE 13

13

Building an even better brick shader

Olano, 1998, http://www.cs.unc.edu/~olano/papers/dissertation/ plain Grooved mortar grain Different colored bricks Different colors within bricks

Procedural Textures

 Using Genetic Algorithms

Sims 1992 Musgrave 1993

Genetic Textures

 Karl Sims [Sims91] applied genetic

algorithms to images

 Images coded by a symbolic function of

(x,y), location of pixels in an image

 LISP like expression  Genetic Programming

Genetic algorithms…what they are

 Class of adaptive algorithms used to solve

search and optimization problems

 Populations of solutions are evolved with

most fit solutions mated and mutated to form next generation of solutions.

3 Steps in using Genetic algorithms

  Coding - Solution to a given problem must

be encoded by a data structure (e.g. lists, arrays, trees)

  Reproduction operators must be defined, on

the solution data structure for

crossover (offspring of 2 parent solutions)

mutation (modification of a single solution)

  Fitness criteria must be defined that judges

the “goodness” of any individual solution

Genetic algorithm - reproduction

 Reproduction -- example

Before After Before After Crossover Mutation Before After Before After Crossover Mutation

slide-14
SLIDE 14

14

Genetic algorithm - basic principles

 Convergence -- if

defined correctly, successive generations will produce better solutions so that fitness converges to the

  • ptimum.

Initialize population Select individuals for crossover (based on fitness function Crossover Mutation Insert new offspring into population Are stopping criteria satisfied? Finish

Genetic Textures

 Coding

 Individual is a parse tree

Warped color noise * X 2 Y .1 2 Warped-cnoise (* X 2) Y .1 2

Genetic Textures

 Function Set:

 Arithmetic (+, -, *, /)  Math functions (sin, cos, min, max, abs, etc)  LISP Control statement (If, then, else)  Color functions (hsv-to-rgb)  Vector functions (dot, cross, etc)  Noise functions (bw-noise, color-noise)  Image processing (blur, warp, grad, filter)

Genetic Textures

[Sims91]

Genetic Textures

 Mutation

Before crossover After crossover

crossover mutation

Before mutation After mutation

Genetic Texture

 Other Mutations

 Add random value to scalar value  Increase/decrease length of a vector

slide-15
SLIDE 15

15 Genetic Texture

 Fitness

 Determined by the user  At each “generation”, the user is presented

with a collection of generated textures

 The user chooses the one he/she likes the

best.

 The chosen textures are mutated to create

textures in next generation.

Genetic Texture

[Sims91]

Genetic Texture

(sin (+ (- (grad-direction (blur (if (hsv- to-rgb (warped-color-noise #(0.57 0.73 0.92) (/ 1.85 (warped-color-noise x y 0.02 3.08)) 0.11 2.4)) #(0.54 0.73 0.59) #(1.06 0.82 0.06)) 3.1) 1.46 5.9) (hsv- to-rgb (warped-color-noise y (/ 4.5 (warped-color-noise y (/ x y) 2.4 2.4)) 0.02 2.4))) x))

[Sims91]

Summary

 Procedural shaders

 Use a function or procedure to define

illumination / shading.

 Categories

 Procedural shading  Procedural texture

 More of an art than a science

Question…

 Can you add procedural shading to your

ray tracer?

 YES YOU CAN!  In fact you will!