Jump to content


Photo

GM Ray Tracer (Multi-threaded version)


  • Please log in to reply
45 replies to this topic

#21 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 29 March 2011 - 09:32 PM

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

Wow... Dude, did you look at the code used to save a screen shot? It doesn't save the entire image, but just the screen, so half your image won't even be visible.

If you actually want the entire thing, you'll have to open the temp folder for the program and try to grab the two images from there and piece them together. Good luck :blink:
  • 0

#22 mrpeanut188

mrpeanut188

    GMC Member

  • GMC Member
  • 814 posts
  • Version:GM8

Posted 30 March 2011 - 01:48 PM


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

Wow... Dude, did you look at the code used to save a screen shot? It doesn't save the entire image, but just the screen, so half your image won't even be visible.

If you actually want the entire thing, you'll have to open the temp folder for the program and try to grab the two images from there and piece them together. Good luck :blink:


DANG IT! My norton security is acting up. Claims that it is a virus. Any1 know what the GML does that could cause it to do that?
  • 0

#23 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 30 March 2011 - 08:13 PM

DANG IT! My norton security is acting up. Claims that it is a virus. Any1 know what the GML does that could cause it to do that?

Why did you reply to my post to another person? :unsure:

No GML should be identified as a virus. Your problem is that your have a piece of crap anti-virus program (aka Norton). These scripts don't even access the registry or possibly restricted files/folders, only the temp_directory.

Edited by LaLaLa, 22 April 2011 - 02:06 AM.

  • 0

#24 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 13 April 2011 - 09:04 PM

New update released! See first post for specifics about what's new/changed.

Also, I'm aware that the first thread doesn't resume from pausing for some reason. It didn't initially do this, so I'll fix it soon. :whistle:

EDIT: This has been fixed, along with some other bugs. See my post below.

Edited by LaLaLa, 07 June 2011 - 06:55 AM.

  • 0

#25 x-Amnesia-x

x-Amnesia-x

    GMC Member

  • New Member
  • 14 posts

Posted 27 April 2011 - 02:30 AM

New update released! See first post for specifics about what's new/changed.

Also, I'm aware that the first thread doesn't resume from pausing for some reason. It didn't initially do this, so I'll fix it soon. :whistle:


Wow, this is really quite amazing, I was randomly searching Google and I stumbled across this thread. This was the last program I ever wrote in GM, and I haven't touched GM since :P
Major props for picking this project up again LaLaLa. I hope you advance the project further in the future!

x-Amnesia-x
  • 0

#26 IQbrew

IQbrew

    Pro-Grammar

  • Banned Users
  • 2607 posts
  • Version:Unknown

Posted 27 April 2011 - 02:50 AM

I've done a bit with raytracing. I found this interesting, but I'm not interesting in my computer crapping itself at 4 cores for hours on end for simple images.
Posted Image

#27 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 27 April 2011 - 08:33 PM

Wow, this is really quite amazing, I was randomly searching Google and I stumbled across this thread. This was the last program I ever wrote in GM, and I haven't touched GM since :P
Major props for picking this project up again LaLaLa. I hope you advance the project further in the future!

x-Amnesia-x

Thanks :D

I've done a bit with raytracing. I found this interesting, but I'm not interesting in my computer crapping itself at 4 cores for hours on end for simple images.

I hope your CPU overheats and melts too... Or how about you just stick the pointy end of C++ up your butt lol.
  • 0

#28 IQbrew

IQbrew

    Pro-Grammar

  • Banned Users
  • 2607 posts
  • Version:Unknown

Posted 27 April 2011 - 09:15 PM

I hope your CPU overheats and melts too... Or how about you just stick the pointy end of C++ up your butt lol.

Sorry, should I have stroked your ego so you don't throw a fit?

#29 xot

xot

    media multimixer

  • Global Moderators
  • 4653 posts
  • Version:GM:Studio

Posted 27 April 2011 - 09:27 PM

Interesting. I wrote my first ray-tracer 20+ years ago but none of them were quite this capable. What really interests me is this method of multi-threading.

