• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
george7378

Confused about monte carlo path tracing

9 posts in this topic

Hi everyone,

 

I've tried to update my ray tracer to handle Monte Carlo path tracing rather than standard ray tracing, and I have got it working but I'd like to check my algorithm over as I'm unsure about a few things. Here's what I'm doing:

 

Base rendering routine: For each pixel (loop through y, x)  and for each sample (loop through sample number, e.g. 100 rays/pixel) shoot a ray through a random point in the pixel, add the results and then divide by the number of samples.

 

My trace function does the following:

 

- For each initial pixel ray, assign an attenuation vector with the value (1, 1, 1) which will be decreased as the ray propagates

- If there's no intersection, return a background colour

- If the intersected shape has an emissive colour, return that colour with 100% probability

- Define the following:

 

float kd = shape->material.diffuseColour.sum(), ks = shape->material.specularColour.sum(), kt = shape->material.transmitColour.sum();

 

...where '.sum()' adds together all the components of the vector

 

- Choose whether to spawn a diffuse, specular or transmitted ray like this:

 

diffuseAttenuation = attenuation*shape->material.diffuseColour; //Per-component multiplication

diffuseProbability = kd/(kd + ks + kt);

if (diffuseAttenuation.findmax() > cutoff && random(0, 1) < diffuseProbability) //'.findmax()' returns largest component of vector

{

- find a random (cosine weighted) direction

- spawn a recursive ray in this direction (its attenuation vector is now equal to diffuseAttenuation)

- multiply it by the current diffuse colour and return.

}

 

else

{

specularAttenuation = attenuation*shape->material.specularColour;

specularProbability = ks/(ks + kt);

if (specularAttenuation.findmax() > cutoff && random(0, 1) < specularProbability)

{

- spawn a recursive ray in a perfectly reflected direction (its attenuation vector is now equal to specularAttenuation)

- multiply it by the specular colour and return

}

 

else

{

transmitAttenuation = attenuation*shape->material.transmitColour;

if (transmitAttenuation.findmax() > cutoff)

{

- spawn a recursive ray in a perfectly refracted direction (its attenuation vector is now equal to transmitAttenuation)

- multiply it by the transmission colour and return

}

 

}

}

 

...OK, so here's what I want to ask about:

 

- I've seen some sites/papers say that I should divide each ray by its probability, e.g. the colour returned by a diffuse ray should be divided by diffuseProbability, etc... - should I be doing this?

- Are there any things you can see wrong with my algorithm? I don;t have any books on this so I'm just going based on what I can lift from papers and various PDFs from unviersities, none of which seem to tell the full story.

 

Thanks!

 

p.s. here's a picture it rendered which took about 45 minutes at 500 samples per pixel. Is this the kind of speed that I should be expecting with this type of path tracing?

 

http://i.imgur.com/hdVfmXh.png

 

:)

Edited by george7378
0

Share this post


Link to post
Share on other sites

I never took the time to properly implement the ideas in [url="http://www.amazon.com/Realistic-Image-Synthesis-Photon-Mapping/dp/1568814623"]"Realistic Image Synthesis Using Photon Mapping"[/url], but I thought it had a lot of good information on the type of things you are doing. I strongly recommend it.

2

Share this post


Link to post
Share on other sites

Thanks for the detailed reply Bacterius :) So by iteratively I guess you mean rather than spawning a new ray with depth + 1 I would loop through all the depths and change the existing ray's direction/proeprties, all the while adding up the colour? That sounds like a good idea seeing as how I only spawn one ray from each intersection, although I'm using cumulative attenuation rather than a ray depth. Maybe I could do it in a while loop?

 

Yes, what I'm doing now is giving whichever ray is spawned full contribution to the sample.

 

Yeah, I'm a bit confused about my probabilities. Since I can only choose one secondary ray I have to check each case one after the other, so I can't see any other way of doing it (unless I limit objects to being only diffuse, specular or refractive).

 

