11
EECS 487: Interactive Computer Graphics Lecture 15: Scenegraph Lighting and Reflection Hierarchical Modeling Hierarchical modeling is essential for transforming objects with attached parts, e.g., in animation: eyes move with head hands move with arms feet move with legs Without such structure the model falls apart, e.g., eyes don’t follow when head moves This idea can be extended to the entire scene scene graph collect every objects into a single hierarchy How to represent a scene? list of objects transform of each object can use minimal primitives: an ellipse is a transformed circle transform applies to points on object Scene representation: data structures+transforms Scene Representation Marschner Can represent scene as a flat list of objects but editing (e.g., delete) requires updating many nodes Scene as a Flat List of Objects Marschner house roof door window window

EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

EECS487:Interactive

ComputerGraphics

Lecture15:•  Scenegraph•  LightingandReflection

HierarchicalModelingHierarchicalmodelingisessentialfortransforming

objectswithattachedparts,e.g.,inanimation:•  eyesmovewithhead

•  handsmovewitharms

•  feetmovewithlegs

• …

Withoutsuchstructurethemodel

fallsapart,e.g.,eyesdon’tfollow

whenheadmoves

Thisideacanbeextendedtothe

entirescene→scenegraph•  collecteveryobjectsintoasinglehierarchy

Howtorepresentascene?•  listofobjects•  transformofeachobject•  canuseminimalprimitives:anellipseisatransformedcircle

•  transformappliestopointsonobject

Scenerepresentation:datastructures+transforms

SceneRepresentation

Marschner

Canrepresentsceneasaflatlistofobjects•  butediting(e.g.,delete)requiresupdatingmanynodes

SceneasaFlatListofObjects

Marschner

house roof door window window

Page 2: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

Introduceanewabstractdatatype:group•  treatsasetofobjectsasoneobject(group)•  containslistofreferencestomemberobjects

•  letsthedatastructurereflecttherenderingstructure•  enableshigh-leveleditingbychangingjustonenode

HierarchicalRepresentation

Marschner

Allpartsofthescenearerepresentedinonegraph

•  eachnodeinthegraphisonesceneelement,including

•  objects,cameras,lights,materials,transformations,…

•  switch/select:specifywhichchildrentoenable,etc…

•  simulationprocedures,shaders

•  otherscenegraphs

•  simplestform:tree

•  everynodehasoneparent

•  interiornodes=groups

•  leafnodes=objectsinthescene

•  edges=membershipofobjectingroup

•  transformsareassociatedwithnodesoredges

•  eachtransformappliestoallgeometrybelowit

SceneGraphs

Marschner,TP3,Schulze

Marschner,Schulze

SceneGraphExample

TheGraphicsSoftwareStack

graphicsAPI•  interfacetographicshardware,e.g.,OpenGL,

Direct3D

GPU

scenegraph/renderingengine•  as“scenegraphAPI”:middlewareforgraphicsAPI

•  as“3Dtoolkit”:implementgraphicsfunctionalities

commonlyrequiredinapplications

applications• modelingprogramsusescenegraphtomanage

complexity,e.g.,Maya,3dsmax,etc.

•  games,visualization,virtualreality,webapps

Schulze

Page 3: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

SceneGraphs

Todrawthescene,thegraphiswalked

•  eachtimeanodeistraversed,eithertherendering

stateischangedorsomethingisrenderedwiththe

currentstate

•  anoperationperformedonanode,suchasrendering,

culling,andtransform,affectsallofitschildren

•  e.g.,traversingalightnodeturnsonthelightforallitschildren•  transformsaccumulatealongpathfromroottoleaves

Makesmodelingandanimationofcomplex

sceneseasierbybreakingthemdownintoa

hierarchyofsimpleroneswiththeirownlocal

behavior

Chenney

SceneGraphAdvantages

Hierarchicalprocessing•  eachsub-hierarchynaturallydefinesaboundingvolume,

e.g.,forculling,collisiondetection,orray-tracing

computation

Object-orientedparadigm•  eachobjectisdefinedinitsownlocalcoordinatesystems

• objectscanhaveotherpropertiesbesidesshape•  color,shadingparameters

•  approximationparameters(e.g.,degreeoftessellation)

•  userinteraction,etc…

•  propertynodescanbeappliedtosub-hierarchy,e.g.,paintentirewindowgreen

• objectsareself-containedandre-usable•  instancing:anobjectcanbeamemberofmultiplegroups

TP3,Marschner

Allowmultiplereferencestonodes

•  reflectsmoreofdrawingstructure

