12 ms·
When I wrote my ray tracer, I set up a simple websocket server to stream pixels to a canvas element.[1] it’s a trivial way to do this without a ton of GUI code.
by fiddlerwoaroof 5y ago
When I wrote my ray tracer, I set up a simple websocket server to stream pixels to a canvas element.[1] it’s a trivial way to do this without a ton of GUI code.
[1]: https://github.com/fiddlerwoaroof/lisp-sandbox/blob/master/raytracing_in_one_weekend/canvas-server.lisp https://github.com/fiddlerwoaroof/lisp-sandbox/blob/master/r...
- shmerl 5y agoInteresting. I'd guess you could do it without GUI, but you still need access to something like WSI / Vulkan to actually get to the screen if you want to do it directly.
- a_e_k 5y agoIn the decade I spent working on RenderMan at Pixar, I learned just how immensely useful it was to have an image viewer running in a separate process talking to the renderer over a socket or pipe. (The Image Tool, or "It" is RenderMan's viewer.) Having it stay up even if you kill the render or it crashes for some reason and being able to flip back and forth to easily compare test renders across recompiles is game changing. If I were to start writing a new renderer, the first thing I'd do is to hook it up to an external image viewer over some protocol. These days, I find myself liking TEV (https://github.com/Tom94/tev https://github.com/Tom94/tev) a lot as a simple open-source image viewer that supports this and most other basic features that I'd want. See the links in the README for Python and Rust implementations of its protocol.
- deleted 5y ago[deleted]
- shmerl 5y agoYou can probably feed something to mpv that way too.
- tekknolagi 5y agoChris Wellons did something similar: https://nullprogram.com/blog/2017/11/03/ https://nullprogram.com/blog/2017/11/03/
- shmerl 5y agoYeah, that's exactly what I thought mpv could do. Good to see a real example.
- corysama 5y ago“Minimal code to put pixels on the screen?” is a question I’ve seen often enough that I’ve made a little gist to link whenever it comes up. https://gist.github.com/CoryBloyd/6725bb78323bb1157ff8d4175d42d789 https://gist.github.com/CoryBloyd/6725bb78323bb1157ff8d4175d... It requires https://www.libsdl.org/ https://www.libsdl.org/ But, making a window and putting some pixels in it, on all the world’s varied platforms, is the premier feature of that lib.
- shmerl 5y agoYeah, I figured you could use SDL. But probably more interesting to do it more directly with Rust and some WSI functions to get the needed surface (though it would be a lot more code).
- signa11 5y agowith multithreaded rendering, is it possible to use SDL ? anecdotally, in my cpu based ray-tracers (i have one in c++ and python so far) , i have found that SDL based rendering causes noticeable slowdowns to become quite useless after the initial novelty wears off.
- corysama 5y agoI've checked the code under the hood of SDL and it does pretty much the best you can do for fast uploads of an image from the CPU to the GPU. My CPU-based ray tracer uses the code I linked. SDL_LockTexture, go wide with threads writing into the locked buffer, SDL_UnlockTexture. If I skip the actual ray tracing, I get 1400 FPS uploading a 1024x1024 image.
- svdree 5y agoMiniFB is also nice for this purpose: https://github.com/emoon/minifb https://github.com/emoon/minifb
- boomlinde 5y agoWhen I want a quick way to get pixels on the screen I just print a PPM image to stdout and pipe my program into `feh -`. There are two PPM formats, both very simple: http://netpbm.sourceforge.net/doc/ppm.html http://netpbm.sourceforge.net/doc/ppm.html For example, the header printf("P6\n%lu %lu\n255\n", width, height); followed by width*height triplets of raw bytes representing the RGB values of each pixel.