Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Raytracer
Index -> Programming, Python -> Python Submissions
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
apython1992




PostPosted: 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:  263 Time(s)

test3.png


Sponsor
Sponsor
Sponsor
sponsor
apython1992




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

An update.


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

test17.png


apython1992




PostPosted: 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:  285 Time(s)

reflect7.png



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

reflect5.png


SNIPERDUDE




PostPosted: 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




PostPosted: 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




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

Pretty decent. How are you optimizing?
apython1992




PostPosted: 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




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
apython1992




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

I couldn't agree more!
QuantumPhysics




PostPosted: 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:   
   Index -> Programming, Python -> Python Submissions
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: