13.07.2015 Views

Raytracing

Raytracing

Raytracing

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

How do we get shadows?What is different about the lightcomputation to get shadows?CSE 472 Spring 20137Shadow FeelersBefore we compute the colorcontribution for a light, shoot a ray inthe light direction.Does it hitanything?Called a:“Shadow Feeler”CSE 472 Spring 20138


Computing Ray Color// Compute the color for a raycolor RayColor(ray)Test ray for intersectionIf(intersection)Determine for intersection:intersection point, normal, material, texture colorcolor = compute-ambient-colorforeach lightif shadowfeeler does not hit anythingcolor += compute-diffuse-color-from-lightcolor += compuer-specular-color-from-lightreturn colorelsereturn background-colorCSE 472 Spring 20139But, be careful or you get:CSE 472 Spring 2013Stipple!10


Problems w/ numerical precisionCSE 472 Spring 2013How far is this pointfrom the polygon?11Problems w/ numerical precisionCSE 472 Spring 201312


A little above or a little belowYour intersection point will be roundedto the nearest float, double, whatever.• Unlikely it will be on the polygon!• If it’s above, no problem• If it’s below, what happens to ourshadow feeler?CSE 472 Spring 2013Term: Self-shadowing13Self-shadowing SolutionsIgnore any intersection less than somesmall amount• But, how small? What about corners?Ignore the polygon we are intersectingwith.• Most common solution.CSE 472 Spring 201314


