float k = 1 - eta * eta * (1 - cosi * cosi); Nobody will ever see your Dropbox folder and your amazing designs, ideas, and work in progress remain buried in your computer! Wouldn’t it be better to show your works to the public and attract new clients? }, void fresnel(const Vec3f &I, const Vec3f &N, const float &ior, float &kr) { There are a couple of details we need to take care of though in the actual implementation of this equation. if (trace(orig, dir, objects, isect)) { There is an option in vray reflection settings for fresnel ior, you can check this on an you can control the strength of reflections at the grazing angle (as the incidence angle approaches 90 degrees away from the camera target (which would be 0 degrees directly in front of the camera). The angle of incidence increases with the distance as shown in figure 16, and we know that the ratio of reflection vs. transmission increases with the angle of incidence. In figure 3, you can see the reflection of three rays with distinct incident directions and distinct colors. ... Parallel – Specifies the color for the texture when viewed at a grazing angle. We can see the reflection of the sun when the angle of the wave with respect to the viewer is right but because the shape of the wave changes rapidly the reflection can appear as well as disappear quickly (glittering effect). } By opposition we say that diffuse reflections are view independent because they don't vary with the angle of view as explained in the chapter on Lambertian material. } if (mesh3 != nullptr) { else If you look at the reflection of a static object in the mirror and change direction, you will see that the image of that object changes. In the case of reflection we need to push the point on the same side of the surface hit by the incident ray, and in the case of refraction, the points need to be pushed inward (figure 17). Figure 16: the ratio of reflected light increases as the angle between the view direction and the surface normal increases. And since by the principle of the conservation of energy, the amount of reflected light plus the amount of refracted light is necessary equal to the total amount of incident light, you can deduce that the amount of reflected light increases when the angle of incidence increases, up to 100% as the angle gets closer to 90 degrees. Though for most scenes using a depth much greater than 4 or 5 generally doesn't make much of visual difference. The terms \(\cos\theta_1\) and \(\cos\theta_2\) are the angle of incidence and refraction respectively. It's only when very complex transparent surfaces are rendered (such as water splashes) that using a depth much greater than 5 is necessarily for producing images that are similar to the real thing. { Keep in mind that the result of \(\cos(\theta_1\)) also needs to be positive. The attenuated the reflection to more easily differentiate the plane from the background. Some people don't feel that this image is actually photo-real. If you do not simulate the internal reflections though, you get an image like the one of the right, which might seem visual more real. If you look at the picture of the lake with some mountains in the background and pebbles in the foreground at the beginning of this chapter, you can see that the reflection seems to increase with distance. We can just set \(F_R\) to 1. hitPoint + bias : hitPoint - bias; if (cosi > 0) { std::swap(etai, etat); } Vec3f reflect(const Vec3f &I, const Vec3f &N) Note that reflection (as many of the other shading effect we will study from now on) can be perfectly simulated with the ray-tracing algorithm. Nrefr = -N; default: Looking at objects through a glass ball can inverse the image of the objects seen through the ball as shown in figure 9. if (kr < 1) { else { Pure water is an electric insulator indeed. if (NdotI < 0) { We also added an ior member variable to the object class to store the object index of refraction: Figure 17: because of numerical precision issues, the intersection point may actually be under the surface of the object the ray has hit. This is not totally wrong, as mirror like surfaces generally never reflect 100% of the incident light anyway. First, you can see that the vector \(T\) the transmission ray that we want to build, is the sum of the vector \(A\) and \(B\). Keep in mind that another reason for putting a cap on the recursion depth is also because ray-tracing is expensive. If inside the object and leaving it, we then need to flip the normal direction to compute the refraction direction. The amount of reflected vs. refracted light can be computed using what we call the Fresnel equations. It is the projection of the vector \(I\) or \(R\) onto the vector \(N\). Light can pass through them, a phenomenon we call transmission and they can reflect light at the same time. This is the principle of Fresnel. We look at a different part of the object. Figure 15: the ratio of reflected light increases as the angle between the view direction and the surface normal increases. Suffice to know that we need to compute the ratio of reflected light for these two waves using two different equations (one for each type of wave) and average the results to find the solution. How much light they reflect vs the amount they transmit actually depends on the angle of incidence. To normalise it, you just need to divide it by \(\sin(\theta_1\)). Though one thing you may want to know before we close this chapter, is that metallic objects too reflect light. Let's start with reflection which is almost the simplest form of light-matter interaction. Blend Amount–  Takes each pixel from the top layer if present. \(A\) and \(B\) can easily be computed using the following two equations: We already know about \(N\) but what about vector \(M\)? This is already a long chapter in which we introduced many fondamental concepts from shading. In this particular piece of code, ior is the refraction index of the material of the physical object the ray has either hit or is about to leave (glass, water, etc.). kr = 1; While the light beams intersects the surface in the same exact point on the surface, the observer will only see the reflection of the ray in the middle (the ray with the orange color). Thus we see through the water more clearly than when we look in the distance. return I - 2 * dotProduct(I, N) * N; float sint = etai / etat * sqrtf(std::max(0.f, 1 - cosi * cosi)); The term \(I + C\) gives a vector perpendicular to \(N\) or if you prefer to say it differently, tangent to the surface. Figure 2: computing the reflection direction can be done using simple geometry. Vec3f Nrefr = N; }, Vec3f refract(const Vec3f &I, const Vec3f &N, const float &ior) float Rs = ((etat * cosi) - (etai * cost)) / ((etat * cosi) + (etai * cost)); Reflection is the result of what happens to a photon, or an incident light beam if you are not familiar with the concept of photon, when it hits the surface of a reflective surface such as glass, water, or a sheet of aluminium for example. The pen is rendered using a flat shading model. Of course, introducing this cap, means that our produced image will deviate from reality. If we denote the speed of light in this medium \(v\), then the index of refraction is simply the ratio of \(c\) over \(v\): Figure 9: effect of refraction (not the inverted image of the background scene in the glass ball). hitColor += 0.8 * castRay(hitPoint + hitNormal * options.bias, R, objects, lights, options, depth + 1);