## Newton Raytracer - Now Interactive!

Share with us how are you using the powerrrr of the force

Moderator: Alain

### Re: Newton Raytracer

Boost.Thread really does make it easy, though:
Code: Select all
`struct pixel{    float x, y;    engine::byte *p;    pixel(float x, float y, engine::byte *p):        x(x), y(y), p(p) {}};void tracePixel(const pixel &p, const mat4 &mat, const phys::world &w, const lightList &lights){    // y goes from bottom to top    ray_t r = screenRay(p.x, p.y, mat);    vec3 c = saturate(colourFromRay(r, w, lights).get_value_or(vec3(0, 0, 0)));    for (size_t j = 0; j < 3; ++j)        p.p[j] = engine::byte(c[j] * 255.0);    p.p[3] = 255;}void tracePixels(const std::vector<pixel> &pixels, const mat4 &mat, const phys::world &w, lightList &lights){    for (size_t i = 0, j = 0; i < pixels.size(); ++i, ++j)    {        tracePixel(pixels[i], mat, w, lights);        if (j == 1024)        {            j = 0;            std::cout << float(i) / pixels.size() * 100 << " %\n";        }    }}struct tracer{    std::vector<pixel> pixels;    mat4 mat;    const phys::world &w;    lightList lights;    tracer(const std::vector<pixel> &pixels, const mat4 &mat, const phys::world &w, const lightList &lights):        pixels(pixels), mat(mat), w(w), lights(lights) {}    void operator()()    {        tracePixels(pixels, mat, w, lights);    }};// in main()for (size_t i = 1; i < pixels.size(); ++i)    {        threads.push_back(boost::shared_ptr<boost::thread>(            new boost::thread(tracer(pixels[i], invMat, world, lights))));    }// main thread do the first pixels    tracePixels(pixels[0], invMat, world, lights);`

I'm just rendering myself some backgrounds in the meantime on 2 cores. Kind of hard to browse the internet, even
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: Newton Raytracer

Amd Phenom 9500 2.2mhz mem 3gig:
512 512 1 = 25 sec
512 512 2 = 15 sec
512 512 3 = 10 sec
512 512 4 = 5 sec
1024 1024 4 30 sec

Very nice stuff.
Good work.
You search a nice physics solution, if you can read this message you're at the good place
OrionX3D Projects & Demos:

Dave Gravel

Posts: 725
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

### Re: Newton Raytracer

wow, I run this test in a freind's brand new Nahelam 2.93 ghz with 4 gbyte ram
and a 512 x 512 with 8 or 16 threads take under 3 secunds, I cna no even mesure the time using the windows clock.
a 1024 x 1025 x 16 takes under 12 secunds
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: Newton Raytracer

Wow, that's awesome . And there's still so many optimizations that can be done (for example, no shadow ray is needed if N.L < 0), and no computations are needed if the surface is facing away from the viewer.

Oh, and I'm going to make it render several frames. Tick the physics, and then make a movie (all of these are ready-to-go NewtonBody's).
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: Newton Raytracer

Wow, this is great! Now my ray tracer can render consecutive physics frames

And it was as simple as:
Code: Select all
`for (size_t i = 0; i < numFrames; ++i)    {        go(viewMat, world, lights, pixels, numThreads);        world.tick(deltaTime);        save(screen, i);        std::cout << "done with frame " << i << "\n";    }`

I'm going to release a new demo soon. Only problem is that it makes a bunch of images, no actual movie file... Though I'd be very interested to see how it runs on a very powerful processor
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: Newton Raytracer

Took about ~30 minutes to render a movie: http://www.youtube.com/watch?v=-2ubVE1B2xc&fmt=18

Pretty short, but it's cool (can't really see much reflections, though, because it's kind of small) I bet you can render quite long moves a lot faster than me, and your friend can do it even faster

I'm going to upload the demo soon.
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: Newton Raytracer

agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: Newton Raytracer

wow the video is very impresive. It is more consistent than I was expecting for a ray tracer from the backyard. Very very coll.
can you make a video a 4 time the resolution and dowun sample it so that it looks at the collest?

Unfortunatly the Nahelen is not mine I was testing in the house of friend over the Thanth Given Dinner.
They think I am a from another planet because I work with computers.
so the ask for my advise getting a new machine and they I had to put it together for them.
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: Newton Raytracer

Sure. That was at 512x512, so maybe I'll do a 2048x2048... Or only 1024x1024. I want to leave it overnight, but I'm afraid it still won't finish if the size is too big. If every frame takes ~15 minutes at 2048x2048 with 1000 spheres, then I can do at most 68 frames
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: Newton Raytracer

Alright, I left a 2048x2048 1000-ball 128-frame job running over the night, and it just finished frame 104. Here's a preview of the graphics quality:

I think I'll let it render a few more frames until I get ready for school and then I'll stop it, give my computer some time to cool off (CPU was at 59C at one point since I turned off a few fans so I could sleep).
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: Newton Raytracer

Here's the overnight video: http://www.youtube.com/watch?v=j6-lR5cBYuY&fmt=18

A bit short and crappy, but it's still pretty cool. I'll upload a new demo soon.
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: Newton Raytracer - Now Interactive!

So, anyone tried the interactive demo? I need to know if it works, or if the whole console thing doesn't work (I run it from my IDE, so I'm not sure if running it from cmd.exe will work the same way).

Anyways, convex hulls and eggs and boxs all work as expected:

agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: Newton Raytracer - Now Interactive!

Is there an imteractive demo, you say?
Julio Jerez
Moderator

Posts: 11155
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: Newton Raytracer - Now Interactive!

There was, but I took the link down because I got reports that it caused weird blue screens . I'm going to debug it and then re-upload.
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Previous