Jump to content


Photo

GM Ray Tracer (Multi-threaded version)


  • Please log in to reply
45 replies to this topic

#1 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 19 February 2011 - 12:06 AM

Here is a sample image that I rendered:
Posted Image

You may download the GMK here: Game Maker Ray Tracer.gmk (GM 8.0 Pro required)
Or download the EXE here: Game Maker Ray Tracer.exe
(press "S" to save a screen shot and feel free to post your creations)

 
First, this project was originally created by x-Amnesia-x and is available at http://gmc.yoyogames...howtopic=448872.

I did not make the original ray tracing code, but significantly modified his project. My current changes include:
  • The rendering code:
    • All rendering is threaded. This is accomplished by alternating lines between each thread which allows the work to be more evenly distributed. This results in faster rendering times (for multi-core CPUs), as all CPU cores are being fully utilized, not just one.
    • You can choose the number of threads with which to render. The most efficient choice would be the number of CPU cores in your computer.
    • Spotlights can have soft edges, so they blend out nicely.
    • Refraction works properly. It doesn't give a "negative square root" error, even if you use an "impossible" refraction index (less than 1 or negative for metamaterials).
    • "Smart" anti-aliasing only sub-samples pixels that have a noticeable color difference from their adjacent pixels. This smooths sharp edges but doesn't waste time doing this to the entire image, where it would be unnecessary.
    • Depth of field with Gaussian blur makes objects that are very close or far away from the camera appear blurry and out of focus, like they would in real life.
    • Hard and soft-edged shadows may be realistically modeled. This is accomplished by creating 3D spherical light sources (rather than point lights) to smooth the shadow.
  • The default shapes that are drawn are more visually appealing, so you get a better idea of what these scripts can do. Specifically, they use refraction and reflection to imitate glass, shiny metal, and mirrors.
  • The user interface:
    • The program contains a new high-quality icon.
    • The window caption gives detailed information about the current image being rendered.
    • The progress (percent completed and rendering stage), time elapsed, and an estimation of the time remaining is drawn inside the window.
    • The image is scaled to fit the whole window and centered, so smaller images can be seen better and larger images can viewed in their entirety.
    • The entire image can be saved to a PNG, BMP, or JPEG file, rather than just what's visible or detailed in the current window.
    • If the selected save file already exists, a prompt confirms the overwrite beforehand because the stupid GM "save dialogue" doesn't. :angry:
    • Rendering may be paused and resumed, for if you want to play a game or do something CPU intensive.

GM Ray Tracer is the first (and only) ray tracer to ever be created in Game Maker.

According to Wikipedia, ray tracing is basically a way to render a high quality image. Standard rendering, called rasterization, is very quick, yet low in quality. Ray tracing works backwards from real life, where photons are shot from lights and "bounce" until they hit your eye; instead, rays are shot from the eye and "bounce" to calculate the light at a certain point.

The major disadvantage to ray tracing is that rendering images requires great amounts of CPU power and time, so real-time applications are not feasible.


More screen shots are contained in the spoiler (including an animation and the biggie :o):
Spoiler

 
Long-term to do list:
  • Add new shapes, such as rectangles (as opposed to infinite planes), triangles, and perhaps wedges of spheres (ungulas).
  • Implement more visual effects, such as depth of field with hard-edged bokeh, bloom/glow, lens flare, and caustics.
Documentation of the new temporary folder structure for threading can be found in the spoiler:
Spoiler

Edited by LaLaLa, 01 May 2012 - 12:44 AM.

  • 0

#2 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 02 March 2011 - 12:14 AM

This might anal rape your CPU. Keep an eye on your temperatures.
  • 4

#3 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 02 March 2011 - 12:28 AM

This might anal rape your CPU. Keep an eye on your temperatures.

Lol, I have to watch the fan on my laptop.
Does anyone have any comments or suggestions? :unsure:

