Ray tracing Help

Practical and theoretical implementation discussion.
Post Reply
Tom
Posts: 3
Joined: Thu Dec 29, 2011 4:54 pm

Ray tracing Help

Post by Tom » Thu Dec 29, 2011 5:26 pm

HI,
I am new to ray tracing and I had a project to do and I have written a code and it did work and I had 2 spheres as a result, but the image was not that clear and I didn't know how to create the 2 planes in the image so I need some help please.
Thanks.
Last edited by Tom on Tue Jan 03, 2012 2:11 pm, edited 1 time in total.

jbikker
Posts: 225
Joined: Mon Nov 28, 2011 8:18 am
Contact:

Re: Ray tracing Help

Post by jbikker » Fri Dec 30, 2011 8:52 am

So basically you're asking us to do your homework? :)
Try to get started, see where you get stuck, then you can ask detailed questions. There are some good tutorials on ray tracing on the web.

Tom
Posts: 3
Joined: Thu Dec 29, 2011 4:54 pm

Re: Ray tracing Help

Post by Tom » Fri Dec 30, 2011 10:26 am

No I told you that I did it and I got 2 spheres as a result but the image is not quite good so I need some help to see where is the problem why am I having this, I need someone to take a look at my code but I won't post it cz I can't post it unless I've presented the project..

Arite
Posts: 9
Joined: Mon Dec 19, 2011 3:05 am

Re: Ray tracing Help

Post by Arite » Mon Jan 02, 2012 11:57 pm

So presumably you want to intersect rays with planes? Here's a useful webpage with links to lots of different object-object intersections (including ray-plane):
http://www.realtimerendering.com/intersections.html

From there - Line-Plane intersection:
http://www.softsurfer.com/Archive/algor ... tersection

Be sure to normalise your vectors accordingly, and check that the normal and ray directions aren't perpendicular first. If dot(ray_dir, norm) > 0 then they won't intersect. Also if the distance to the plane is negative then the plane is behind the camera so also won't intersect.

Cheers, Arite.

Arite
Posts: 9
Joined: Mon Dec 19, 2011 3:05 am

Re: Ray tracing Help

Post by Arite » Tue Jan 03, 2012 4:36 pm

Can you be more specific? Like jbikker said ask detailed questions, and there are lots of good tutorials on the web. One I found useful is the Codermind tutorial:
http://www.codermind.com/articles/Raytr ... acing.html

And of course Jacco's tutorials (URL is now slightly different as DevMaster's been updated):
http://devmaster.net/posts/raytracing-t ... troduction

Anyway, the shading part is done after the intersection part. If you had diffuse, reflective and refractive surfaces, then you'd check/lookup the material of the object you intersected before you shade it. So to make a ray tracer without the reflection or refraction you just assume the object you've hit is a diffuse surface.

If you only have diffuse surfaces then, after your primary ray intersects with an object, fire another ray from that object to the light source (assuming it's a point light source); a shadow ray. Check the light source isn't behind the object (so ensure dot(norm, shadow_ray) > 0), and trace the ray to light source. If there are objects in the way then the part is occluded and so the colour is black/ambient colour. If it's not occluded then you colour the pixel.

Assuming you're doing lambertian reflection, the incoming light is inversely proportional to the square of the distance from the light source (which is just dot(shadow_ray, shadow_ray)). Multiply that by the light colour to give the incoming light. Then take dot(shadow_ray, norm) (normalise vectors first!) to get the cosine of the angle of the normal to the incoming light.

Multiply the incoming light by that, then multiply by the object colour (if it's white then no need). Return that colour and you're done.

EDIT: Seems I replied to a now deleted post.

Arite.

jbikker
Posts: 225
Joined: Mon Nov 28, 2011 8:18 am
Contact:

Re: Ray tracing Help

Post by jbikker » Tue Jan 03, 2012 8:42 pm

His professor found ompf. ;)

Tom
Posts: 3
Joined: Thu Dec 29, 2011 4:54 pm

Re: Ray tracing Help

Post by Tom » Wed Jan 04, 2012 8:30 am

No he didn't actually :P but it worked with me and I had 2 spheres with shadow thanks arite.

Post Reply