•  allowseditingofrepeatedpartsinoneoperation

InstancingExample

Marschner

MultipleInstantiations

Objectdefinedonce,usedmanytimes,

inmanyplacesinthescene

•  anobjectwithmultipleinstantiationshasmultipleparents•  notthe“makeacopy”instantiationofC++

•  transformsstillaccumulate

alongpathfromroottoleaf

•  objectsmayhavemultiplepaths

fromroottoleaves

•  transformmaybedifferent

foreachinstance

• graphisnolongeratree,butadirectedacyclicgraph

(DAG,nocycle)

Schulze,Marschner,James

Page 4: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

SceneGraphToolkitsandAPIsNobroadlyacceptedstandard

APIsfocusondifferentapplications•  OpenSceneGraph(openscenegraph.org)•  scientificvisualization,virtualreality,GIS•  optimizedformemoryrequirements

•  opensourceversionofhistoricalscenegraphAPIsforSGIIRISGL•  OpenInventor(oss.sgi.com/projects/inventor/)•  OpenGLPerformer(oss.sgi.com/projects/performer/)

•  Ogre3D(www.ogre3d.org)andahostofothers•  games,optimizedforhigh-performancerendering(speed)

•  Javascriptscenegraphs,WebGLcompatible:•  three.js(threejs.org)•  “alightweight3Dlibrarywithaverylowlevelofcomplexity”

•  sceneJS(scenejs.org)•  CAD,medical,andengineeringvisualization

•  Modelingsystems’proprietarylibraries•  optimizedforeditingflexibility

BasicSceneGraphOperations

High-levelscenemanagement

•  edittransformation•  needgoodUI

•  transformobjectinworldcoordinateframe•  traversepathfromroottoleaf

•  groupingandungrouping

•  re-parenting•  movingnodefromoneparenttoanother

Marschner

CommonFunctionalities

Resourcemanagement•  assetmanagement(geometry,textures,materials,

animationsequences,audio)

•  shadermanagement

• memorymanagement

• multi-threading

•  (serverclustering)

Renderinglibraries:•  bumpmapping

•  shadows

•  particlesystem

Schulze

PerformanceOptimizationsCulling•  earlydiscardofinvisiblepartsofscene

Level-of-detail•  uselowerpolycountversionfordistant(small)object

Computingboundingvolumehierarchyfor•  culling•  collisiondetection•  rendering,e.g.,ray-tracing,qsplat

Scenegraphcompilation/optimization•  renderobjectswithsimilarattributes(textures,materials,

shaders,geometry)inbatches•  efficientuseoflow-levelAPI

•  avoidstatechangesinrenderingpipeline

Seriousscenegraphsshouldhave

implementationofthesetechniquesSchulze

Page 5: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

SceneGraphEncoding

Collada•  assetexchangeusinganXMLschema•  e.g.,passingmodelstoaphysicsengine

•  assettransformationfromhigh-levelmodeling

descriptiontoplatform-specificoptimizeddescription

•  candescribeeverythingtodowithascene:

geometrywithfullskinning,advanced

materialandvisualeffects,animation,

physicalpropertiesandcollisions

customtools

Maya

SceneGraphEncodingX3D (web3d.org)• VRMLwithXMLsyntax,replacedVRMLinJuly2004•  primarygoalisforinteractivevisualizationof3Dassets

•  specifiesbehaviorsandinteractionsandincludes•  arun-timemodelthatenablesviewing,navigation,picking,andscripting

•  anAPItomanipulatethescene-graphatruntime

X3DOM• HTML5/X3Dintegration

•  declarative3D(vs.

proceduralWebGL)

• x3dom.orgview3D (PA2,4)

EECS487:Interactive

ComputerGraphics

Lecture15:•  Scenegraph•  LightingandReflection

ObjectAppearanceinCGI

ObjectappearanceinCGIdependsonits

•  shape:thegeometryofitssurfacesandpositionwrtcamera

•  shade:itsilluminationenvironmentandopticalproperties

Renderingprogramseparates:

•  geometricprocessing:transformation,hiddensurfaceremoval,etc.from

•  opticalprocessing:propagationandfilteringoflight

Page 6: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

IlluminationModelsArenderingprocesscanbemodeledasanintegralequationrepresentingthetransportoflightthroughtheenvironment�therenderingequation

Localillumination:anapprox.oftherenderingeqn.•  assumeslightisscatteredonlyonce:lightfromlightsourceisreflectedbyasurfaceandmodulatedonitswaytowardstheeye

