Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Raytracer
Author Message
apython1992

Posted: Wed Mar 09, 2011 11:13 pm   Post subject: Raytracer

This is the output from the beginning works of a raytracer implemented entirely in python (probably a poor choice for this kind of project, but what the heck). More to come once I add reflection and refraction.

test3.png
Description:
Filesize:  66.06 KB
Viewed:  266 Time(s)

apython1992

Posted: Sun Mar 13, 2011 8:19 pm   Post subject: Re: Raytracer

An update.

test17.png
Description:
Filesize:  69.86 KB
Viewed:  262 Time(s)

apython1992

Posted: Sat Mar 26, 2011 6:02 pm   Post subject: Re: Raytracer

Yet another update. Recursive raytracing in place for reflections.

reflect7.png
Description:
Filesize:  85.23 KB
Viewed:  289 Time(s)

reflect5.png
Description:
Filesize:  122.14 KB
Viewed:  286 Time(s)

SNIPERDUDE

Posted: Sat Mar 26, 2011 8:39 pm   Post subject: RE:Raytracer

Looking pretty good man, how fast does it render? I know it varies by task and machine, just curious.
apython1992

Posted: Sat Mar 26, 2011 8:45 pm   Post subject: Re: Raytracer

Thanks man, before making it recursive I spent some time making various optimizations and it took around 72 seconds to render. Now, with reflections and such it takes about two minutes, so it's not horrible but it could be better.
SNIPERDUDE

Posted: Sat Mar 26, 2011 8:50 pm   Post subject: RE:Raytracer

Pretty decent. How are you optimizing?
apython1992

Posted: Sun Mar 27, 2011 1:14 am   Post subject: Re: Raytracer

Well, at first I was more concerned with just making sure the math was right and stuff so at first I was making a lot of unnecessary calculations. When I made sure everything was right, the first few optimizations were algorithmic - using a geometric solution as opposed to an algebraic solution for calculating the sphere-ray intersections, for example. I made quite a number of those kinds of optimizations and it really helped. Then I made some little tweaks here and there, replacing list comprehensions with function mapping where possible, and stuff like that. Overall, I went from taking 8 minutes to render a non-recursive image to taking 2 minutes to render a recursive (reflected) image, but I know there are still optimizations to be made. I read about storing the previously intersected object in a temporary cache so that the next primary ray would test an intersection with that object first, which sounds like it would speed things up quite a bit given large enough objects. Also, I've read a tiny bit on dividing up the scene into segments, and surrounding complex composite objects with simple, quick-to-test polygons, which will be a handy optimization when I start using more than just simple geometric objects.

I profiled my code and the vast majority of time is spent calculating ray-object intersections, so I've mostly focused on tweaking these parts up and algorithmically doing as few intersection tests as possible. You seem to know a bit about this...do you have any ideas for optimization that I might not have thought about yet?
SNIPERDUDE

Posted: Sun Mar 27, 2011 4:23 pm   Post subject: RE:Raytracer

Regarding your first optimizations it really goes to show how far efficient coding and planning ahead (prevents redundancies) goes.

apython1992

Posted: Sun Mar 27, 2011 5:20 pm   Post subject: RE:Raytracer

I couldn't agree more!
QuantumPhysics

Posted: Mon Oct 08, 2012 11:11 am   Post subject: RE:Raytracer

Sorry for resurrecting the dead thread but this is amazing! Really great work. My reaction was absolute, wow!
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 10 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: