Final Exam effects Ground rules Textures II Teams of 2/3 GRAD - - PDF document

final exam effects
SMART_READER_LITE
LIVE PREVIEW

Final Exam effects Ground rules Textures II Teams of 2/3 GRAD - - PDF document

Final Exam effects Ground rules Textures II Teams of 2/3 GRAD students: responsible for research Team: responsible for implementation and documentation Procedural Textures Implement in GLSL and RenderMan (for teams of 3)


slide-1
SLIDE 1

1

Textures II

Procedural Textures

Final Exam effects

 Ground rules

 Teams of 2/3  GRAD students: responsible for research  Team: responsible for implementation and

documentation

 Implement in GLSL and RenderMan (for teams of

3)

 Implement in GLSL or RenderMan (for teams of 2)

Final exam effects

 Deliverables:

 Research (Grads only)  Shader code  Documentation

 Describe shader params  Explain chosen implementation.  List constraints.  Give results.

Final exam effect

 Presentation:

 Final exam period

 Monday, May 19th  12:30 - 2:30pm  ICL5

 15 minutes per presentation

 …and now the effects

Final exam effect

Bright Lights, Big City (Neon)

(Martini not included) Research: Tim Peterson Andrew Fabiny Dan Wisnewski

Final exam effect

Strawberry Fields Forever

(Beatles not included) Research: Abhishek Moothedath John Smith Steve Sarnelle

slide-2
SLIDE 2

2

Final Exam Effect

 Made from the Best Stuff on

Earth

(Silly Factioids in the cap not included)

 Research: Mike Allyger  Adam Linderman

Final exam effect

 Where’s the Ocean?

(JAWS not included)

 Research: Abhijit Bhelande  Jeff Herdman

Final Exam Effect

 CD / DVD

(music not included)

 Research: Jacob Hays  Andrew Ford  Matt Penepent

Final exam effect

 Monet’s Pallette

(Giverny not included)

 Research: Rodrigo Urra  Carl Loutin

Final exam effect

 Having My Picture

Taken

(Job at Kodak not included)

 Research: Rohan

Mehalwal

 Peter Kaszubinski

 Old Black and White or

Glorious Technicolor

Final exam effect

 Questions?

slide-3
SLIDE 3

3

About Lab 3

 RenderMan only  DevIL is on it’s way to getting installed.  Should understand texture space in

GLSL.

Plan

 Textures II

 Procedural Textures

 1st half: tools and functions  2nd half: Revisiting the brick.

It’s all about the mapping

x y z geometry u v image screen

Texture pipeline

Akenine-Moller / Haines

It’s all about the mapping

 In shaders

 [s, t] --> [ x y z ]  s, t range from 0 - 1  Shaders provide [ x y z ] --> [ s t ]  How you set up textures will determine how

  • ut or range values are mapped

 GLSL: set up in OpenGL  RenderMan: argument to txmake

It’s all about the mapping

 In order to provide this inverse

mapping, texture coordinates must be defined.

 GLSL: set up in OpenGL

 Explicitly (e.g. glTexCoord())  Automatically (e.g. gluQuadricObjs)

 Renderman: set of rules

 Based on primitive

slide-4
SLIDE 4

4

RenderMan rules

 Bicubic patches

 [ s t ] --> [ u v ]

 Quadrics

 [ s t ] --> 2D parameterization of quadric

RenderMan rules

 Polygon

 [s t] --> [ x y ] in object space  Causes problems for polygons

perpendicular to x,y plane.

Consider…

surface mytex () { Ci = color "rgb" (s, t, 0); Oi = 1; } In RIB file: AttributeBegin

Surface "mytext" TransformBegin Polygon "P" [-5 -5 5 5 -5 5 5 -5 -5 -5 -5 -5 ] AttributeEnd

What you get

S > 1 |S| <1 S <0 T=-5

Looking down at the floor

How to fix

 Redefine polygon in object space then

transform

AttributeBegin

Surface "mytext" TransformBegin Rotate 90 1 0 0 Translate 0 2.5 0 Polygon "P" [-5 -5 0 5 -5 0 5 5 0 -5 5 0] TransformEnd AttributeEnd

Results

  • 5 < S <5
  • 5 < T <5
slide-5
SLIDE 5

5

To get texture between 0 - 1

 Redefine polygon in object space then

transform…you can scale too