Globalillumination:•  lightraystravelingfromlighttosurfacemaybe•  blockedbyinterveningsurfaces(shadows)or

•  bentorscatteredbyinterveningmaterial(refractionandatmosphericeffects)or

•  lightarrivingatasurfacemaycomeindirectlyviaanothersurface(reflectionandcolorbleed)

GlobalIlluminationEffects

Properlydeterminingtherightcolorisreallyhard•  translucency•  refraction• particlescattering•  colorbleed

LocalIllumination

Aphotographofalitsphereshowsnotauniformlycoloredcirclebutacircularshapewithmanygradationorshadesofcolor,givingtheimpressionof3D

Localilluminationconsistsoftwomajoraspects:

1.  lightsourcedistributionfunction2. surfacereflectancedistributionfunction

LightSources

LightisapproximatedbytheRGBcomponents

emittedfromthelightsource

Forlight,theRGBcoefficientsrepresent

percentagesoffullintensityofeachcolor

•  c = (1.0, 1.0, 1.0)iswhite

•  c = (0.5, 0.5, 0.5)iswhiteathalfintensity,

whichappearsgray

Page 7: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

LightSources

Grassman’sLaws:

•  iftwolightsemitatc1 = (R1, G1, B1)andc2 = (R2, G2, B2),thelightthatarrivesattheeyeis

c = c1⊕ c2 = (R1 + R2, G1 + G2, B1 + B2)•  scalinglightintensity:c(s a) = s c(a)

a b

LightSources

Typesoflightsources

• pointlight,e.g.,lightbulb:lightdirectionchangesoversurface

• directionallight,e.g.,sunlight:“distant”light,directionisconstant

• spotlight:pointsourcewithdirectionalfall-off

• areasource:luminous2Dsurface:radiateslight

fromallpointsonsurface,generatessoftshadowsspotlightdirectionalpointlight

PointandDirectionalSources

Pointlight:

•  lightarrivingatapoint(x)onthesurface•  lalwayspointstowardsthelight

•  mustbenormalized

•  tospecifyanOpenGLlightatlightposition(1, 1, 1):Glfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position);

Directionallight:l(x) = llight

•  thelvectordoesnotvaryacrossthesurface• OpenGLlightshiningfromdirection(1, 1, 1):Glfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position);

l(x) =plight -xp

light-x

x

plight

Spotlight

Pointsource,withintensityafunctionof–l,specifiedwith:

•  position:thelocationofthesourceglLightfv(GL_LIGHT0,GL_POSITION,light_posn);

•  direction(sdir):thecenteraxisofthelight

glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,light_dir);•  intensitymaximalalongdirectionsdir

•  whenlightmoved,directionmustbeupdatedalongwithposition

•  cut-off(α):howbroad(indegree)thebeamisglLightfv(GL_LIGHT0,GL_SPOT_CUTOFF,45.0);•  intensityfallsoffanglingawayfromsdir

•  exponent(sexp):howthelighttapersoffattheedgesoftheconeglLightfv(GL_LIGHT0,GL_SPOT_EXPONENT,1.0);•  intensityscaledbyexponent:sspot = max(−l • sdir, 0)sexp

Spotlight

−l

(cosα)sexp

sdir

α

Page 8: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

OpenGLLightSources

glLightfv(lightname,param,value) •  parameters

• GL_AMBIENT • GL_DIFFUSE • GL_SPECULAR

• GL_POSITION• GL_SPOT_DIRECTION • GL_SPOT_CUTOFF • GL_SPOT_EXPONENT

• GL_CONSTANT_ATTENUATION • GL_LINEAR_ATTENUATION • GL_QUADRATIC_ATTENUATION

HowLightsArePositioned

Allcomputationsarecarriedoutineyecoordinates

•  storelightsineyecoordinates

•  lightsconvertedtoeyecoordinatesusingcurrentModelViewtransform

•  lightsmovewitheye•  defaultGL_LIGHT0–directionalfromtheback,

withspecularcomponent

•  glEnable(GL_LIGHTING); •  glEnable(GL_LIGHT0); •  don’tforgettosetthenormalsproperly

WhyisWinterLightWeaker

thanSummerLight?

Theamountoflightreceivedandreflectedbyasurface

dependsonangleofincidence(θ)•  biggeratnormalincidence

•  smallerslanted,byhowmuch?

•  Lambert’sCosineLaw:

proportionaltocosθ

Durand,FvD94

n

surface

θ

n

Surface2 Surface1

n

dA

dA cos θθ

π/2 − θ

