Sign in to follow this  

raytracing

This topic is 4781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, have a few questions about raytracing... 1) how do you deal with computational inaccuracies. ie. ray-sphere intersection, I get a point of intersection (PI). A reflected ray then hits the sphere it has reflected off (because the PI lies on the sphere or slightly inside). I've tried to shift the PI along the ray (or normal for shadow rays). I've tried checking for results close to 0 and tried not allowing the ray to collide with the primitive that has reflected it. Neither of it works 100%. If two primitive were close enough, I can shift the PI from one into the other, the same goes with the second method. For non-conevx primitives, the third method wouldn't work. How do you deal with it 2) in shadow tests, how do you deal with refraction? I mean you can cast a ray to the light. If it hits a transparent primitive, it wouldn't prolly hit the light then. But that doesn't mean another ray from the light wouldn't! It might go a bit to the side and refract just the way we need. How do we deal with this? chances are you might have other useful info that could help me on this topic (like what you've stumbled upon when writing a raytracer). I'd highly appreciate this :) thanks. If you can hint on the questions I'[ve asked, perfect. Don't hesitate to explain if you feel like. I'll read it all thoroughly. thanks

Share this post


Link to post
Share on other sites
correct reflections/refractions/shadows is very simple. You have loop where you check for intersections with other objects.
You have checks like
if(IntersectionDistance>0 && IntersectionDistance<ClosestIntersectionDistance)ClosestIntersectionDistance=IntersectionDistance;

You need to

if(IntersectionDistance>smallvalue && IntersectionDistance<ClosestIntersectionDistance)ClosestIntersectionDistance=IntersectionDistance;


Also you may need to switch to doubles, in most cases 'em is as fast but much higher accuracy.
Quote:

2) in shadow tests, how do you deal with refraction? I mean you can cast a ray to the light. If it hits a transparent primitive, it wouldn't prolly hit the light then. But that doesn't mean another ray from the light wouldn't! It might go a bit to the side and refract just the way we need. How do we deal with this?

it's solved different way, via photon mapping / radiosity.

Share this post


Link to post
Share on other sites
checking if(distance>smallvalue... what if the distance between two spheres is < smallvalue?

what shall I do then, is the transparent object a occluder or not then (shall it collide with the shadow test?)

Share this post


Link to post
Share on other sites
hmm this seems like a lot of extra work. are you solving for the t value of the parametric form of a line with regards to the equation of a sphere?
if you are you should get 1 or at most 2 results. simply take the smaller of the two t values
{assuming of course at least one is > 0 if not the sphere is behind the ray's origin.

here is my current c# version of this coding




using System;
using Math;

namespace Raytrace
{

/// <summary>
/// CSphere Stores specific information and methods for
/// creating and modifying a sphere for use in the raytace's
/// graphics function
/// </summary>
public class CSphere : Raytrace.CShape
{

/// <summary>
/// Creates a sphere with a radius of 0 at location {0,0,0}
/// </summary>
public CSphere()
{
Radius = 0;
Location = new Math.CVector(0,0,0);
}


/// <summary>
/// Radius of the sphere
/// </summary>
public double Radius;

/// <summary>
/// Location holds the position of the CSphere
/// in object space
/// </summary>
public CVector Location;

/// <summary>
/// Intersection function used to check for intersection
/// of CRay and CSphere
/// </summary>
/// <param name="CheckRay">CRay to check for intersection
/// with CSphere</param>
/// <param name="Intersect">CVector that the closest
/// intersection point will be saved to _if_ CheckIntersect
/// returns true </param>
/// <returns>
/// CheckIntersect returns true if the CRay intersects
/// this CSphere and sets Intersect to closest intersection
/// CheckIntersect returns false if the CRay does not
/// intersect this CSphere and sets Intersect to {0,0,0}
/// </returns>
public override bool CheckIntersect(CRay CheckRay,
ref CVector Intersect)
{
CVector RayDirection = new CVector(CheckRay.DirectionVector());
CVector StartToSphere = new CVector(Location.X - CheckRay.RayStart.X,Location.Y - CheckRay.RayStart.Y,Location.Z - CheckRay.RayStart.Z);
double disc, v,d;

v = CVector.DotProduct(StartToSphere,RayDirection);
disc = Radius * Radius - (CVector.DotProduct(RayDirection,RayDirection) - v * v);
if (disc <0)
return (false);
else
{
d = System.Math.Sqrt(disc);
Intersect.X = CheckRay.RayStart.X + (v - d) * RayDirection.X;
Intersect.Y = CheckRay.RayStart.Y + (v - d) * RayDirection.Y;
Intersect.Z = CheckRay.RayStart.Z + (v - d) * RayDirection.Z;
}
return (true);
}


}
}

Share this post


Link to post
Share on other sites
i do it this way:

my ray structure also contains a reference to a primitive, called origin, which the ray originates from. also, it contains information on wether this ray already is within a transparant solid or not.

using this information your program can tell the impossible situations apart. like: ive found an intersection with a sphere on t=-0.00001 oops its the same sphere as im originating from, and im not inside of it, so this must be numerical error.

Share this post


Link to post
Share on other sites

This topic is 4781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this