3 ms·
Raytracing is surprisingly simple if you already know trigonometry. If you don't know Trig... you'll have to brush up on your math. But fundamentally, you proj
by dragontamer 6y ago
Raytracing is surprisingly simple if you already know trigonometry.
If you don't know Trig... you'll have to brush up on your math. But fundamentally, you project rays, you calculate if those rays hit an object (and if so, which object is "in front", and therefore hit first). And finally, you apply BSDF functions (math formulas created by artists that specify how light bounces off of objects) to calculate where the light bounced to.
That's it. The BSDF is an abstraction: there are many different models: one for metal, one for "specular" ("shiny" objects, like a marble), one for "diffuse" ("soft" objects like an egg), etc. etc. And an "uber BSDF" that kind of provides sliders for many different objects. (Invented by Disney: Roughness, Metalicness, Specularness, Diffuseness). But the BSDF itself is just an abstraction: where did the light bounce to? And different objects have different properties.
------
From there: making a FAST raytracer is the hard part. What kind of data-structures are needed to calculate intersections more quickly? Understanding the hardware (SIMD-cores, maybe even GPUs) to calculate BSDFs in parallel. Etc. etc. Lots of little things to learn and ultimately complicating the thing.
A professional raytracer would also have special code for the different kinds of objects in the scene.
True random path tracing takes too long. Biased techniques and quasi-random paths can make smoother images with less effort. Unbiased techniques shy away from such "theoretically suboptimal" optimizations. Denoising. Multithreaded, multi-computer, multi-GPU support. The feature sets goes on-and-on-and-on.
But if you want to just make "a" raytracer, without any care in the world about how fast (or slow) it is, then you easily can do that in one weekend. So give it a shot if you like.
-----------
https://www.kevinbeason.com/smallpt/ https://www.kevinbeason.com/smallpt/
They brute-force an all-to-all check against all objects. There's no oct-tree partitioning or BVH trees. The only shape supported are spheres of varying sizes (no squares, no triangles, no cubes. Just spheres). There are only three BSDF functions implemented (specular "hard and shiny", diffuse "soft and matte", and glass). This tiny program is inefficient as all heck, but hey... 99 lines of code is pretty spiffy. That's all you really need for a raytracer.
- peapicker 6y agoMore Linear Algebra plus Trig... trig won't teach you eigenvetors, normals, etc.
- banachtarski 6y agoNormals are part of trigonometry. Eigenvectors won't show up in an elementary path/ray tracer. You need the most barebone understanding of LA for xform composition/application.
- dragontamer 6y agoThe way I see it: the linear algebra parts are just optimizations. You can probably??? write a raytracer using Trig alone: it just means that you'll be using sin/cos on angles instead of "short-cutting" with a dot-product to determine normal vectors. Hmmm... well... maybe the concept of dot-products and orthogonal vectors will help. So Linear Algebra probably will make things easier if you studied that too... but I still think its kinda optional.
- Arelius 6y agoCan you even get the angle between two three dimensional vectors without using some sort of vector product and venturing into linear algebra territory?
- dragontamer 6y agoYeah. Its just harder using Trig: SOH CAH TOA. tan(angle) = opposite-leg / adjacent-leg. arctan(opposite-leg / adjacent-leg) == angle. The more I do this, the more I realize that the linear-algebra approach might be easier... but the Trig approach can certainly do what you are asking for. I mean, I recognize that I'm just "reinventing cross-product" here to get the length of opposite-leg and the direction of adjacent-leg. But it does seem feasible to do all of these things in Trigonometry alone. A little bit of Linear algebra (cross product creates an orthogonal vector) would definitely make this problem easier.
- Arelius 6y agoOk, hmm I'm still a bit lost though, those identities work on a right triangle, but how do you construct a right triangle between two 3D vectors A, and B?
- Arelius 6y agoMostly nitpicks: > math formulas created by artists Rarely do artists create the BSDF, generally a general model BSDF is provided by an engineer or scientest, and the parameterization is tweaked by an artist. > that specify how light bounces off of objects Technically a BSDF generalizes all light interaction with medium. a BRDF, is the function that describes how light bounces (reflects, the R in BRDF) off of objects, which is sufficent for raytracing solid, non transparent/translucent objects. > And an "uber BSDF" that kind of provides sliders for many different objects. (Invented by Disney The idea of an uber BSDF wasn't "Invented by Disney" Brent Burley did develop Disney's principled BRDF at Disney, but it builds on a long foundation of uber BRDFs at VFX studios. He did popularize, if not invent the idea of a metalness map. It was however already possible to represent metals in existing uber shaders by just using a standard full color specular lobe. > Understanding the hardware (SIMD-cores, maybe even GPUs) I'd add understanding memory cache hierarchies, and their affect on performance highest among those.
- mattkrause 6y agoThere is even some crazy work using micro-CT scans to develop highly realistic scattering models of materials. https://www.cs.cornell.edu/~kb/publications/SIG11CT.pdf https://www.cs.cornell.edu/~kb/publications/SIG11CT.pdf A friend worked on a similar project to predict bird (and dinosaur) coloration from the structure of their feathers, which is just wild!
- Arelius 6y agoThat's really cool. I hadn't seen it, but I'm not surprised to see Wenzel Jakob's name on the paper.
- dahart 6y ago> He did popularize, if not invent the idea of a metalness map. I don’t know what the precise differences are, but FWIW we had an uber shader that we called “uber shader”, with a metalness map (a texture driven metallic BRDF lobe, not just full color specular) at PDI in the late 1990’s, written by Sing Choong Foo (who worked on the Lafortune model). I’d guess Pixar and other studios had one too by that time.
- brundolf 6y agoThis is what made it such a fun project for me. I don't enjoy really complex math, but I love optimizing and refactoring and making things more modular and achieving new visual effects. So I was able to just drop in a couple of key equations from the internet, and I was off to the races and got many hours of enjoyment from the infinite tail of possible improvements. Plus, you get really satisfying output really early on ("in a weekend"), which is a big motivator for me to keep going.
- mattkrause 6y agoThe same author also has "Ray Tracing: The Next Week", which introduces a lot of the missing features you mention. Chapter 3 introduces BVHs, Chapters 4-5 add more surfaces, and Chapter 7 adds cubes. There's a third book ("Ray Tracing: The Rest of Your Life") that tackles more sophisticated approaches like importance sampling.
- blackrock 6y agoInteresting. The angle of incidence equals the angle of reflection.