Docsity

Environment and Bump Mapping: A Historical Perspective and Cg Implementation - Prof. Aaron, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
1
Lecture 10: Environment and Bump Mapping
Prof. Aaron Lanterman
School of Electrical and Computer Engineering
Georgia Institute of Technology
Real-time graphics has come a long way
Virtua
Virtua Fighter
Fighter
(SEGA Corporation)
(SEGA Corporation)
NV1
NV1
50K triangles/sec
50K triangles/sec
1M pixel ops/sec
1M pixel ops/sec
1995
1995
Dead or Alive 3
Dead or Alive 3
(
(Tecmo
Tecmo Corporation)
Corporation)
Xbox (NV2A)
Xbox (NV2A)
100M triangles/sec
100M triangles/sec
1G pixel ops/sec
1G pixel ops/sec
2001
2001
Dawn
Dawn
(NVIDIA Corporation)
(NVIDIA Corporation)
GeForce FX (NV30)
GeForce FX (NV30)
200M triangles/sec
200M triangles/sec
2G pixel ops/sec
2G pixel ops/sec
2003
2003
Slide from from “Teaching Cg” Powerpoint presentation:
developer.nvidia.com/object/cg_tutorial_teaching.html
The Cg Tutorial
•Can get Cg Toolkit, example code, etc. here:
http://developer.nvidia.com/object/cg_tutorial_home.html
Image from “Teaching Cg” Powerpoint presentation:
developer.nvidia.com/object/cg_tutorial_teaching.html
Nice framework for experimentation
Image from “Teaching Cg” Powerpoint presentation:
developer.nvidia.com/object/cg_tutorial_teaching.html
pf3
pf4
pf5

Partial preview of the text

Download Environment and Bump Mapping: A Historical Perspective and Cg Implementation - Prof. Aaron and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Lecture 10: Environment and Bump Mapping

Prof. Aaron Lanterman

School of Electrical and Computer Engineering

Georgia Institute of Technology

Real-time graphics has come a long way

VirtuaVirtua FighterFighter

(SEGA Corporation)

(SEGA Corporation)

NV1NV

50K50K triangles/sectriangles/sec

1M1M pixelpixel ops/secops/sec

DeadDead oror AliveAlive 33

Tecmo

Tecmo Corporation)

Corporation)

XboxXbox (NV2A)(NV2A)

100M100M triangles/sectriangles/sec

1G 1G pixelpixel ops/secops/sec

Dawn Dawn

(NVIDIA Corporation)

(NVIDIA Corporation)

GeForceGeForce FXFX (NV30)(NV30)

200M200M triangles/sectriangles/sec

2G 2G pixelpixel ops/secops/sec

Slide from from “Teaching Cg” Powerpoint presentation:

developer.nvidia.com/object/cg_tutorial_teaching.html

The Cg Tutorial

  • Can get Cg Toolkit, example code, etc. here:

http://developer.nvidia.com/object/cg_tutorial_home.html

Image from “Teaching Cg” Powerpoint presentation:

developer.nvidia.com/object/cg_tutorial_teaching.html

Nice framework for experimentation

Image from “Teaching Cg” Powerpoint presentation:

developer.nvidia.com/object/cg_tutorial_teaching.html

Cube maps

Images from “OpenGL Cube Map Texturing,”

developer.nvidia.com/object/cube_map_ogl_tutorial.html

Back Front

Right

Bottom Left Top

texCUBE ((samplerCUBE) envMap,(float3) vec)

Reflection and refraction

θ

I

θ

R

θ

I

θ

T

Incident

vector I

Refracted

vector T

Incident

vector I

Reflected

vector R

Normal

vector N

Normal

vector N

θ

I

= θ

R

Ρ

1

sin( θ

I

) = Ρ

2

sin( θ

T

)

T= refract (I,N,etaRatio)

R= reflect (I,N)

Ρ

1

/ Ρ

2

etaRatio=

Ρ

1

Ρ

2

Cg vertex shader for reflective mapping

void C7E1v_reflection( float4 position : POSITION ,

float2 texCoord : TEXCOORD0 , float3 normal : NORMAL ,

out float4 oPosition : POSITION ,

out float2 oTexCoord : TEXCOORD0 ,

out float3 R : TEXCOORD1 ,

uniform float3 eyePositionW,

uniform float4x4 modelViewProj, uniform float4x4 modelToWorld)

oPosition = mul (modelViewProj, position);

oTexCoord = texCoord;

