• 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
Geometrian

Choose Path in Path Tracing

9 posts in this topic

Hi,

I've implemented a path tracer. It can handle materials that are either completely diffuse (cosine weighted) or specular (cosine^n weighted).

For mixed surfaces, clearly one ray must be generated for either specular or diffuse. My question is, how do you decide? I doubt it's just 50-50.

Any hints or resources would be great. Thanks,
-G
0

Share this post


Link to post
Share on other sites
I'd say it actually might be 50:50 or other ratio based on the surface properties at the hit point. In case you plan to support various other paths (material properties), you'll use a "roulette" selection scheme. However, I can't tell how to scale the [b]probabilities[/b] as I haven't done it myself yet :(
0

Share this post


Link to post
Share on other sites
In the real world, nothing is perfectly diffuse or perfectly specular, things are always somewhere in between (as you probably know) [img]http://public.gamedev.net/public/style_emoticons/default/smile.gif[/img]

The diffuse/lambertian model assumes that when a photon strikes the material, it is [i]equally [/i]likely to exit in [i]any[/i] direction -- all possible directions are weighted with 1.0.
The cosine weighting isn't actually part of the diffuse model -- it's based on the fact that when illuminating a surface at a glancing angle, the area covered by the light is greater than the area covered when illuminating a surface head-on. This cosine weighting should therefore be applied to all materials.

The two basic categories of reflection (diffuse and specular) originate from the physical laws of reflection vs refraction, which people normally associate with the science experiment where you use a glass prism to make rainbow colours appear.

When a photon strikes a surface, there is a certain probability that it will be reflected straight off the surface, without any real interaction taking place ([i]which means it's not discoloured by the surface[/i]) -- this is what we call a specular reflection.
The other possibility ([i]if it isn't reflected[/i]) is that the photon is refracted [b]into [/b]the surface. When this happens, the photon will bounce around inside the material, losing energy ([i]"picking up colour"[/i]) with each bounce -- however, if it's lucky, it will bounce right back out of the surface into the air -- this is what we call a diffuse reflection. The bouncing essentially makes the exit direction random, and the energy loss is what causes the surface to appear coloured ([i]it's "diffuse colour" / "albedo"[/i]).

In physics, you would use a material's [b]i[/b]ndex [b]o[/b]f [b]r[/b]efraction to tell you how likely a photon is to be reflected vs refracted. In computer graphics though, we usually use a "specular mask" value instead ([i]where [font="Courier New"]specMask ~= ((IOR-1)^2)/((IOR+1)^2)[/font][/i]). You can think of the spec-mask as a probability value -- if it's 1.0, then there's 100% chance of reflection and 0% chance of refraction. If it's 0.0, then there's a 0% of reflection and a 100% chance of refraction.

So, your original idea of using a 50/50 mix is equivalent to a material with a specular mask value of 0.5 ([i]which corresponds to an IOR value of 5.8, which would be a highly exotic material -- [b]much [/b]shinier than diamond[/i]).
Real-world materials typically have spec-mask values between 0.01 and 0.2.
0

Share this post


Link to post
Share on other sites
[quote]In physics, you would use a material's index of refraction to tell you how likely a photon is to be reflected vs refracted.[/quote]

Wrong.

In physics the photon actually reflects with some energy and refracts with some energy (see. Fresnel equations for that). As Fresnel equation is defined as: "When light moves from one medium with refractive index n1 to another medium with refractive index n2, both reflection and refraction might occur. The relationship between incident ray and reflected ray angles is Law of reflection, and relationship between incident ray and refracted ray is Snell's law of refraction. In simple model, the fraction of power that has been reflected is known as reflectance and the fraction of power that has been refracted is known as transmittance - the rest will be absorbance (if any), to keep model simple, we assume both mediums aren't magnetic.
Both reflectance and trasmittance depends on polarisation of light. All equations can be found in any good physics book.


Thats the only correct way to do it, otherwise it is just an approximation.

-1

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1323936018' post='4894113']The diffuse/lambertian model assumes that when a photon strikes the material, it is [i]equally [/i]likely to exit in [i]any[/i] direction -- all possible directions are weighted with 1.0.
The cosine weighting isn't actually part of the diffuse model -- it's based on the fact that when illuminating a surface at a glancing angle, the area covered by the light is greater than the area covered when illuminating a surface head-on. This cosine weighting should therefore be applied to all materials.[/quote]Not quite. Suppose light is normal to a surface. Now, I change my viewing angle. If light has an equal probability of bouncing sideways as straight back, then the surface would appear brightest when I'm looking farthest from the normal (the surface takes up less area in my FOV. There are actually three cosine terms: the light (N dot L), the reflection, and the viewer's angle. It's just that the last two cancel.

[quote name='Vilem Otte' timestamp='1323972086' post='4894227']
[quote]In physics, you would use a material's index of refraction to tell you how likely a photon is to be reflected vs refracted.[/quote]

Wrong.

In physics the photon actually reflects with some energy and refracts with some energy (see. Fresnel equations for that).[/quote]Actually, he's sort of right. Path tracers deal in probabilities, because they only trace one photon's path. So you have to choose. The [i]way[/i] you do this (for glass) is with the Fresnel equations.

I'm aware the Fresnel equations apply for glass. So, they work for other classes of materials too? For example, plastic sphere (classic Phong shading example) would choose whether to make a diffuse ray or a specular ray based on Fresnel equation probabilities?

Thanks,
-G
0

Share this post


Link to post
Share on other sites
[quote name='Vilem Otte' timestamp='1323972086' post='4894227']In physics the photon actually reflects with some energy and refracts with some energy (see. Fresnel equations for that). As Fresnel equation is defined as: "When light moves from one medium with refractive index n1 to another medium with refractive index n2, both reflection and refraction might occur[/quote]I was under the impression that a continuous wave of light will both reflect and refract, but each individual photon (which is one quanta of light) has to do one or the other? -- In the same way that a beam-splitter will send 50% of a laser's energy down each path, but is unable to split a [i]single [/i]photon ([i]which must take one path or the other[/i]).

Either way, isn't the end result the same when working with the probability of a quanta taking each path, compared to the percent of energy that takes each path?

[quote name='Geometrian' timestamp='1323989179' post='4894308']Suppose light is normal to a surface. Now, I change my viewing angle. If light has an equal probability of bouncing sideways as straight back, then the surface would appear brightest when I'm looking farthest from the normal (the surface takes up less area in my FOV[/quote]I don't follow your logic here - shouldn't that mean that it's the same brightness from any viewing angle, and that only the light/surface angle affects it's brightness?
Another way of phrasing my meaning is that the N.L factor is part of the rendering equation, and NOT part of the BRDF. The lambertian BRDF is simply a constant number.

[quote]Actually, he's sort of right. Path tracers deal in probabilities, because they only trace one photon's path. So you have to choose.[/quote]If I am wrong about that, then at the point of impact, your photon splits in two and you've got a refracted photon and a reflected photon... so I guess you could trace both paths from the split onwards?
[quote]I'm aware the Fresnel equations apply for glass. So, they work for other classes of materials too? For example, plastic sphere (classic Phong shading example) would choose whether to make a diffuse ray or a specular ray based on Fresnel equation probabilities?[/quote]Yeah, at work we take the IOR for any material and calculate the Fresnel reflectance at 0°, and call that value our "spec mask". We then use that value in Schlick's approximation to get the fresnel term for other angles.
0

Share this post


Link to post
Share on other sites
[quote]I was under the impression that a continuous wave of light will both reflect and refract, but each individual photon (which is one quanta of light) has to do one or the other?[/quote]
Actually it can just reflect or refract when we're taking each single photon into account (but then path tracing is very insufficient model for this - as it holds color (not wavelength - it actually can hold it, but...), is instant (doesn't take speed of light into account), etc. - e.g. it is more like tracing paths of "photon groups". When we're tracing paths of photon groups - then it should behave like a photon group (that means the path should reflect and refract splitting energies (meaning colors) into 2 paths - reflected and refracted).

Let's assume simple case - path goes towards reflective and refractive surface (behaving according to fresnel laws - F.e. its reflectivity = 0.3, refractivity 0.7 and (though unreal, but to keep it simple) absorbance = 0.0). We choose to reflect path - then we lost 70% of the energy of the path somewhere. Of course we could assume that next path would refract (and we "gained 70% back") and think that it would regulate the loss, but that won't work - because then we gave 2 * 100% of the energy to the system and got just 100% of the energy back.

Of course, assuming we want system where we get back all energy we've given into the system ("physically correct" - strong brackets around this one, as it is still not counting each single photon). Anyway you will most likely get exactly the same result using both, except - when you create two paths on that hit instead of one, your Fresnel-based surfaces will converge a lot sooner than when using probability functions to select if to reflect, or refract (thus you won't need to oversample them that much) - and thats important.

[quote]I'm aware the Fresnel equations apply for glass.[/quote]
Actually they apply for every material, not just glass. Even F.e. silver (0.370), or steel (2.485) have index of refractions that can be used in Fresnel equations (to calculate F.e. absorbtion coefficient of the material).
0

Share this post


Link to post
Share on other sites
[quote name='Vilem Otte' timestamp='1324060857' post='4894576']Wrong.
In physics the photon actually reflects with some energy and refracts with some energy
... Actually it can just reflect or refract when we're taking each single photon into account.[/quote]So... it's not wrong?
[quote]Let's assume simple case - path goes towards reflective and refractive surface (behaving according to fresnel laws - F.e. its reflectivity = 0.3, refractivity 0.7 and (though unreal, but to keep it simple) absorbance = 0.0). We choose to reflect path - then we lost 70% of the energy of the path somewhere. Of course we could assume that next path would refract (and we "gained 70% back") and think that it would regulate the loss, but that won't work - because then we gave 2 * 100% of the energy to the system and got just 100% of the energy back.[/quote]Assuming you're working with indivisible photons -- you haven't lost 70% of the energy, because when the photon is reflected, it does not lose 70% of it's energy. Likewise, if the photon is refracted, it does not lose 30% of it's energy either. So you put 2 * 100% energy in, and you get 2 * 100% energy out.

But yes, if working with groups of photons, then you'd have to create multiple exit paths, with the reflected paths having 30% of the input energy and the refracted paths having 70% of the input energy.
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1323992496' post='4894325'] [quote name='Geometrian' timestamp='1323989179' post='4894308']Suppose light is normal to a surface. Now, I change my viewing angle. If light has an equal probability of bouncing sideways as straight back, then the surface would appear brightest when I'm looking farthest from the normal (the surface takes up less area in my FOV[/quote]I don't follow your logic here - shouldn't that mean that it's the same brightness from any viewing angle, and that only the light/surface angle affects it's brightness?[/quote]. . . yes. That's what a diffuse surface does.

[quote name='Hodgman' timestamp='1323992496' post='4894325'][quote name='Vilem Otte' timestamp='1323972086' post='4894227']In physics the photon actually reflects with some energy and refracts with some energy (see. Fresnel equations for that). As Fresnel equation is defined as: "When light moves from one medium with refractive index n1 to another medium with refractive index n2, both reflection and refraction might occur[/quote]I was under the impression that a continuous wave of light will both reflect and refract, but each individual photon (which is one quanta of light) has to do one or the other? -- In the same way that a beam-splitter will send 50% of a laser's energy down each path, but is unable to split a [i]single [/i]photon ([i]which must take one path or the other[/i]).

Either way, isn't the end result the same when working with the probability of a quanta taking each path, compared to the percent of energy that takes each path?[/quote]Well, actually, single photons take [i]every[/i] path between point A and B, where A and B are points of measurement. This is why single photons can [i]interfere with themselves[/i] (e.g., double slit experiment).

[quote name='Hodgman' timestamp='1323992496' post='4894325' ][quote]Actually, he's sort of right. Path tracers deal in probabilities, because they only trace one photon's path. So you have to choose.[/quote]If I am wrong about that, then at the point of impact, your photon splits in two and you've got a refracted photon and a reflected photon... so I guess you could trace both paths from the split onwards?[/quote]In real life, yes. Single photons "split". But the point of a path tracer (as opposed to a ray tracer) that you [i]don't[/i] do that split because you'll get exponential growth of your ray tree.

[quote name='Hodgman' timestamp='1323992496' post='4894325' ][quote]I'm aware the Fresnel equations apply for glass. So, they work for other classes of materials too? For example, plastic sphere (classic Phong shading example) would choose whether to make a diffuse ray or a specular ray based on Fresnel equation probabilities?[/quote]Yeah, at work we take the IOR for any material and calculate the Fresnel reflectance at 0°, and call that value our "spec mask". We then use that value in Schlick's approximation to get the fresnel term for other angles.[/quote]Cool; thanks.[quote name='Vilem Otte' timestamp='1324060857' post='4894576'][quote]I'm aware the Fresnel equations apply for glass.[/quote]Actually they apply for every material, not just glass. Even F.e. silver (0.370), or steel (2.485) have index of refractions that can be used in Fresnel equations (to calculate F.e. absorbtion coefficient of the material).[/quote]Thanks,
0

Share this post


Link to post
Share on other sites
[quote name='Geometrian' timestamp='1324235174' post='4895053']. . . yes. That's what a diffuse surface does.[/quote]Hahah, sorry, I miscommunicated. What I meant was that [i]at a material level, [/i]giving all directions an equal probability does produce the same brightness from any viewing angle -- it doesn't make it brighter at glancing angles.

Using a BRDF of 1.0 ([i]or any other constant value[/i]) actually [i]does[/i] give you a lambertian/diffuse value.
[u]This is just an argument of terminology though[/u] -- it's arguing as to whether the cosine/[font="Courier New"]N.L[/font] term is part of the material ([i]BRDF[/i]) or part of the light/geometry interaction.

In the [url="http://en.wikipedia.org/wiki/Rendering_equation"]rendering equation[/url], the cosine term is [i]outside[/i] of the BRDF, so using a constant number does actually give you a diffuse/lambertian surface. In other words, every type of material has the cosine term applied to it, so using [font="Courier New"]1.0[/font] for your material actually gives you [font="Courier New"]blah * N.L * 1.0[/font].
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