Recall:

sin(π/2–θ) = cosθ

SurfaceNormalTheintensityofasurfacecolordependsonthe

orientationofthesurfacewrtthelightandviewer

Thesurfacenormalvectordescribes

thisorientationatapoint

•  isperpendiculartothetangentplaneofthesurface(recall

howtotransformnormals)

•  isoftencalledjust“thenormal

vector”or“thenormal”

• willusenorNtodenote

Normalsareeithersupplied

bytheuserorautomaticallycomputed

surface

normal

light

direction

Page 9: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

SpecifyingNormals

NormalscanbespecifiedusingglNormal3*()

Normalsareassociatedwithvertices

Specifyinganormalsetsthecurrentnormal•  remainsunchangeduntiluseraltersit

•  usualsequence:glNormal3, glVertex, glNormal3, glVertex, glNormal3, glVertex,…

Normalsarenotnormalizedbydefault•  canbeautomaticallynormalizedbycallingglEnable(GL_NORMALIZE)orglEnable(GL_RESCALE_NORMAL) •  butthisisslow,insteadnormalizeasneeded

MaterialAppearance

Factorseffectingmaterialsappearance•  color•  texture•  intensityandshapeofhighlights•  glossiness

Forsurfacecolor,theRGBcoefficients

representpercentagesofreflected

proportionsofeachcolor

Ngan,Hanrahan

OpenGL’sSimpleReflectanceModel

Ifthelightisemittingcl = (Rl, Gl, Bl)andthematerialreflectscm = (Rm, Gm, Bm),thelightthatarrivesattheeyeisc = cl ⊗ cm = (Rl Rm, Gl Gm, Bl Bm)

Aredballinwhitelightreflectsred

andabsorbsgreenandblue

Aredballingreenlightappearsblack

(nolightisreflected)

OpenGLLightingandReflectance/* Initialize material property, light source, lighting model, and depth buffer. */ void init(void) { GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 50.0 }; GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); }

Page 10: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

Clampingvs.Scaling

RGBcoefficientsmustbein[0.0, 1.0]range

Reflectedcolorc = (c1⊕ c2) ⊗ cm=�[(R1 + R)Rm2, (G1 + G2)Gm, (B1 + B2)Bm] mayhave

component> 1.0,e.g.,brightorangeis(2.5, 1.5, 0.5)•  ifclampedto1.0,(1.0, 1.0, 0.5)isyellow

•  ifscaledby1/2.5instead,weget(1.0, 0.6, 0.2),whichretainstheoriginalorangehueandsaturation

MicrofacetTheory:modelsurfaceasacollection

oftinymirrors[Torrance&Sparrow1967]

Exampleofmicrofacetdistribution:

•  surfaceoftheocean•  viewersees“bright”pixels

•  whenmicrofacetsarepointing

halfwaybetweenthesunandtheeye

•  othermicrofacetsareobstructed,

eitherinshadoworhidden

Torrance-SparrowReflectanceModel

Durand

MicrofacetModel[Cook&Torrance82]Reflectanceat(l,v)isaproductofthe•  numberofmirrorsorientedhalfwaybetweenlandv,•  percentageofunblockedmirrors,and

•  Fresnelcoefficient:fractionoflightreflected(notabsorbed),

functionofangleofincidenceandindexofrefraction

Durand

l

v

h

Lozano-Perez

MeasureofReflectance:BRDF

ωo

ωi

ρ (θi, φi, θo, φo)

Differentmaterialemits,absorbs,

orreflectslightdifferently

BidirectionalReflectanceDistributionFunction(BRDF)

ρ (ωi, ωo):•  ratioofradianceincomingfromone

directionthatgetsreflectedin

anotherdirection•  relatesincominglightenergytooutgoing

•  functionbasedondirectionsofincidenceandview

•  unifyingframeworkformanymaterials

•  (assumeisotropicmaterial,reflectance

isinvarianttorotationaboutthenormal,

unlikevelvetorsatin,e.g.)

Page 11: EECS 487: Interactive Computer Graphicsweb.eecs.umich.edu/~sugih/courses/eecs487/lectures/... · The Graphics Software Stack graphics API • interface to graphics hardware, e.g.,

Hanrahan

TypesofReflection

Wegenerallyrecognize3typesofreflection:

IdealSpecular• ReflectionLaw

• Mirror

IdealDiffuse•  Lambert’sLaw

• Matte

RoughSpecular• Directionaldiffuse• Glossy

HowtoObtainBRDF?

Gonioreflectometer

Ward,Hanrahan