AttributeBegin Surface "mytext" TransformBegin Rotate 90 1 0 0 Translate -5 0 1.25 Scale 10 10 10 Polygon "P" [ 0 0 0 1 0 0 1 1 0 0 1 0 ] TransformEnd AttributeEnd

To get texture between 0 - 1 Procedural Textures

 s and t will be calculated regardless if a

texture is read / used

 Can use this to construct textures on

the fly.

 Only calculate for sample points when

needed.

Proceduralism vs. Stored Textures

 Strored textures

 Need to be captured  Has limited resolution  One of a kind  Takes lots of space

 Procedural textures

 Need to write code  Need to debug code  Need to run code (may take time)  aliasing

Texture modulation

 Repeating patterns

 FP mod function -- returns floating point

remainder of x / y

 mod (x, y) -- RenderMan  mod (x, y) -- GLSL (float, vec234 versions)

Simple checkerboard

smod = mod (s * freq, 1); tmod = mod (t * freq, 1); if (smod < 0.5) if (tmod < 0.5) color = green else color = yellow; else if (tmod < 0.5) color = yellow else color = green

0 ≥ s ≥ 1 0 ≥ t ≥ 1

smod < 0.5 tmod < 0.5 smod > 0.5 tmod < 0.5 smod > 0.5 tmod < 0.5 smod > 0.5 tmod > 0.5

slide-6
SLIDE 6

6

Simple checkerboard -- freq

Freq = 1 Freq = 3 Freq = 4 Freq = 2

Layering

 Placing one texture on top of another.  Allows you to build textures up a bit at a

time

 Mixing layers:

 mix (C0, C1, f)

 F between 1 and 0  Returns (1-f)C0 + f*C1

Steps, Clamps, and Conditionals

 step (a, x)

 Returns (x >= a)

 Quick and dirty if statement

 C = mix (c0, c1, step (0.5, u))

Steps, Clamps, and Conditionals

 clamp (x, mn, mx)

 Clamps a value between 2 extremes

Steps, Clamps, and Conditionals

 Smoothstep (a, b, x)

 Smooth stepping function

 0 if x < a  1 if x > b  Spline if between 0 and 1

Periodic functions

 To form repeating patterns

 sin, cos  Greater frequency -- more detail

slide-7
SLIDE 7

7

Periodic functions

 mod can be used to construct periodic

functions.

 If f(x) is a function defined on [0, p] then  f (mod(x,p)) will give a periodic version of f

Spectral Synthesis 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

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.”

Noise

 Repeatable  Known range [0, 1]

 Note original Perlin noise returns [-1 1]

 Band limited / scalable  Doesn’t exhibit obvious periodicities  Statistically invariant under translation  Statistically invariant under rotation

Noise

 Noise parameters

 noise (float) -- 1D noise  noise (float, float) -- 2D noise  noise (point) -- 3D noise  noise (point, float) -- 4D noise

 In Cg

 noise[1234] (x) -- x can be (float, vec2,

vec3, vec4).

slide-8
SLIDE 8

8

Noise in RenderMan

 Noise variants:

 noise -- variant of Perlin noise

 Tends to hover about [0.3, 0.7]

 snoise - signed noise

 Range of [-1 1]….#defined.

 cellnoise -- for pseudorandom discrete values

 Does NOT hover around 0.5

 pnoise -- perioidic noise

 Repeats about some period.

Noise in GLSL

 Using noise in shaders

 Use the built in noise function (if your card

supports it!)

 Write your own noise function in GLSL  Calculate noise in OpenGL code and pass

to shader as a 3D texture.

Noise in GLSL

 Why not just use the noise function?

 Your hardware may not support it!  You may not like the noise your hardware

gives you

 Accessing a texture map may be faster

than calling noise.

Noise in GLSL

 Then we should always use a texture,

right? Well….

 Consumes texture memory  Uses a texture unit  Sampling issues  Obviously repeated  You have to set it up in OpenGL

Noise as a sin substitute

 Noise resembles a sin wave but with

“random” bumps:

Spectral Synthesis with noise

slide-9
SLIDE 9

9

Paul Burke, 2000

Procedural Shading – Perlin Noise

Sum

fBm / Turbulence

 fBm -- fractional Brownian motion.  1/f noise

 Sum of noise functions  Contribution of each is proportional to the

inverse of the frequency