As for the app itself, it is a lot more pleasant when the level of recursion is reduced to sane levels. That should be a user setting. It would be nice if this had a recursion limiter tied to certain threshold of potential influence (eg. if the next ray contributes less than 5%, halt recursion).

Edited by xot, 27 April 2011 - 09:38 PM.

  • 0

#30 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 06 May 2011 - 01:13 AM


I hope your CPU overheats and melts too... Or how about you just stick the pointy end of C++ up your butt lol.

Sorry, should I have stroked your ego so you don't throw a fit?

Well, that wouldn't have been a bad thing... :rolleyes:

Interesting. I wrote my first ray-tracer 20+ years ago but none of them were quite this capable. What really interests me is this method of multi-threading.

As for the app itself, it is a lot more pleasant when the level of recursion is reduced to sane levels. That should be a user setting. It would be nice if this had a recursion limiter tied to certain threshold of potential influence (eg. if the next ray contributes less than 5%, halt recursion).

The "level of recursion" can be set in the object's Create event, which sets the maximum amount of bounces for each ray before its color is calculated. As for "sane" levels, it is set to 4 by default, which is reasonable. If set lower then reflections and refractions (like off the walls or the glass sphere) will appear completely black and not look good.

As for halting recurson, I'm not sure what you mean. You can't determine the final contribution of a ray until you bounce it off however many surfaces and see how bright in will appear from the lights in the scene. Due to the HDR lighting, even if a ray only shows 10% off a reflection, if the light has a color of (100 * 255, 100 * 255, 100 * 255), then it could still appear white because of the relative "overflow" of color intensity.

Edited by LaLaLa, 10 May 2011 - 08:40 PM.

  • 0

#31 xot

xot

    media multimixer

  • Global Moderators
  • 4653 posts
  • Version:GM:Studio

Posted 09 May 2011 - 10:00 PM

You can't determine the final contribution of a ray until you bounce it off however many surfaces and see how bright in will appear from the lights in the scene.

If you know the intensity of your lights and the reflectance and transmittance of the surface, you can easily calculate the maximum amount of light a ray can contribute to the pixel. It's really no different than what you are already doing (ie. not spawning rays where reflectance or transmittance is zero), except the threshold calculation is a bit different. HDR doesn't change your ability to make that calculation. However, since the surfaces you've chosen are all at least marginally specular/reflective, such an optimization would probably provide only negligible gains.

As for "sane" levels, it is set to 4 by default, which is reasonable. If set lower then reflections and refractions (like off the walls or the glass sphere) will appear completely black and not look good.

When I said "sane levels", I wasn't commenting so much on image quality as I was on the time needed to complete the demonstration. Expecting people to spend an hour or more running this (or days without some additional guidance from you) may not be an effective way to get your point across.

A few stylistic changes might have produced a much faster yet equally effective demonstration.

Posted Image

These tests brought up something very strange. The image on the right (600x600, 1x AA) should have the same number of samples as the image in the middle (300x300, 4x AA), yet their times are drastically different. What's going on here?

EDIT:

OK, I see where I made my mistake concerning 4x AA. Here it means 4x4 = 16 subsamples, not 4 subsamples (which would be 2x AA).

Edited by xot, 09 May 2011 - 11:26 PM.

  • 0

#32 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 10 May 2011 - 09:32 PM

If you know the intensity of your lights and the reflectance and transmittance of the surface, you can easily calculate the maximum amount of light a ray can contribute to the pixel.

Ah, I see what you mean. Determine the brightest light in the scene and for each ray cast, based on the reflection/refraction levels of the shape, determine if it could possibly add more than, say, 5% color to the pixel and, if not, break out. That would be effective in reducing the computations for the walls and things when there are up to 4 raycasts, by which point there's no major impact to the pixel's color. This would especially help in the current scene because every surface is somewhat reflective/refractive.

When I said "sane levels", I wasn't commenting so much on image quality as I was on the time needed to complete the demonstration. Expecting people to spend an hour or more running this (or days without some additional guidance from you) may not be an effective way to get your point across.

I agree. I'll see what I can do to get it to run faster out of the box.

OK, I see where I made my mistake concerning 4x AA. Here it means 4x4 = 16 subsamples, not 4 subsamples (which would be 2x AA).

