Calculate shading through a transparent surface

In ray tracing, I want to calculate the shading for the point where my ray hit. I "draw" lines to all light sources and check if they are blocked by objects or not. If they are not blocked, I calculate the light intensity according to their intensity and the degree between the โ€œhit beamโ€ and the normal surface.

But what if the light is blocked by a partially transparent surface? Then the light should detect the point, but its intensity and color depends on the color of the surface through which it passes, and in order to calculate that I need to trace the rays to pass the light ray (actually for two points, one of the input and one of the exits), and it will be very expensive, and possibly also almost endless (I think that with the right location of the light sources and surfaces you could put the tracer in an almost endless loop for each hit).

Is there a quick and good way to get closer to color, or should I just take the color of the surface as light color and transparency as intensity?

+8
raytracing graphics shader
source share
2 answers

You do not need to do ray tracing from entry and exit. Think about how light strikes these moments. A ray of light that hits a translucent surface at an angle different from that that hits your target will not affect the color of the light that hits your target.

+ * + + * + + * + + * + ---------- | +*+ | | + * + | | + * + | ---------- + * + * * ------- 

This suggests, of course, that there is no refraction in the material.

Now, if you want to extend the ray tracer to something more advanced, for example, trace tracing, you will need to consider the light that bounces off the translucent object and falls into your last object, but for the beam indicator that you do, you do not need to worry about it .

For a translucent object, I would model a decrease in light intensity as a linear function of distance (most objects in the real world strictly adhere to this assumption). If you model the light as having RGB components (not physically realistic ...), you reduce each component in proportion to this component value inside the object.

If you want to really advance with what light does during an object, then you will need to switch to subsurface scattering (the reason why milk in a glass does not look like a white solid and why people are so hard to model in CGI).

EDIT: The phenomenon that you mention about how easy and quick to jump back and forth, and using a variety of calculations, is what behaves in a real light. Currently, advanced rendering tools cannot integrate all of these light components, and instead randomly displays the distribution of light. The more samples, the closer the image converges to realistic, and the closer the integration of light becomes its true value. This is called monte carlo rendering. Traceroute, bidirectional traceroute and metropolitan traffic light are all monte carlo algorithms that completely mimic light transport. Each algorithm, given sufficient time, will converge to the same final image, however, some of them are more efficient than others. (See the Wikipedia path trace . At the bottom of the article, the image is better than the one I tried to draw.)

+3
source share

If you need surfaces that can do both proper shading and transparency, the simplest thing is to ignore regular shading for shadow rays: for lighting purposes, use only the filtering attributes of transparent surfaces. This avoids the potentially endless lighting described by you.

Please note that there is a good way of approaching the endless rays of trees, which follows the colorful name "Russian Roulette": when any branch of a tree becomes too inconsequential, make an arbitrary choice whether to prune it. Branches are cut off with probability P and add zero to the result (they are โ€œdeadโ€ and do not need to be calculated). The surviving branches (โ€œwinnersโ€) receive their contribution multiplied by 1/(1-P) , so that the approximation obtained is on average correct.

Russian roulette is the Monte Carlo method; You might want to take a look at the Monte Carlo ray tracing and other global lighting methods.

0
source share

Source: https://habr.com/ru/post/650633/


All Articles