float value = 0; for (f = MINFREQ; f < MAXFREQ; f *=2) value += snoise (P * f) / f; return value;.

fBm / Turbulence

 Turbulence

 Like fBm but absolute value of noise is

summed

 Both are useful for “natural” effects float value = 0; for (f = MINFREQ; f < MAXFREQ; f *=2) value += abs (snoise (P * f)) / f; return value;.

fBm / Turbulence

fBm turbulence

Questions?

 Break

Example: Building a Brick Shader

 Brick shader will be defined as a

procedural texture that is mapped onto a surface

 Build texture in stages

 Coordinate system

 s, t texture coords from renderer  ss, tt coordinate system of the brick

slide-10
SLIDE 10

10

Brick parameters -- 1st pass

 Brickcolor -- color of the brick  Mortarcolor -- color of the mortar  Brickwidth -- width of the brick (in s

coords)

 Brickheight -- height of the brick (in t

coords)

 Mortarthickness (in st space)

Brick coordinate system

BRICKWIDTH BRICKHEIGHT MORTARTHICKNESS

1 1

Step 1 -- Brick coloring

 Conversion from st to ss/tt

ss = s / (bWidth + mThickness); tt = t / (bHeight + mThickness);

 Shift every other row half a brick

if (mod (tt*0.5, 1) > 0.5) ss += 0.5;

Step 1 -- Brick coloring

 Find out which brick we are in and

subtract that off to get a point on that brick

sbrick = floor (ss); tbrick = floor(tt); ss -= sbrick; tt -= tbrick

Step 1 -- Brick coloring

 At this point we are in [0 1] of brick

space

 Are we in brick or mortar? if ((ss < mThickness) || (tt < mThickness)) Ci = mColor; else Ci = bColor;

Step 2 -- Groove the mortar

 Use simple bump mapping to achieve a

“grooved” look.

 Bump mapping should be peformed in object

space

 Must use a illumination model that depends on N  Good use of smoothstep

float stbump = …calculate bump point Psh = transform (“shader”, P); normal Nsh = ntransform (“shader”, N); Nsh = calculatenormal (Psh + Nsh * stbump); Normal Nf = ntransform (“shader”, “current”, Nsh); Nf = normalize (Nf); // use in Phong

slide-11
SLIDE 11

11

Step 3 - Add grain to bricks

 Bump map the brick surface using noise.

 Noise should be applied in object space if based

  • n point

 Bump mapping should be performed in object

space.

point Psh = transform (“shader”, P); float amp = 0.8; // amount of bump float freq = 20.0; // detail of grain float stbump = amp * noise (freq * Psh);

GLSL - Tangent Space

 Build a local coordinate system around

the normal at a point

GLSL does not have a calculatenormal() function

GLSL - Tangent Space

 Converting to tangent space

S - vector in tangent space

T - tangent vector

N - normal vector

B - binormal vector

O - vector in object space

Sx Sy Sz

  • =

Tx Ty Tz Bx By Bz Nx Ny Nz

  • Ox

Oy Oz

  • CONSTRUCT T, N, and B in Vertex Shader

Matrix Multiplication

 Sx = T • O  Sy = B • O  Sz = N • O

Sx Sy Sz

  • =

Tx Ty Tz Bx By Bz Nx Ny Nz

  • Ox

Oy Oz

  • Sx = TxOx + TyOy + TzOz

DO This in Fragment Shader using iterpolated T, B, N

Bump Mapping

 For a modified Phong

 Vertex shader takes as args:

 Normal (built-in)  Tangent (user defined)  Bi-normal (can be calculated)

 Will pass to fragment:

 Light vector  Eye position  BOTH IN Tangent Space

Bump Mapping

 For a modified Phong:

 Fragment Shader will:

 Modify normal  Do lighting calculation.  Set fragment color.

slide-12
SLIDE 12

12

Step 4 - variable brick colors

 Vary the brick color…based on brick

 Use noise again.  Noise based on brick number

color Ct = bColor; color Cmod = color (1.0, 0.0, 0.0); Ct -= (Cmod * cellnoise(sbrick, tbrick));

Step 5 -- Variable color within individual bricks

 Keep the noise coming.  This time modify color based on noise.  Noise keyed off of s/t or point.

Ct += noise (freq * Psh);

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

My attempt at RIT brick Questions For next time

 Thursday: Texture II Lab

 Procedural Textures