Yes, isn't that always the case, even in games or graphics card settings where you choose like 2X or 4X anti-aliasing? I mean, how would you render it if the user chose a total of 2 sub-samples per pixel, as opposed to in each direction; cast 1.414 rays per direction lol?

On that note, I'm thinking of how to get "smart" anti-aliasing where normally every pixel has one (original) ray cast, but only areas where there could be hard edges (on the edges/intersections of shapes) would be sub-sampled.

EDIT: This has been implemented. See my post below.

Edited by LaLaLa, 07 June 2011 - 06:57 AM.

  • 0

#33 xot

xot

    media multimixer

  • Global Moderators
  • 4653 posts
  • Version:GM:Studio

Posted 13 May 2011 - 03:55 AM


OK, I see where I made my mistake concerning 4x AA. Here it means 4x4 = 16 subsamples, not 4 subsamples (which would be 2x AA).

Yes, isn't that always the case, even in games or graphics card settings where you choose like 2X or 4X anti-aliasing? I mean, how would you render it if the user chose a total of 2 sub-samples per pixel, as opposed to in each direction; cast 1.414 rays per direction lol?

There is no law that says subsamples have to be distributed on a subdivided, square grid, and even that isn't a very limiting factor.

Posted Image

There has been a good deal of research suggesting that random subsamples distributed with blue noise frequency will result in optimal image sampling. This is the same sampling distribution used by the photo-receptors of the human eye. Foregoing the effort required to generate high-quality blue noise one can simply select subsamples at a random position within the area of the pixel. In such a case, any number of subsamples can be easily supported. Randomly "jittering" sample points within the area of the pixel can result in a noisy image, especially at low levels subsampling. An advantage of non-lattice-based sample distribution is that it can help mitigates Moiré artifacts that can appear when certain regular patterns are sampled at a rate lower than their Nyquist limit.


On that note, I'm thinking of how to get "smart" anti-aliasing where normally every pixel has one (original) ray cast, but only areas where there could be hard edges (on the edges/intersections of shapes) would be sub-sampled.

I was going to suggest this as well but didn't want to muddle things anymore than I already have. I'd be curious to see your results if you proceed.
  • 0

#34 DanRedux

DanRedux

    GMC Member

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

Posted 13 May 2011 - 06:04 PM

Perhaps run a 1-ray-per-pixel layer, storing not only color data but also length data, run a quick edge-detect filter on your depth grid, and then you'll have a grid telling you how many subsamples to do at each pixel.

Not only that, but you also have a semi-quick way to do shadows. Have a light object run a render pass from its perspective, storing a list of every vertex (and where on that vertex and the lights power, which is divided every time it bounces) that each light ray passes through.

Now when you render the visual scene, you can quickly scan the list of vertexes the light hits for the vertex that this ray hit, and if you dont find one, the vertex is in complete darkness. If you do find that one of the lights rays hit that vertex, then find the closest hit on that vertex to your own hit, and then that "hit" will be that pixels lightness. Per-pixel lighting.

It would of course be much faster with some sort of lookup table, ie, each vertex has an ID, and if you ask for that index in some array, you get a list of "hits" on that vertex that the light made, and how much "power" the ray had left at that point.

Edited by time4dan, 13 May 2011 - 06:05 PM.

  • 0

#35 mrpeanut188

mrpeanut188

    GMC Member

  • GMC Member
  • 814 posts
  • Version:GM8

Posted 18 May 2011 - 01:59 AM

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


HOLY CRAP!
I accidentially did 600 x 600 with 4x with 40 threads....Opppsss.

DANG!!! My computer though can run it at 8 threads. What is the other peeps max?

This thing is cool now that I finally got it to work.
(Norton said it was a virus)

Edited by mrpeanut188, 18 May 2011 - 02:02 AM.

  • 0

#36 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 23 May 2011 - 12:30 AM

There has been a good deal of research suggesting that random subsamples distributed with blue noise frequency will result in optimal image sampling. This is the same sampling distribution used by the photo-receptors of the human eye.

That's interesting and seems reasonable, but I don't plan on going into all that work.