It's currently running on a quad core 1.8Ghz laptop and I'm using OpenMP to multithread, but there aren't any other optimisations.

 

Thanks again :)

 

Alvaro - I looked at photon mapping too but it seems that it would need KD trees to implement and I'd rather not go there given that I'm still doubting myself about my basic implementation!

0

Share this post


Link to post
Share on other sites

Alvaro - I looked at photon mapping too but it seems that it would need KD trees to implement and I'd rather not go there given that I'm still doubting myself about my basic implementation!

 

My recommendation is for the book, not necessarily the technique. Chapter 2 is a great introduction to rendering in general, including some clear definitions of all the quantities involved (radiance, flux...). Chapter 3 is titled "Monte Carlo Ray Tracing" and it covers path tracing. Photon mapping is introduced on chapter 4. But even if you are only going to read the first 3 chapters, it's worth your time and your money.

1

Share this post


Link to post
Share on other sites

Ah right, I'll take a look smile.png I've seen enough papers and powerpoints that it will be nice to see an actual book!

 

In the meantime I've updated the path tracer to be simpler (each surface is now either diffuse, refractive, specular or a light) so that I can be sure it's rendering properly.

 

I also made it iterative, which actually makes it a lot simpler and intuitive (for me, anyway). Right now every ray starts off as (1, 1, 1) and it then enters a while loop based on the magnitude of the largest component of the ray's colour. Every time it hits an object the ray's colour is multiplied by the object's colour and it is given a new direction based on the BRDF of the surface. If it hits a light then the loop is broken and the ray colour is multiplied by the light colour, same for if it hits the sky. The picture it produces is basically the same (yes, I changed the colour of the sphere on purpose!!). This took 205 seconds at 50 samples per pixel.

 

I also now understand the Russian Roulette method for getting rid of certain rays, and I get why you divide by the termination probability. I'll try and see how it looks with textures too :)

 

 

 

0

Share this post


Link to post
Share on other sites

OK, I've been thinking some more about combining specular, diffuse and transmission. Rather than doing it using different colours for each and comparing their magnitudes, which is what I did above, I think this makes more sense:

 

- Each material has a single colour

- assign a probability to each of diffuse, specular or transmission for a given material which total to one, for example:

 

[material shiny_yellow]

colour = (0.8, 0.8, 0.2)

pd = 0.1

ps = 0.9

pt = 0

 

[material dull_glass]

colour = (0.9, 0.9, 0.9)

pd = 0.4

ps = 0.1

pt = 0.5

 

...and then in my code, do the following for an incoming ray:

 

- Find hit point, multiply ray colour by surface colour, get the three probability values

- generate p = random [0, 1] number

 

if (p < pd){ray is scattered diffusely}

else if (p < pd + ps){ray is scattered specularly}

else {ray is transmitted}

 

...in my head, this makes sense. I hope I'm not being stupid! Also, I still don't understand why some papers are telling me to divide by probability density functions left, right and centre.

0

Share this post


Link to post
Share on other sites

I don't think you should link the specular color and the diffuse color of the materials. Look at the reflection of the 13 ball on the 12 ball here: http://www.desktophdwallpapers.eu/view-billiard-balls-1400x1050.html

 

[EDIT: A better thing to look at might be the highlights on billiard balls: They are all white, instead of the color of the individual ball.]

Edited by Álvaro
1

Share this post


Link to post
Share on other sites

That's a good point, I know that it's material specific but for simplicity I'm leaving that out for now! Also I think I finally understand the whole probability division thing - you need to do it if you are choosing whether or not to terminate a ray as opposed to which direction your current ray continues - is this right? So since I'm propagating all my rays until they run out of energy or hit a light, I'm not introducing a bias whereas if I was terminating them based on their radiance, I'd have to weight accordingly. Damn, it's so annoying trying to figure this stuff out from such contextless sources! Makes me wish there was a course on this I could take at university.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0