Final exam effects Final exam effects Lighting Neon lights - - PDF document

final exam effects final exam effects
SMART_READER_LITE
LIVE PREVIEW

Final exam effects Final exam effects Lighting Neon lights - - PDF document

Announcement Lots of CS Scholarship opportunities Textures I Deadline: April 15, 2008. Final exam effects Final exam effects Lighting Neon lights Textures / refelction Strawberry Snapple bottle Water surface CD


slide-1
SLIDE 1

1

Textures I

Announcement

 Lots of CS Scholarship opportunities

 Deadline: April 15, 2008.

Final exam effects Final exam effects

 Lighting

 Neon lights

 Textures / refelction

 Strawberry  Snapple bottle  Water surface  CD surface

 Volumetric

 PET scan visualization

 Postprocessing

 “Classic” film look  Impressionistic painting

Final exam effects

 Grads

 Research and implementation plan

 Teams

 Implementation

 RenderMan  GLSL

 Documentations

Final exam effects

 Please register your preference

 Mycourses quiz.

slide-2
SLIDE 2

2

Notes for Lab 1

 GLSL coordinate spaces

Model transformation

View

Projection

  • bject

world eye clip

gl_ModelViewMatrix gl_ModelViewProjection

Notes for Lab 1

 In Renderman, premultiply opacity…I.e.

Os = Oi; Cs = Ci * Os;

Plan

 Textures

 This week

 Texture mapping (from files)  Bump Mapping  Environment Mapping  Simple Toon Shading

 Next week

 Procedural shading 

Define surface characteristics of an object using an image

Basic concept: associate value at some coordinates in texture with pixel at some coordinates in geometry

Coordinate spaces used in texture mapping:

Texture space (u, v)

Object space (xo,yo,zo)

Screen space (x, y) parameterization texture space (u,v)

  • bject space (xo,yo, zo)

screen space (x,y) projection

Texture Mapping

x y z geometry u v image

Texture Mapping

screen

Texture Mapping

slide-3
SLIDE 3

3

Textures in shaders

 Textures are just data  Texture coordinates available to the

shader

 Global variable / semantic  Actual mapping determined by underlying

scene model.

Texture pipeline

Akenine-Moller / Haines

Texture pipeline example

Akenine-Moller / Haines

Textures in shaders

 Tasks:

 Make texture data available to rendering  Grab texture data for a given point

 Use texture coord from shading point  Indexed by some other means

 Apply texture data as appropriate

 Color, normal, opacity, whatever.

Texture mapping in RenderMan

 Texture coordinates range from 0-1 in

texture space

 Values of texture coords corresponding

to P given in global parameters s and t.

 Filtered texture lookup

 Free antialiasing.

Textures in RenderMan

 Access texture values from file using

the texture() function

 texture (filename, q, r) -- Return

value(s) at texture coords (q,r)

 texture (filename) -- Return value(s)

at standard texture coords (s, t).

slide-4
SLIDE 4

4

Textures in RenderMan

 Can access color or floating point values

from file

 f = float texture (“foo.tex”);  c = color texture (“bar.tex”);

 Can access specific channels from file

 f = texture (“foo.tex” [1]);

Textures in RenderMan

 texture() function provides manual

control over filtering

 Blur  Filter width  Type of filter  Fill data (for missing channels)  See Section 8.1.4 in text.

Texture format

 prman has a proprietary format for textures.

 txmake [args] infile outfile

 Converts images into this format  Args:

 -mode [black clamp periodic]  -smode, -tmode  -short, -float  -resize up-

Textures in RenderMan

surface paintedplastic ( float Ka = 1, Kd = .5, Ks = .5, roughness = .1; color speccolor = 1; string texname = “”;) { color Ct = Cs; if (texname != “”) Ct *= color texture (texname); normal Nf = faceforward (normalize(N), I); vector V = -normalize (I); Ci = Ct * (Ka*ambient() + Kd*diffuse(Nf)) + speccolor * Ks * specular (Nf, V, roughness); Oi = Os; Ci *= Oi; }