On that note, I'm thinking of how to get "smart" anti-aliasing where normally every pixel has one (original) ray cast, but only areas where there could be hard edges (on the edges/intersections of shapes) would be sub-sampled.

I was going to suggest this as well but didn't want to muddle things anymore than I already have. I'd be curious to see your results if you proceed.

I have implemented this, but it is based off of color differences between adjacent pixels rather than shape edges. Anti-aliasing edges would have been way too hard to find where, say, two random spheres intersect or intersections in reflections/refractions. It works pretty well and requires considerably less time than anti-aliasing the entire image.

Not only that, but you also have a semi-quick way to do shadows. Have a light object run a render pass from its perspective, storing a list of every vertex (and where on that vertex and the lights power, which is divided every time it bounces) that each light ray passes through.

I was working on adding shadows, but it didn't work so I gave up. I might try something different soon. As for you're idea, however, rendering the scene from each light's perspective would take way too long.

I accidentially did 600 x 600 with 4x with 40 threads....Opppsss.

DANG!!! My computer though can run it at 8 threads. What is the other peeps max?

There is no "max" but if you use more than like 10 threads it will only slow down your computer (and the rendering) a lot because it's loading lots of processes and your processor is switching between threads. I even tried launching it with 100 threads lol. It worked but was pretty stupid...

 
I have released a new version of the scripts. The changes include:
  • Bug fix with certain threads not resuming from being paused (freezing the game when the form lost focus was the issue because sometimes the pausing threads would lose focus before they hid their window, so Game Maker froze them indefinitely).
  • Bug fix with the sprite of certain threads randomly disappearing/popping in and out (the parent thread would occasionally try to load a sprite from an image that the slave thread was still writing, so it wouldn't load and wouldn't be drawn until the next line was completed).
  • Fixed considerable memory leak with depth of field lists (they weren't destroyed after each pixel was calculated, so they kept building up).
  • Fixed issue when applying depth of field with multiple threads (the image would be darkened because each thread didn't have the color data from other threads to blur with).
  • Added "smart" anti-aliasing (and removed full image anti-aliasing).
  • Added depth of field with Gaussian blurring (hard-edged bokeh might come later).

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

  • 0

#37 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 07 August 2011 - 09:21 AM

I have released a new version of these scripts. Please re-download the GMK or the EXE from the first post.

New features include:
  • Soft shadows that can be rendered accurately. Implemented using new, spherical 3D light sources.
  • Rendering speed improvements. Accomplished by implementing a recursion break when further ray casts from reflections/refractions can no longer make a noticible impact on the current pixel's color.
  • Simplified method of adding rendering stages. This allows certain ones to be skipped easily, such as depth of field.
  • Improved image saving routine. Now allows individual rendering stages to be composited and exported.
  • Minor GUI improvements.
  • Re-did folder and file structure for threading method so it is more logical. See first post spoiler for details.
Bug fixes include:
  • Fixed issue with depth of field in reflections/refractions not working properly.
  • Fixed issue with errors when opening grid data files between rendering stages. Caused because the next thread was attempting to load them while the previous thread was still saving them.
  • Fixed issue with errors about opening files for reading/saving when the user clicks the X (close) button as opposed to pressing Escape.
  • Now skips refraction when the index is set to 0, as this is undefined.

Edited by LaLaLa, 07 August 2011 - 09:24 AM.

  • 0

#38 mrpeanut188

mrpeanut188

    GMC Member

  • GMC Member
  • 814 posts
  • Version:GM8

Posted 11 August 2011 - 09:44 PM


DANG IT! My norton security is acting up. Claims that it is a virus. Any1 know what the GML does that could cause it to do that?

Why did you reply to my post to another person? :unsure:


Didn't realize I hit the quote button. :P
  • 0

#39 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 12 August 2011 - 06:48 AM

Didn't realize I hit the quote button. :P

That's fine lol. Have you tried out the new version with shadows and other fancy stuff? :unsure:

Post a picture if you can! :rolleyes:
  • 0

#40 LaLaLa

LaLaLa

    GMC Member

  • New Member
  • 511 posts
  • Version:GM8

Posted 13 September 2011 - 09:53 PM

[bump to my awesome scripts]
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users