**1**

# Choose Path in Path Tracing

###
#1
Crossbones+ - Reputation: **1717**

Posted 13 December 2011 - 07:39 PM

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

###
#2
Members - Reputation: **748**

Posted 14 December 2011 - 05:56 AM

**probabilities**as I haven't done it myself yet

###
#3
Moderators - Reputation: **42033**

Posted 15 December 2011 - 02:00 AM

The diffuse/lambertian model assumes that when a photon strikes the material, it is

*equally*likely to exit in

*any*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 (

*which means it's not discoloured by the surface*) -- this is what we call a specular reflection.

The other possibility (

*if it isn't reflected*) is that the photon is refracted

**into**the surface. When this happens, the photon will bounce around inside the material, losing energy (

*"picking up colour"*) 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 (

*it's "diffuse colour" / "albedo"*).

In physics, you would use a material's

**i**ndex

**o**f

**r**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 (

*where specMask ~= ((IOR-1)^2)/((IOR+1)^2)*). 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 (

*which corresponds to an IOR value of 5.8, which would be a highly exotic material --*).

**much**shinier than diamondReal-world materials typically have spec-mask values between 0.01 and 0.2.

###
#4
Crossbones+ - Reputation: **2089**

Posted 15 December 2011 - 12:01 PM

In physics, you would use a material's index of refraction to tell you how likely a photon is to be reflected vs refracted.

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.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

###
#5
Crossbones+ - Reputation: **1717**

Posted 15 December 2011 - 04:46 PM

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.The diffuse/lambertian model assumes that when a photon strikes the material, it is

equallylikely to exit inanydirection -- 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.

Actually, he's sort of right. Path tracers deal in probabilities, because they only trace one photon's path. So you have to choose. TheIn physics, you would use a material's index of refraction to tell you how likely a photon is to be reflected vs refracted.

Wrong.

In physics the photon actually reflects with some energy and refracts with some energy (see. Fresnel equations for that).

*way*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

###
#6
Moderators - Reputation: **42033**

Posted 15 December 2011 - 05:41 PM

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 aIn 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

*single*photon (

*which must take one path or the other*).

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?

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?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

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.

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?Actually, he's sort of right. Path tracers deal in probabilities, because they only trace one photon's path. So you have to choose.

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.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?

###
#7
Crossbones+ - Reputation: **2089**

Posted 16 December 2011 - 12:40 PM

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).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?

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.

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).I'm aware the Fresnel equations apply for glass.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

###
#8
Moderators - Reputation: **42033**

Posted 16 December 2011 - 11:15 PM

So... it's not wrong?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.

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.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.

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.

###
#9
Crossbones+ - Reputation: **1717**

Posted 18 December 2011 - 01:06 PM

. . . yes. That's what a diffuse surface does.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?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

Well, actually, single photons takeI 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 aIn 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

singlephoton (which must take one path or the other).

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?

*every*path between point A and B, where A and B are points of measurement. This is why single photons can

*interfere with themselves*(e.g., double slit experiment).

In real life, yes. Single photons "split". But the point of a path tracer (as opposed to a ray tracer) that youIf 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?Actually, he's sort of right. Path tracers deal in probabilities, because they only trace one photon's path. So you have to choose.

*don't*do that split because you'll get exponential growth of your ray tree.

Cool; thanks.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.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,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).I'm aware the Fresnel equations apply for glass.

###
#10
Moderators - Reputation: **42033**

Posted 18 December 2011 - 06:12 PM

Hahah, sorry, I miscommunicated. What I meant was that. . . yes. That's what a diffuse surface does.

*at a material level,*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 (

*or any other constant value*) actually

*does*give you a lambertian/diffuse value.

This is just an argument of terminology though -- it's arguing as to whether the cosine/N.L term is part of the material (

*BRDF*) or part of the light/geometry interaction.

In the rendering equation, the cosine term is

*outside*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 1.0 for your material actually gives you blah * N.L * 1.0.