MRay - Minimalist Raytracing in Unity

In keeping with my spirit of not doing anything useful… :roll:

I’ve been playing around with Unity and made a very simple raytracer. Right now it is beyond simple—it calculates the normal of the hit surface compared to the light direction, which is defined in the script; it doesn’t currently use external lights at all. It does randomly generate cubes and save the output to a png file, for what that’s worth.

Maybe this will go somewhere, maybe not. It sure was fun though :smile:

A couple pics:
5000 cubes:

10000 cubes:

Note: I almost ended a line with a semicolon back there… Perhaps I’ve been coding too much.

66071–2440–$mray_v01_811.unitypackage (9.13 KB)

I’ve had this idea brewing in my head for a long long time and basically had it almost written in psuedocode on some surface in the back of my brain. Your post poked it and it fell out onto my computer through my fingers.

http://forestjohnson.blogspot.com/2008/02/real-time-raytracing-p.html

Nothing magical here, its very simple and very slow. Sorry to hijack your thread…

I’ll look into making a simple realtime version. Since I can’t use GL to draw to the screen, I think I’ll just put a plane with the renderTarget on it and remove the mesh collider. I’ll see what happens…

You can download the one I did at my blog post. It is completely indie friendly, I use a GUI.DrawTexture() to get the rendered result onscreen.

The link doesn’t work.

Oh, sorry about that. It should work now.

Seems like Unity changes from using .unitypackage to .unityPackage every time I try to do this. Also, I just descovered that safari likes to try to display .unitypackage files as characters, grrrrr.

Very cool stuff. I wish I had a use for this because it would be a lot of fun to play with! :smile:

…well a great use is to render reflections in real time!!!
I really hope you take this further.
At the moment there is not an easy way to get things reflected from irregular surfaces.
Either you have a flat plane or you just use cube mapping.
Your plugin could offer the possibility to have real time reflections…
way too cool!
thanks!
G.

:shock:

Well, not really considering how slow it is. Mixing raytracing and rasterizing in a single render is a bit crazy, too. But you can get the next best thing using only raster techniques by using Camera.RenderToCubemap();

Now, if there was a way to get simple raytracing on the GPU that was fast, reliable and looked “generally the same” as a rasterized render, that would be cool because true reflections and refractions would be possible.

well, the limitation with that, I guess, is the parallax error…
do you think this could be solved?

What do you mean by parallax error?

I meant that if you use an infinite distant cube map for the reflection this may be ok, but if the object that is reflected is too close, than the approximation will not be accurate because of the parallax error…

It’ s little like:
looking north from a point and seeing an house.
If you move a little East and you do not see anymore this house you cannot use the same cubemap with the house in it…

G.

Here’s a small update. It’s now realtime and in a webplayer. It’s really small though, and doesn’t really do anything special. Cool though :smile:

Just a heads up: I tried this fullscreen on my iMac running Firefox and it ran extremely slowly (maybe 1 frame per minute) and crashed Firefox. :shock:

It basically runs at full res right now, sorry. Just try not to run it in fullscreen. :stuck_out_tongue:

Very cool. :slight_smile:

I took this as a dare to see how powerful my iMac was. I went fullscreen and was probably getting 3 or 4 seconds per frame. I exited fullscreen mode and it appeared to be working fine. Closed the tab and BAM, out goes Firefox. :stuck_out_tongue:

Teaser pic time :smile:
Ambient Occlusion:


Radiosity:

On this note, how would I go about generating a grid of evenly distributed ray directions? Example: (0.5,1,0.5),(-0.5,1,0.5),(-0.5,1,0.5),(-0.5,1,-0.5)… Any ideas?

DannyL, thanks for posting your raytracer, it’s been very helpful.

Any chance you can fix the broken links to your radiosity and ambient occlusion? I’m actually working on Instant Radiosity at the moment, and I’d like to see your results. I will post mine as soon as I get something to show.

Sure–go wild: http://dl-games.site50.net/mrayscreens/
A copy of the files are also attached since that link will almost inevitably break. :wink:

102280–3928–$mrayscreens_768.zip (1.34 MB)