Textures in RenderMan

 Questions?

Textures in GLSL

 Texture access in GLSL is almost as

easy

 EXCEPT…  Texture state must be set up in OpenGL

program!

 Places texture into texture memory for use

by shaders

slide-5
SLIDE 5

5

Setting up OpenGL Texture state

 Select a texture unit and make it active

(glActiveTexture())

 Create a tecture object and bind to the

active texture (glBindTexture()).

 Set texture parameters (wrapping,

filtering etc) (glTexParam()).

 Define the texture (glTexImage())

Setting up the OpenGL texture state

 Notes:

 No need to enable texture (glEnable()) or

set the up the texture function (glTexEnv())

 Texture data must be read in by aux

functions.

Sample setup code

 Initializing the texture

Sample code setup

 Using the texture

glActiveTexture (GL_TEXTURE0) glBindTexture (GL_TEXTURE_2D, myTexName);

Sample code setup

 Passing texture to a shader

texLoc = glGetUniformLocation (myProgram, “paramname); glUniform1i (texLoc, 0);

On the shader side

 Textures are grabbed from texture

memory by use of samplers

 sampler1D - 1D texture  sampler2D - 2D texture  sampler3D - 3D texture  samplerCube - cube map texture  samplerShadow1D/2D - shadow maps

slide-6
SLIDE 6

6

Shader texture functions

 texture1D  texture2D  texture3D  textureCube  shadow1D  shadow2D  See section 5.7 for complete list

Texture access in GLSL

 Access to texture values: use

 textureNNNN[proj/Lod] () functions  shadowNNNN[proj/Lod] () functions  NNNN =  1D / 2D / 3D - using texture coords (0-1)  Cube - for environment mapping  [proj] - projective texture map  Proj = As if projected by slide projector/Useful in shadowing  Lod = Use of textures in vertex shaders

Textures in GLSL

 Projective texture mapping

Simple example