Edited by LaLaLa, 30 March 2012 - 03:08 AM.

  • 0

#4 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 02 March 2011 - 12:34 AM


This might anal rape your CPU. Keep an eye on your temperatures.

LMAO. I have to watch the fan on my laptop.
Do you or anyone else have any comments or suggestions? :unsure:

You could probably speed it up by using this DLL. Showing the progress would need to draw every pixel onto a surface or something, though.
  • 2

#5 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 02 March 2011 - 01:01 AM

You could probably speed it up by using this DLL. Showing the progress would need to draw every pixel onto a surface or something, though.

That is an interesting DLL, but since this is just an example of a set of GML scripts, I don't want to add an outside resource and complicate it further.

As far as implementing it, however, it would be similar to how I've threaded other programs. I have the child thread(s) write to a 2-dimensional array in the parent thread the color of each pixel, and then update a row/column counter variable also in the parent thread. The parent thread then draws each new pixel until it gets to the currently computed one, and then ends its Draw step.

Doing this might be faster, but would complicate the code. :( I currently have something rather simple and elegant in its ideology.

Edited by LaLaLa, 07 August 2011 - 07:03 AM.

  • 0

#6 Recreate

Recreate

    Furry

  • GMC Member
  • 2928 posts
  • Version:GM8

Posted 20 March 2011 - 05:53 AM

This might anal rape your CPU. Keep an eye on your temperatures.

No problem when it's been anal-raping my desktop's CPU for 5 days straight, with the fan at low speed all the time. :P Dust, clean it.
  • 0

#7 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 20 March 2011 - 07:33 AM


This might anal rape your CPU. Keep an eye on your temperatures.

No problem when it's been anal-raping my desktop's CPU for 5 days straight, with the fan at low speed all the time. :P Dust, clean it.

Dust isn't always the problem, sometimes you just don't have proper cooling (and can't fix it).
  • 0

#8 Recreate

Recreate

    Furry

  • GMC Member
  • 2928 posts
  • Version:GM8

Posted 20 March 2011 - 02:50 PM

Then I'd suggest you get a better computer that's designed better so that it won't overheat itself at stock frequencies.
  • 0

#9 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 20 March 2011 - 06:06 PM

Then I'd suggest you get a better computer that's designed better so that it won't overheat itself at stock frequencies.

Plus my CPU is much more powerful than yours and uses about the same amount of space. It generates more heat.

I have no case fans. I need some.
  • 0

#10 Recreate

Recreate

    Furry

  • GMC Member
  • 2928 posts
  • Version:GM8

Posted 20 March 2011 - 08:13 PM

Actually, no.
Intel Core2 Quad Processor 2.83 GHz, TDP: 65 watts.(CPU similar to the one you have)
Intel Pentium 4 Processor 3.20 GHz GHZ, TDP: 103 watts.(CPU my desktop has)

My desktop's CPU is a lot less efficient than yours, generates nearly double the heat. :) Conclusion, you're wrong, your computer cooling and casing design is crap.

Edited by Recreate, 20 March 2011 - 08:13 PM.

  • 0

#11 Recreate

Recreate

    Furry

  • GMC Member
  • 2928 posts
  • Version:GM8

Posted 22 March 2011 - 02:17 PM

Posted Image
It's been two days.(since i accidentally closed it and restarted it)
TWO DAYS.

Someone ought to make this be able to work with multiple computers over a network.
  • 0

#12 Phantom107

Phantom107

    Engineer

  • GMC Member
  • 2589 posts
  • Version:GM:Studio

Posted 22 March 2011 - 03:21 PM

Very impressive, but what is the practical use of this? There are a number of render tools out there for free like Kerkythea. It's awsome, I made this and this one with it.
  • 0

#13 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 23 March 2011 - 10:45 PM

It's been two days.(since i accidentally closed it and restarted it)
TWO DAYS.

Someone ought to make this be able to work with multiple computers over a network.

Lol... If you close out of something half way through and restart it, it usually takes longer. However, considering how long this takes, I might make some way of resuming in the middle of rendering an image.

I could also implement distributed rendering across a network, but I don't think it'd be worth it considering so few people could/would utilize this.

Anyway, the reason your image is taking SO long to render is because it's at 1280x800px with 4x anti-aliasing! That's a bit over the top :o (and the same as a 5120x3200px).

Edited by LaLaLa, 23 March 2011 - 10:47 PM.

  • 0

#14 The Scorpion

The Scorpion

    GMC Member

  • GMC Member
  • 416 posts
  • Version:GM8

Posted 25 March 2011 - 08:37 AM

Dude nothing appears, Nothing at all!
Should I Add things my self ?
  • 0

#15 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 25 March 2011 - 07:38 PM

Dude nothing appears, Nothing at all!
Should I Add things my self ?

It's slow.
  • 0

#16 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 25 March 2011 - 08:31 PM

Dude nothing appears, Nothing at all!
Should I Add things my self ?

Yeah, you will have to give it a few minutes, and eventually something should come up. There is a gray background and it updates line by line. I see no reason why this wouldn't work, but try rendering a small image, like 200 x 200 px with 1x anti-aliasing on 1 thread.
  • 0

#17 The Scorpion

The Scorpion

    GMC Member

  • GMC Member
  • 416 posts
  • Version:GM8

Posted 25 March 2011 - 08:48 PM


Dude nothing appears, Nothing at all!
Should I Add things my self ?

Yeah, you will have to give it a few minutes, and eventually something should come up. There is a gray background and it updates line by line. I see no reason why this wouldn't work, but try rendering a small image, like 200 x 200 px with 1x anti-aliasing on 1 thread.


Well, that took some time !
The result was just Amazing!
But I really don't see How any one can use this ! (But Still NICE to look at :P)
  • 0

#18 ipq

ipq

    GMC Member

  • GMC Member
  • 34 posts

Posted 25 March 2011 - 09:45 PM

This should be gathered before the computer clusters connected with others through computers or render farm, otherwise it could be to grill processor. I do not know how it stays in rendering programs, but those tend to have insurance against high CPU loads and use only a part, including the GPU.

This might anal rape your CPU. Keep an eye on your temperatures.

Rather, baked orange.
  • 0

#19 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 25 March 2011 - 10:21 PM

This should be gathered before the computer clusters connected with others through computers or render farm, otherwise it could be to grill processor. I do not know how it stays in rendering programs, but those tend to have insurance against high CPU loads and use only a part, including the GPU.


This might anal rape your CPU. Keep an eye on your temperatures.

Rather, baked orange.

What? Do you mean there should be a way to throttle CPU usage?

Currently the rendering threads are set to low priority so they shouldn't interfere with other activities. However, as for actually setting a CPU utilization percentage, I'm not sure how to do this...

BTW, update coming soon!

Edited by LaLaLa, 25 March 2011 - 10:23 PM.

  • 0

#20 Recreate

Recreate

    Furry

  • GMC Member
  • 2928 posts
  • Version:GM8

Posted 25 March 2011 - 10:31 PM


It's been two days.(since i accidentally closed it and restarted it)
TWO DAYS.

Someone ought to make this be able to work with multiple computers over a network.

Lol... If you close out of something half way through and restart it, it usually takes longer. However, considering how long this takes, I might make some way of resuming in the middle of rendering an image.

I could also implement distributed rendering across a network, but I don't think it'd be worth it considering so few people could/would utilize this.

Anyway, the reason your image is taking SO long to render is because it's at 1280x800px with 4x anti-aliasing! That's a bit over the top :o (and the same as a 5120x3200px).

That must be why 1920x1080 with 6x AA was only at 20% after a week of time.(on two threads)

Edited by Recreate, 25 March 2011 - 10:33 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users