## GRP1 discussion

### Re: GRP1 discussion

Ow but that explains: you can't pick a random direction in a cube. If you do that, you get random directions with a density that is higher in the corners, leading to the artifacts you complained about. *If* you pick directions in a cube, you need to reject all directions with a magnitude greater than 1 (so you get a sphere again).

### Re: GRP1 discussion

Impressive work there!

One of my favorite courses, hope everyone enjoys it!

One of my favorite courses, hope everyone enjoys it!

### Re: GRP1 discussion

Hey guys, have some trouble with my ray triangle intersections and was wondering if any1 could help me out,

here is the code i currently use:

Intersection IntersectionManager::Intersect(Triangle* pTriangle, Ray* pRay)

{

Vector3 edge1 = pTriangle->v1 - pTriangle->v0;

Vector3 edge2 = pTriangle->v2 - pTriangle->v0;

Vector3 pvec = Cross(pRay->mDir, edge2);

double det = Dot(edge1, pvec);

if(CULLING)

{

if(det < EPSILON){return Intersection();}

Vector3 tvec = pRay->mOrigin - pTriangle->v0;

double u = Dot(tvec, pvec);

if(u < 0.0f || u > det){return Intersection();}

Vector3 qvec = Cross(tvec, edge1);

double v = Dot(pRay->mDir, qvec);

if(v < 0.0f || u + v > det){return Intersection();}

float t = Dot(edge2, qvec) * (1.0f/(float)det);

pRay->mDistToIntersect = t;

return Intersection(pRay->mOrigin + (pRay->mDir * t), pTriangle->mNormal, pTriangle->mMaterial, Matrix4());

}

else

{

if(det > -EPSILON && det < EPSILON){ return Intersection();}

float invdet = 1.0f/det;

Vector3 tvec = pRay->mOrigin - pTriangle->v0;

float u = Dot(tvec, pvec) * invdet;

if(u < 0.0f || u > 1.0f){return Intersection();}

Vector3 qvec = Cross(tvec, edge1);

float v = Dot(pRay->mDir, qvec) * invdet;

if(v < 0.0f || u + v > 1.0f){return Intersection();}

float t = Dot(edge2, qvec) * invdet;

pRay->mDistToIntersect = t;

return Intersection(pRay->mOrigin + (pRay->mDir * t), pTriangle->mNormal, pTriangle->mMaterial, Matrix4());

}

}

and here is an image of the result, the model used has 2500 triangles

as you can see it doesn't render every other triangle, i already checked if my BVH was being filled correctly and if my model loader was working properly

thanks in advance!

here is the code i currently use:

Intersection IntersectionManager::Intersect(Triangle* pTriangle, Ray* pRay)

{

Vector3 edge1 = pTriangle->v1 - pTriangle->v0;

Vector3 edge2 = pTriangle->v2 - pTriangle->v0;

Vector3 pvec = Cross(pRay->mDir, edge2);

double det = Dot(edge1, pvec);

if(CULLING)

{

if(det < EPSILON){return Intersection();}

Vector3 tvec = pRay->mOrigin - pTriangle->v0;

double u = Dot(tvec, pvec);

if(u < 0.0f || u > det){return Intersection();}

Vector3 qvec = Cross(tvec, edge1);

double v = Dot(pRay->mDir, qvec);

if(v < 0.0f || u + v > det){return Intersection();}

float t = Dot(edge2, qvec) * (1.0f/(float)det);

pRay->mDistToIntersect = t;

return Intersection(pRay->mOrigin + (pRay->mDir * t), pTriangle->mNormal, pTriangle->mMaterial, Matrix4());

}

else

{

if(det > -EPSILON && det < EPSILON){ return Intersection();}

float invdet = 1.0f/det;

Vector3 tvec = pRay->mOrigin - pTriangle->v0;

float u = Dot(tvec, pvec) * invdet;

if(u < 0.0f || u > 1.0f){return Intersection();}

Vector3 qvec = Cross(tvec, edge1);

float v = Dot(pRay->mDir, qvec) * invdet;

if(v < 0.0f || u + v > 1.0f){return Intersection();}

float t = Dot(edge2, qvec) * invdet;

pRay->mDistToIntersect = t;

return Intersection(pRay->mOrigin + (pRay->mDir * t), pTriangle->mNormal, pTriangle->mMaterial, Matrix4());

}

}

and here is an image of the result, the model used has 2500 triangles

as you can see it doesn't render every other triangle, i already checked if my BVH was being filled correctly and if my model loader was working properly

thanks in advance!

Dave Schachtschabel - 121377

2GA - 2PR

2GA - 2PR

### Re: GRP1 discussion

Are you sure your model is triangulated? I've seen that same thing happen, because the model loader I used would load quads as triangles.

Wout van Poppel | 3GA-2PR

### Re: GRP1 discussion

I know the course has ended, but here's a render of a 8.9kk triangle model

Dave Schachtschabel - 121377

2GA - 2PR

2GA - 2PR

### Re: GRP1 discussion

Hi all,

The pretty image contest has been opened on ompf2.com:

http://ompf2.com/viewtopic.php?f=5&t=1892

Please note that if you register on that forum you will need to send me an e-mail to get your account activated.

That's an awesome forum btw, with lots of discussions on ray tracing. It's hosted here at IGAD.

- Jacco.

The pretty image contest has been opened on ompf2.com:

http://ompf2.com/viewtopic.php?f=5&t=1892

Please note that if you register on that forum you will need to send me an e-mail to get your account activated.

That's an awesome forum btw, with lots of discussions on ray tracing. It's hosted here at IGAD.

- Jacco.

### Who is online

Users browsing this forum: No registered users and 1 guest