Hacker News new | past | comments | ask | show | jobs | submit login
Cray - A Clojure Ray Tracer (code.google.com)
53 points by fogus on Oct 7, 2009 | hide | past | favorite | 15 comments



They should have called it clay (you know, model stuff, like with clay ;); the first thing I thought of was http://www.cray.com supercomputers. Maybe that was intentional.

After browsing the source, it seems they are using Java2D primitives, specifically BufferedImage to do textures and shaders. I wonder if this project could use JOGL bindings...

EDIT: btw, I meant to say that this looks pretty badass


> I wonder if this project could use JOGL bindings...

It wouldn't make much sense. Opengl is for realtime 3d graphics. Here you just output the final rendered image, which is a bitmap.


Right, although there are options to combine the two.

Shader language can be used to write raytracers running entirely on the GPU, rendering the output to merely two textured triangles streched over the screen.

However as we are talking about Clojure, not shader languages, an alternative way would be offloading some of the weight lifting to OpenGL, for example by calculating visibility using the videocard's z-buffers or creating shadow maps by rendering the scene from the lights' viewpoint into shadow buffers and using the results in the raytracer.


Ah, thanks, that makes sense. What I was thinking of was the many times I've crashed java by trying to load/render decently sized images in memory (something about how heap space takes awhile to dynamically allocate). You could specify initial heap size with a command line flag, but it was hacky and I had a hard time getting it to work consistently.


I'll take anything over "clj-ray" or "rayjure."


why not "craj" like clojure does "cons" "conj" :)


Looking at it made me curious. Is there any ray tracer that includes the effects of gravity when tracing the rays? You would have to model in terms of solids and give materials densities.

It would be a really interesting project.


Unless you were planning on ray-tracing a scene near a black hole, what good would this be?


This is _hacker_ news. It doesn't need to be good for something as long as it's cool.


How would you know it was working?


Thanks for giving me the laugh of the day! :D


"As you can see, adding this feature slows down the rendering by a factor of 4, but I think it's a small price to pay for the added accuracy, even if you can't see it."


There's a sample image below which it says "First results, 83 lines of code." Is that the total number of source lines in that version of the raytracer? Wow! I mean, the sample doesn't look especially beautiful, but 83!! WOW!!


Hi there, I wrote this ray tracer. Thanks to everyone for your positive comments. I don't have a copy of that version any more, but it was 83 lines from start to finish, including the scene description and dealing with Java to display the image. No AA or multi-CPU support, but point-light sources and reflection, and a little general-purpose vector library.

There was probably more code on each line than is typical Lisp style, though.

There are some techniques in the code for getting good performance (as good as Java at least) for mathematical routines - the JVM is the limiting factor rather than Clojure.

I hope it helps to show that Clojure is a practical language, since the concepts in it are going to be important in the near future. Also, if anyone is impressed by shiny spheres and wants to talk of entrepreneurial things, email's on the project page. :)


I'm pretty sure that's the number of lines in the rendering code, which is interpreted by the (many-LOC) raytracer.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: