TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Writing a Raytracer in Rust – Part 1

177 pointsby miqktabout 8 years ago

8 comments

K0nservabout 8 years ago
I too have been writing a raytracer in Rust[0] recently. I tend to use raytracers as my go to project when learning a new language, especially those that are OOP, since it touches a few different areas that are commo such as:<p>+ Protocols&#x2F;traits&#x2F;interfaces and using that for polymorphishm, think intersectable&#x2F;primitve types.<p>+ It typicall involves both understanding heap and stack allocated memory in the language as well as understanding the general memory model to build scene graphs etc<p>+ Building a small linear algebra library usually touches things like low level operations and performance operations as well as operator overloading if the language supports it.<p>+ Writing images to disks via pixel buffers<p>Primarily though I think raytracers are very fun projects because you can produce nice looking results quickly which I find helps with motivation and passion for the project. I&#x27;m pretty pleased with some of my renders already[1]<p>0: <a href="https:&#x2F;&#x2F;github.com&#x2F;k0nserv&#x2F;rusttracer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;k0nserv&#x2F;rusttracer</a><p>1: <a href="https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;k0nserv&#x2F;rusttracer&#x2F;master&#x2F;docs&#x2F;bit-later-render.png" rel="nofollow">https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;k0nserv&#x2F;rusttracer&#x2F;master&#x2F;...</a>
评论 #13995983 未加载
评论 #13994962 未加载
评论 #13994327 未加载
gonewestabout 8 years ago
Peter Shirley&#x27;s &quot;Raytracing in One Weekend&quot; e-books are a nice resource for people who want to do this themselves from scratch.
评论 #13993378 未加载
评论 #13993359 未加载
评论 #13993569 未加载
izymabout 8 years ago
&gt; raytracing an image takes much longer than the polygon-based rendering done by most game engines.<p>Minor nitpick, but it has nothing to do with the fact that it renders polygons. Ray tracing can also render polygons. More precisely, game engines use rasterization which works by projecting triangles onto the screen rather than tracing rays through the screen.
评论 #13993750 未加载
Patient0about 8 years ago
I didn&#x27;t follow this bit (from Part 2):<p>&quot;This requires a bit more geometry. Recall from last time that we detect an intersection by constructing a right triangle between the camera origin and the center of the sphere. We can calculate the distance between the center of the sphere and the camera, and the distance between the camera and the right angle of our triangle. From there, we can use Pythagoras’ Theorem to calculate the length of the opposite side of the triangle. If the length is greater than the radius of the sphere, there is no intersection.&quot;<p>The two sides he describes have the camera in common - so the &quot;opposite&quot; side of that triangle is the line from the center of the sphere to the right angle - I don&#x27;t see how this helps....<p>Edit: ok I finally get it but I think he should just label some of these lengths on the diagram with letters (a,b,c etc) and then just show how they are related by stating Pythagoras theorem explicitly...
mijoharasabout 8 years ago
Is anyone able to shed any light on the FOV correction? I&#x27;m not sure I understand exactly what is happening there.
评论 #13995586 未加载
评论 #13997958 未加载
santaclausabout 8 years ago
&gt; Despite that, it also happens to be the simplest way to render 3D images.<p>I&#x27;m not sure I would claim that -- with a line drawing routine in hand (a for loop), you can have 3D perspective renderings of objects with a few matrix vector multiplies.
评论 #13997552 未加载
kobeyaabout 8 years ago
Pixar&#x27;s RenderMan is not a ray tracer, btw.
评论 #13995505 未加载
saosebastiaoabout 8 years ago
It&#x27;s be really cool if someone wanted to port this raytracer[0] to Rust and compare benchmarks.<p>[0] <a href="http:&#x2F;&#x2F;www.ffconsultancy.com&#x2F;languages&#x2F;ray_tracer&#x2F;benchmark.html" rel="nofollow">http:&#x2F;&#x2F;www.ffconsultancy.com&#x2F;languages&#x2F;ray_tracer&#x2F;benchmark....</a>