Final exam effects Textures I Final exam effects Final exam - - PDF document

final exam effects
SMART_READER_LITE
LIVE PREVIEW

Final exam effects Textures I Final exam effects Final exam - - PDF document

Final exam effects Textures I Final exam effects Final exam effects Lighting Grads Light saber Research and implementation plan Stage lighting Textures Teams Coffee froth Implementation Donuts Coke Can


slide-1
SLIDE 1

1

Textures I

Final exam effects Final exam effects

 Lighting

 Light saber  Stage lighting

 Textures

 Coffee froth  Donuts  Coke Can

 Volumetric

 Coffee smoke

 Postprocessing

 Advanced Toon Shader / NPR

Final exam effects

 Grads

 Research and implementation plan

 Teams

 Implementation

 RenderMan  Cg

 Documentations

Final exam effects

 Please register your preference

 Mycourses quiz.

Plan

 Textures

 This week

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

 Next week

 Procedural shading

slide-2
SLIDE 2

2

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 Textures in shaders

 Textures are just data  Texture coordinates available to the

shader

 Global variable / semantic  Actual mapping determined by underlying

scene model.

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.

slide-3
SLIDE 3

3

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

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

 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 Cg

 Texture operations happen in fragment

shaders

 Texture coords, attached to vertices are

interpolated and available to fragment shader

 TEXCOORD0 ,TEXCOORD1 semantic

slide-4
SLIDE 4

4

Textures in Cg

 Access to texture values: use

 texNNNN[proj] () functions  NNNN =

 1D / 2D / 3D - using texture coords (0-1)  RECT - using texel coords (0 - texWidth, textHeight)  CUBE - for environment mapping

 [proj] - projective texture map

 As if projected by slide projector  Useful in shadowing

Textures in Cg

 Projective texture mapping

Textures in Cg (vertex)

struct voutput { float2 texCoord : TEXCOORD0; } voutput mytexturepass (float2 texCoord: TEXCOORD0); { voutput OUT; OUT.texCoord = texCoord; return OUT; }

Textures in Cg (fragment)

struct toutput { float4 color : COLOR; } toutput mytexture (float2 texCoord: TEXCOORD0, uniform sampler2D decal); { toutput OUT; OUT.color = tex2D (decal, texCoord); return OUT; }

Textures in Cg

 The sampler2D datatype

 Sampler objects refer to an external object

that Cg can sample

 Set in application program

 In OpenGL this can be a texture object

 void cgGLSetTextureParameter(CGparameter

param, GLuint texobj);

 Texturing parameters set in openGL will apply.

Textures in Cg

 Textures are data

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

swizzling / masking

 Questions.

slide-5
SLIDE 5

5

What you can do with texture maps

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

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

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…

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));

slide-6
SLIDE 6

6

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 Cg

 Once again, bump mapping like all

texture mapping, must be done by a fragment shader.

 Consider the basic Phong shader.

Phong as a Fragment Shader

void PhongVertexPass (float4 position: POSITION, float3 normal: NORMAL,

  • ut float4 oPosition: POSITION,
  • ut float3 objPos: TEXCOORD0,
  • ut float3 oNormal: TEXCOORD1

uniform float4x4 modelViewProj) {

  • Position = mul (modelViewProj, position);
  • bjPos = position.xyz;
  • Normal = normal;

}

Need texCoord at vertex to be passed to fragment shader

Phong as a Fragment Shader

void basicPhongFrag (float4 position: TEXCOORD0, float3 normal : TEXCOORD1,

  • ut float4 color: COLOR,

uniform float3 globalAmbient, uniform float3 lightColor, uniform float3 lightPos, uniform float3 eyePos, uniform float3 Ka, uniform float3 Kd, uniform float3 Ks, uniform float shininess)

Need texCoord at vertex to be accepted by fragment shader Texture map need to be added as a parameter These values will be modified by values in bump map

Phong as a Fragment Shader

{ float3 P = position.xyz; float3 N = normalize (normal); // ambient term float3 ambient = Ka * globalAmbient; // diffuse term float3 L = normalize (lightPos - P); float diffuseLight = max (dot(N, L), 0); float3 diffuse = Kd * lightColor * diffuseLight;

slide-7
SLIDE 7

7

Phong as a Fragment Shader

// specular term float3 V = normalize (eyePos - P); float3 R = normalize (reflect (L, N)); float specLight = pow (max(dot(R, V), 0), shininess); if (diffuseLight <= 0) specLight = 0; float3 specular = Ks * lightColor * specLight; // put it all together color.xyz = ambient + diffuse + specular; color.w = 1; }

Bump Mapping

 Questions?  Break.

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.

slide-8
SLIDE 8

8

Toon Shading

 To avoid aliasing

 Use large map with gradient between color

transitions.

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

slide-9
SLIDE 9

9

Texture Mapping

 Environment mapping

Environment Mapping

 Both RenderMan and Cg 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);

slide-10
SLIDE 10

10

Environment Mapping in RenderMan

 Creating a cube map:

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

Environment Mapping in Cg

 All texture mapping is done in fragment

shader

 Calculation of reflection vector done in

world space

 Can attach reflection vector to vertex then

pass to fragment shader

Environment Mapping in Cg

 Vertex shader:

 Passthrough:

 Position (converted to clip space)  texCoord (if using other textures)  Normal (converted to world coords)  Reflection vector (in world coords)

 Need:

 ModelViewProj matrix  modelToWorld matrix

Environment Mapping in Cg

 Fragment shader:

 Calculates color based on reflection found

in CUBE map

float4 c = texCube (environmentMap, R);

 Where

samplerCUBE environmentMap;

Environment Mapping in Cg

 Cube Map must be constructed in

OpenGL/DX.

 See pp. 430-431 in Red Book.

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

Summary

 Texturing from files

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

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