Intersect Functionbool Intersect(const CRay &p_ray, // The ray we are testingdouble p_maxt, // The maximum allowable tconst Object *p_ignore, // A polygon to ignoreconst Object *&p_object, // Object we hit (return)double &p_t,// Distance to intersection (return)CGrPoint &p_intersect); // Intersection point (return)CSE 472 Spring 201315Intersect Functionbool Intersect(const CRay &p_ray, // The ray we are testingdouble p_maxt, // The maximum allowable tconst Object *p_ignore, // A polygon to ignoreconst Object *&p_object, // Object we hit (return)double &p_t,// Distance to intersection (return)CGrPoint &p_intersect); // Intersection point (return)What is the use for p_maxt?CSE 472 Spring 201316


SummaryConstruct a shadow feeler ray• Starts at intersection, direction is towards lightShoot ray at light (intersection test)• Set ignore to ignore the polygon ourintersection point is on.• Set maxt to the distance to the light.If we get an intersection, we are shadowedCSE 472 Spring 201317Next amazing thingCSE 472 Spring 201318


Aliasing, aka “Jaggies”Why doesthis happen?CSE 472 Spring 201319Point samplingCSE 472 Spring 201320


Point samplingCSE 472 Spring 201321But, we don’t see like this…Why don’t we see like this?Why don’t camera images look likethis?CSE 472 Spring 201322


Characteristics of the Human EyeReceptors have area• They are not points• What would this mean?Receptors are randomly distributed• Not true for cameras, but they do getmore artifacts than we seeCSE 472 Spring 201323That “area” issue…CSE 472 Spring 201324


What we want (to simulate nature)We want the color of a pixel to bethe area-weighted average ofwhat’s under the box for the pixel• How can we do this with rays?CSE 472 Spring 201325General answer to all things ray tracing…CSE 472 Spring 201326


Instead of one raythough the center…CSE 472 Spring 201327But, where?Bad choice• Rectangular grid• Causes animations problemsCSE 472 Spring 201328


Common AlternativesFixed Jitter Tables• OpenGL book has one• Not really a very great choiceRandom• The choice of championsCSE 472 Spring 201329Antialiasing in Ray TracingFor each pixel• For i=1 to antialiascnt• Generate random location in pixel• Shoot ray through random pixel• Ray color is average of all raysCSE 472 Spring 201330


uniform random numbersFirst idea is to use uniformlydistributed random number (rand())• This does not work as well becausethey tend to have clumps.CSE 472 Spring 201331Clumping110.90.90.80.80.70.70.60.610 1000.50.50.40.40.30.30.20.20.10.100 0.2 0.4 0.6 0.8 100 0.2 0.4 0.6 0.8 110.90.80.710000.60.50.40.30.2CSE 472 Spring 20130.100 0.2 0.4 0.6 0.8 132


The Poisson DistributionSimple idea• We generate a set of random numbers, notwo of which are closer than someminimum distance to each other• How would you do this• Think of generating one random number ata time• How do you do this in 2D?CSE 472 Spring 201333Poisson GeneratorFor each set of random numbers needed:history.clearFor each random number needed:dovalid = true // Till we know otherwisepoint p = (rand(min,max), rand(min, max))foreach item in historyif(Distance(item, p) < minimumDvalid = falsewhile !validhistory.add(p)return pCSE 472 Spring 201334


Poisson Distributions10.90.810.90.80.70.70.60.60.50.510 1000.40.40.30.30.20.20.10.100 0.2 0.4 0.6 0.8 100 0.2 0.4 0.6 0.8 110.90.80.70.610000.50.40.30.2CSE 472 Spring 20130.100 0.2 0.4 0.6 0.8 135Compare110.90.90.80.80.70.70.60.60.50.50.40.40.30.30.20.20.10.100 0.2 0.4 0.6 0.8 100 0.2 0.4 0.6 0.8 1RandomPoissonCSE 472 Spring 201336


What’s the minimum distance?I usually use: range / (2 * sqrt(N))• N points in 2D spaced evenly would berange / sqrt(N) apart• We make the minimum distance half that• When sampling an area that is notsquare, use: sqrt(area) / (2 * sqrt(N))CSE 472 Spring 201337Where does the name come from?CSE 472 Spring 201338


Poisson is French for “Fish”CSE 472 Spring 201339BTW…The rods and cones in the eyeapproximate a Poisson distribution• Well, what do you know about that!!CSE 472 Spring 201340


Antialiasing Ray TracingCPoisson2D poissonPoisson.SetMinDistance( 1 / (2 * sqrt(antialiascnt) )for r = 0 to height-1for c = 0 to width-1poisson.reset()color = (0, 0, 0)for a=1 to antialiascntp = poisson.generate()ray.origin = (0, 0, 0)ray.direction.x = xmin + (c + p.x) / width * xwidray.direction.y = ymin + (r + p.y) / height * ywidcolor += RayColor(ray)color /= antialiascntpixel(r, c) = RangeBound(color)CSE 472 Spring 201341No AntialiasingCSE 472 Spring 201342


4x AntialiasingCSE 472 Spring 20134316x AntialiasingCSE 472 Spring 201344


64x Antialiasing/20 minutesCSE 472 Spring 201345Stochastic Ray TracingThe term for the use of random raysto increase quality in ray tracing is:• Stochastic Ray TracingSometimes also called:• Distributed Ray Tracing• A most unfortunate choice of wordsCSE 472 Spring 201346


Next?CSE 472 Spring 201347ReflectionsHall indicated what to do with thereflection, so where does it comefrom?• Shoot more rays• Shoot a ray in the reflectiondirection and see what color you see.• The Self-Shadowing issue stillapplies!CSE 472 Spring 201348


RayColor functionYou should have a RayColor functionHere’s what mine looks like:void CRaytraceRenderer::RayColor(const CRay &p_ray, (input)CRayColor &p_color,(output)int p_recurse,(to control recursion)const CUseIntersection::Object *p_ignore) (ignore)This will call itself• We call this a recursive ray tracer• What is your stopping condition?CSE 472 Spring 201349TransmissionI’ll let you figure this one out…CSE 472 Spring 201350


Recursion issuesDon’t recurse if you don’t need to• What if the specular color is black?Recursion is expensive• Decide how much you want to doCSE 472 Spring 201351What’s different, now?CSE 472 Spring 201352


CSE 472 Spring 201353PenumbraPenumbra is a soft-edged shadow• You get it when the light has area• Often called “soft shadows”CSE 472 Spring 201354


How do we solve this problem?All together, now!CSE 472 Spring 201355How do we solve this problem?All together, now!CSE 472 Spring 201356


Implementing PenumbraSample point on the surface of the light with a PoissonDistribution. Minimum distance is:d = sqrt(lightArea) / sqrt(numRays) * 0.5CSE 472 Spring 201357How to find a spot on the surfaceof a rectangular lightdcalen=length(b – a)wid=length(d – a)area = len * widx = xp / len y = yp / widpoint = a (1 – x) (1 – y) + b (x) (1 – y) + c (x) (y) + d (1 – x) (y)CSE 472 Spring (xp, 2013yp) is from Poisson distribution from (0, 0) to (len, wid)b58


RayColor with PenumbraCPoisson2D poissonPoisson.SetMinDistance( sqrt(lightarea) / (2 * sqrt(antialiascnt) )color = ambient lightforeach lightfor p=1 to penumbraCntPP = random point on surface of light (Poisson distribution)L = PP – intersectif shadowfeeler doesn’t hit anythingcolor += contribution from this light / penumbraCntcolor += any reflectionscolor += any transmissionreturn colorCSE 472 Spring 20135916x Antialiasing, 8x penumbra, 1 level of recursionCSE 472 Spring 201360


Stats for that imageKd Tree Nodes: 31399Tree Depth: 39Intersection Tests: 112,276,007Polygon Tests: 476,466,446Average polygon tests per IT: 4.24371CSE 472 Spring 201361Depth of FieldWhat causes depth of field in a cameraor your eye?How would youimplement it?CSE 472 Spring 201362


Putting it all togetherWe have three stochastic things:• Antialiasing• Penumbra• Depth of FieldWhat’s an efficient way to do all ofthese together?CSE 472 Spring 201363Motion blurWhat causes motion blur?How would youimplement it?CSE 472 Spring 201364


FogAny ideas?CSE 472 Spring 201365StarsWhy are they hard?CSE 472 Spring 201366


Stochastic Ray TracingProblem with ray tracing:Point samplingWe can introduce randomnessall over the place• Jitter for antialiasing• Light area for penumbra• Depth of field and motion blur[Jensen07]CSE 472 Spring 201367Path Tracing1) Sample each pixel with N rays2) At each intersection, trace only one rayproportion of rays in each categoryshould match the actual (surface) distributionRay TracingPath TracingReduces the amount of work deeper in the ray treeCSE 472 Spring 201368


Adaptive samplingDetermine if number of samples isenough• If not, increase the numberWorks for uniform and stochasticsamplingCSE 472 Spring 201369Ray tracing from the light sourcesIn regular ray tracing we don’t see• Lighting reflected through mirrors• Surfaces lit by reflection from other surfacesLarge set of rays from each light• Computes light that hits surfaces• General solution for diffuse reflection?• Still requires tracing from the eye as pass 2CSE 472 Spring 201370


Photon map•Photon by light-based raytracing•Separating GI from rendering•Stored in kd-trees•Good for• Caustics, subsurface scattering,• …CSE 472 Spring 201371Photon pathStart from light sourcesIntensity -> photonCSE 472 Spring 2013[Jensen]72


Final Gathering•Radiance Computation•Distributed ray tracingCSE 472 Spring 2013[Jensen]73Another example[Jensen00]CSE 472 Spring 201374

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!