varying float Intensity; Uniform sampler2D myTexture; void main() { vec3 light = vec3 (texture2D (myTexture, glTexCoord [0].st; glFragColor = vec4 (light * Intensity, 1.0); }

Textures in GLSL

 Textures are data

 Can be used as values  Individual components can be accessed via

swizzling / masking

 Questions / Break

What you can do with texture maps

 Color  Bump Mapping  Environment Mapping  Toon Shading.

slide-7
SLIDE 7

7 Texture Mapping- Bump Mapping

  • Adds roughness to surfaces
  • Quick way to add detail to

an object

  • Polygon remains physically

flat, but appears bumpy

Jim Blinn

Texture Mapping- Bump Mapping

 Perturbing surface normal  Texture map represents displacements from the

normal

 Use perturbed normal in illumination model

Texture mapping – Bump Mapping

Issues with Bump Mapping

 How much to perturb  Common coordinate system

 Using eye or even object may be

cumbersome.

 Normal map defined on object

Tangent Space

 Build a local coordinate system around

the normal at a point

Bump mapping in RenderMan

 Performed using the displacement shader:

 Modifies global variables P and N

P+= bumpheight * normalize(N); N = calculatenormal (P);

 Recall that displacement shaders are

executed before surface shaders.

 bumpheight can be read from a texture file,

  • r generated procedurally, or both…
slide-8
SLIDE 8

8 Bump vs displacement mapping

 Displacement mapping

 Moves actual point

P+= bumpheight * normalize(N); N = calculatenormal (P);

 Bump mapping

 Just changes normal

N = calculatenormal (P + amp*normalize(N));

Bump mapping in RenderMan

 Bump mapping calculations should be

done in “shader” space

The coordinate system in which the shading calculations are being performed. This is normally the "camera" or "world" coordinate system. "current" The coordinate system in which the shader was defined. This is the "object" coordinate system when the shader is defined. "shader" Description Coordinate System

Bump Mapping in Renderman

vector Nshad = vtransform (“shader”, N); point Pshad = transform (“shader”, P); Pshad += amp * normalize (Nshad); P = transform (“shader”, “current”, Pshad); N = calculatenormal (P);

 Works just as well (see Section 8.2.3 in text

for derivation)

vector Nn = normalize (N); P += Nn * (amp / length (vtransform(“shader”, Nn));

Bump Mapping in GLSL

 No convenient displacement shader

 Just vertex and fragment shaders  Must be done in fragment shader

Phong as a Vertex Shader - diffuse

Lighthouse3d.com

Phong as a Vertex Shader - specular

slide-9
SLIDE 9

9

Issues with Bump Mapping

 How much to perturb  Common coordinate system

 Using eye or even object may be

cumbersome.

 Normal map defined on object

Tangent Space

 Build a local coordinate system around

the normal at a point

GLSL does not have a calculatenormal() function

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

  • 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

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-10
SLIDE 10

10

Bump Mapping

 Questions?

Toon Shading

 Mimic the look of cartoons

 Intentionally 2-dimensional  Use of a set solid colors (rather than a

gradiant)

 Hard edges

Toon Shading

[Lake, et. al. 2000]

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

Note: Ln are radiance terms, include both light and material info

Toon Shading

 Much like diffuse shading but…

 Rather than using N • L to determine

shade color

 Use N • L as index to a 1D texture map.

Toon Shading

 To avoid aliasing

 Use large map with gradient between color

transitions.

slide-11
SLIDE 11

11

Toon Shading

 toon shading in print:

 [Lake, et. al. 2000]  X-Toon [Barla, et. al. 2004]

Environment mapping

 Create an image, representing the reflection of

the world onto an object

 Use surrounding sphere or box, image is texture

map indexed by direction of reflection ray

 Poor-man’s ray tracing - cheaper

Environment mapping

 Not associated with a particular object but

with an imaginary surface surrounding the scene

 Specular Reflection – indexed by reflected ray  Diffuse - by surface normal  Transparency – refracted ray direction

Environment Mapping Environment Mapping

spherical Cube map

Texture Mapping

 Environment mapping

slide-12
SLIDE 12

12

Environment Mapping

 Both RenderMan and GLSL have basic

support for cube mapping

Environment Map

 Map provides data based on direction

 Reflection, refract, etc.

Environment Mapping

 Major assumption

 Environment is infinitely distant from object  This is a hack…but a good hack

 Getting away with stuff

 Every object should have its own environment

map

 Envrionment maps should change as objects are

moved

 Environment maps don’t self reflect. Best on

convex objects

 Works best on curved rather than flat surfaces.

Environment Mapping in RenderMan

 Use environment function: environment (string filename, vector R, …)  Like texture()

 Can return color or float  Can access separate channels using []  Automatic filtering

Environment mapping in RenderMan

 Typical usage: normal Nf = normalize (faceforward (N,I)); vector R = normalize (reflect(I,N)); color Crefl = color environment (mapname, R);

Environment Mapping in RenderMan

 Creating a cube map:

From RIB file: MakeCubeFaceEnvironment Using txmake txmake -envcube Parameters front, back, top, bottom, left, right cubemapfile

slide-13
SLIDE 13

13

Environment Mapping in GLSL

 Calculates color based on reflection found

in CUBE map

vec4 c = texureCube (environmentMap, R);

 Where

samplerCUBE environmentMap; R is reflection direction

Environment Mapping in Cg

 Cube Map must be constructed in

OpenGL.

 See pp. 430-431 in Red Book.

http://developer.nvidia.com/object/cube_map_ogl_tutorial.html  Questions?

Spherical Environment Map

 Alternative to cube mapping

Cylindrical mapping

d = 1 2 cos1(y) (x 2 + z2)

u = 0.5 + xd v = 0.5 + zd

Summary

 Texturing from files

 Basic textures  Bump Mapping  Toon shading  Environment Mapping

 Will get to do 3 out of the 4 in lab.