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

Username:   Password: 
 RegisterRegister   
 Ray Tracer With Reflections and AA
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wierdo1111




PostPosted: Thu May 01, 2014 2:30 am   Post subject: Ray Tracer With Reflections and AA

I made this to improve my algebra. So basically this is a "real-time" ray tracer if you consider 1/20 fps with one light and object real time. This version includes AA by super sampling, I also made another version which does MSAA which is maaaaany times faster. Originally all calculations where done through functions but that was slow so I removed them and added an extra 100+ lines of pure calculations, and before you ask I know what a for statement is but there slow. I left in original functions and commented out there calls so you could see what what was happening instead of random calculations.

The GUI only display info you can't change anything except AA level, so all change will have to be manual. AA takes a long time to do, luckily that time is can easily be calculated. Time with AA is ~= to time without AA it would have take multiplied by 2^(n) when n > 1, where n is your AA level which should be a positive integer, but funny story I never tested for negatives or put in any checks so I don't actually know what happens.

Camera variables are at line 502 and 503, only change camPos and look_at. Object and Light data can be found right below camera.

Quick tut on setting up object and lights, because I added no comments.


Turing:

var lightCount : int := 1 % amount of lights to make, make sure this is set right
var lights : array 1 .. lightCount of ^Light
%
for i : 1 .. lightCount
    new lights (i)
end for
% lights (i) -> CreateLight ((x,y,z),(r,g,b,s))
lights (1) -> CreateLight (Vector.Set (0, 6, 0), Colour.Set (0.3, 0.3, 0.3, 0))

%%%%

var objCount : int := 1 % Amount of objects u create, make sure this is set too
var object : array 1 .. objCount of ^Primitive
%
for i : 1 .. objCount
    new object (i)
end for
% object (i) -> CreatePrimtive ((x,y,z),r,(r,g,b,s),shape)
% shape 0, plane
% shape 1, sphere
% r is radius or distance from origin in direction of normal for planes
% colour s, reflectiveness 0= none 1=full
object (1) -> CreatePrimitive (Vector.Set (0, 1, 0), -1, Colour.Set (1, 1, 1, 1), 0)


Other things to note, using Open Turing more than doubles rendering speed and compiling as .exe further ups that by 5~10%. Funnily enough the direction of planes while have no difference on colour or reflections can greatly effect speeds, in the version I include if you invert the normal and r-values it will add an extra 30 seconds of rendering time. Also throwing in a .exe compiled with Open Turing if you didn't believe about the speed. Just added MSAA version in zip, comes with 3 pics; no AA 8x MSAA and 8x SSAA.



Ray Tracer.zip
 Description:
Contains SSAA version, MSAA version and 3 pics

Download
 Filename:  Ray Tracer.zip
 Filesize:  432.42 KB
 Downloaded:  246 Time(s)


Ray Tracer SSAA.t
 Description:

Download
 Filename:  Ray Tracer SSAA.t
 Filesize:  28.31 KB
 Downloaded:  197 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Thu May 01, 2014 5:22 pm   Post subject: RE:Ray Tracer With Reflections and AA

That's pretty awesome!

It looks like your shadows aren't working correctly. You're taking the magnitude of the light-direction vector as the distance to the light, but you're doing it after you normalize, so your shadows don't work quite right.

It also looks like your reflected rays are just taking the brightness of the object they hit (that is, they ignore shadowing / lighting). If you fix the shadow bug first, this second bug will become a lot more obvious, especially on the very-reflective objects.

Great work!
wierdo1111




PostPosted: Thu May 01, 2014 10:37 pm   Post subject: Re: RE:Ray Tracer With Reflections and AA

DemonWasp @ Thu May 01, 2014 5:22 pm wrote:

It also looks like your reflected rays are just taking the brightness of the object they hit (that is, they ignore shadowing / lighting). If you fix the shadow bug first, this second bug will become a lot more obvious, especially on the very-reflective objects.

Thanks, I never even noticed the lighting issue till you mentioned it because it doesn't look overly wrong. From what I can tell fixing the shadow bug has no impact on speed and colour, but I fixed it anyways.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: