5 ms·
This is a really great book! I went through the first one and implemented it in Rust. Was a great learning experience both in ray tracing and in Rust (my first
by aprdm 6y ago
This is a really great book! I went through the first one and implemented it in Rust. Was a great learning experience both in ray tracing and in Rust (my first ""real"" project with it).
I really recommend! Much cooler (IMO) then doing another TODO list app. I also recommend going to google to more deeply understand some of the algebra concepts that are used (since they aren't really explained in a deeper level and assume you already know).
- Tempest1981 6y agoNaive question: how do you draw graphics in Rust? (Or "go"?) Some wrapper on top of OpenGL?
- justinsaccount 6y agoeasiest way: https://en.wikipedia.org/wiki/Netpbm https://en.wikipedia.org/wiki/Netpbm
- aprdm 6y agoIn this case you just do it from scratch :) I didn't use any external libraries. You generate a PPM image https://en.wikipedia.org/wiki/Netpbm https://en.wikipedia.org/wiki/Netpbm and then open the image from anything that opens a ppm image (open in mac works)
- siddboots 6y agoYou can do that. Luminance and glium are two examples. I'm not exactly sure what is state of the art though. As a casual observer, it seems that making a properly typed opengl wrapper is apparently quite hard, and the solution space hasn't matured yet.
- outworlder 6y ago> Naive question: how do you draw graphics in Rust? (Or "go"?) Some wrapper on top of OpenGL? The beauty of raytracers is that you don't need any graphics support at all. The output of a raytracer is a frame. The simplest way is just an array. Compute your color values, save them to array positions. Of course, you eventually will want to see the result. You can save an image to a file then. One of the simplest formats is PPM. The PPM format requires a header, afterwards you just push RGB values. Which means you don't even need a library (http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file#C http://rosettacode.org/wiki/Bitmap/Write_a_PPM_file#C) If your question is not about raytracers, but more general, there's countless ways. Are you drawing in 2D (and not a game)? You can use the OS's own native functions for this if you are brave. Since Rust can call C libraries, this should work. Draw in memory, then "blit"(i.e. copy it over) to the appropriate buffer. Under Windows, you could use the Win32 API directly if you don't value your time :) Alternatively, you can use a library that will make your work much simpler. There are many cross platform UI libraries, some of them with Rust bindings. And some Rust-specific ones too Check https://www.areweguiyet.com/ https://www.areweguiyet.com/ If you don't care about GUI controls and are mostly drawing images (like in games!), there's SDL. That will take care of most of your needs. See also: https://arewegameyet.rs/ https://arewegameyet.rs/ If you are doing it in 3D, you could use OpenGL. I've done that with my raytracer back in university. Same principle applied: I would generate a scene in memory, then copy to a texture and display it. Geometry was just two triangles. You could do a similar thing.
- lambda_obrien 6y agoThanks for taking the time to answer that person's question with such great detail and also talking about several levels. It was a joy to read.
- lazypenguin 6y agoI recommend this crate if ease-of-use trumps the performance of using graphics acceleration: https://github.com/emoon/rust_minifb https://github.com/emoon/rust_minifb
- grovesNL 6y agoThere are lots of options for graphics in Rust, so it's really just a choice of which graphics API you'd like to use or learn more about. (full disclosure: I contribute to some of these crates) For example, there is an implementation of WebGPU (https://github.com/gfx-rs/wgpu-rs https://github.com/gfx-rs/wgpu-rs) that can run both inside and outside of the browser that has been growing in popularity lately. There are also bindings for Vulkan (ash, erupt), D3D12 (d3d12-rs), Metal (metal-rs), cross-platform abstractions at various levels (gfx-hal, wgpu), OpenGL (glow, glium), etc. It's also possible to simply render graphics to an image (a pretty common approach for Raytracing in One Weekend) or blit pixels onto a window surface.
- pjmlp 6y agoFor Go have a look at https://ebiten.org/ https://ebiten.org/
- decompiled_dev 6y agoI also went through this as my first project in Rust. I thought it was a good first project.
- Pelic4n 6y agoIt was for me too ! I ended up doing a lot more maths than writing code, so it wasn't that good of a project.