// Compute position and normal in world space

float3 positionW = mul (modelToWorld, position).xyz;

float3 N = mul (( float3x3 )modelToWorld, normal);

N = normalize (N);

// Compute the incident and reflected vectors

float3 I = positionW - eyePositionW; R = reflect (I, N);

From “The Cg Tutorial,” p. 177

Cg pixel shader for reflective mapping

void C7E2f_reflection( float2 texCoord : TEXCOORD0,

float3 R : TEXCOORD1,

out float4 color : COLOR,

uniform float reflectivity,

uniform sampler2D decalMap,

uniform samplerCUBE environmentMap)

// Fetch reflected environment color

float4 reflectedColor = texCUBE (environmentMap, R);

// Fetch the decal base color

float4 decalColor = tex2D (decalMap, texCoord);

color = lerp (decalColor, reflectedColor, reflectivity);

From “The Cg Tutorial,” p. 180

Fresnel effect

reflectCoeff = max( 0 ,min( 1 , bias + scale ( 1 + I • N )

power

))

C

final

= reflectCoeff × C

reflected

  • ( 1 − reflectCoeff ) C

refracted

  • Some light reflects and some refracts
  • Think about looking into water
    • At shallow angles, a lot of reflection and little refraction
    • Looking straight in, a lot of refraction and a little reflection
  • Empirical approximation:

From “The Cg Tutorial,” p. 189

Bump mapping

Drawing from Søren Dreijer, “Bump Mapping Using Cg (3rd Edition),”

www.blacksmith-studios.dk/projects/downloads/bumpmapping_using_cg.php

Images from Paul Baker, “Simple Bumpmapping,”

www.paulsprojects.net/tutorials/simplebump/simplebump.html

Bump mapping examples

Height map

Normal map

Top row from Wikipedia

entry on “bump mapping”

Bottom row from Søren Dreijer, “Bump Mapping Using Cg (3rd Edition),”

www.blacksmith-studios.dk/projects/downloads/bumpmapping_using_cg.php

Shader effect movies

  • Bump mapping demo with the Cimg library

http://video.google.com/videoplay?docid=

  • Bump mapping and reflective textures
    • (HLEH - Half Life mod???)

http://www.youtube.com/watch?v=FmpyHc6hXc

  • Bump mapping on the Nintendo DS

http://www.youtube.com/watch?v=6ypt5JE-ofg

Storing normals in textures

• Textures don’t have to store color; we can store

other things as well, like normals

– Use r, g, b components to store, x, y, z of normal

• Problem: Textures take [0,1] values; normals

need [-1,1] values

• Easy solution: “Range Compression”

colorComponent = 0.5 * normalComponent + 0.5;

normalComponent = 2 * (colorComponent - 0.5);

From “The Cg Tutorial,” p. 202

Creating normal map from height field

• Height field H(u,v)

normal =

H

g

− H

r

, H

g

− H

a

H

g

− H

r

, H

g

− H

a

H

g

H

r

H

a

• In flat regions, normal is (0,0,1), i.e. pointing “up”

From “The Cg Tutorial,” p. 203

Cg vertex shader for bump mapping

void C8E1v_bumpWall( float4 position : POSITION,

float2 texCoord : TEXCOORD0,

out float4 oPosition : POSITION,

out float2 oTexCoord : TEXCOORD0,

out float3 lightDirection : TEXCOORD1,

uniform float3 lightPosition, // Objectspace

uniform float4x4 modelViewProj)

oPosition = mul (modelViewProj, position);

oTexCoord = texCoord;

// Difference vectors for object-space light direction

lightDirection = lightPosition - position.xyz;

From “The Cg Tutorial,” p. 205

Cg pixel shader for bump mapping

float3 expand( float3 v) { return (v-0.5)*2; }

void C8E2f_bumpSurf( float2 normalMapTexCoord : TEXCOORD0 ,

float3 lightDir : TEXCOORD1 ,

out float4 color : COLOR ,

uniform sampler2D normalMap,

uniform samplerCUBE normalizeCube)

// Normalizes light vector with normalization cube map

float3 lightTex = texCUBE (normalizeCube, lightDir).xyz;

float3 light = expand(lightTex);

// Sample and expand the normal map texture

float3 normalTex = tex2D (normalMap,normalMapTexCoord).xyz;

float3 normal = expand(normalTex);

// Diffuse lighting

color = dot(normal,light);

From “The Cg Tutorial,” p. 206