Jump to content
  • Advertisement
Sign in to follow this  
saghi.sharif

Monte carlo path tracing

This topic is 2567 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

Hi,

I'm trying to implement Monte Carlo path tracing with importance sampling by dividing the equation into 2parts : direct illumination and indirect illumination. I'm using phong BRDF sampling for importance sampling. The problem that I have is with the glossy objects, all of them have a black line in the border. and it seems that the refraction is not completely correct and doesn't give the feeling of glass. Do you have any idea what the problem can be?

Share this post


Link to post
Share on other sites
Advertisement

Hi,

I'm trying to implement Monte Carlo path tracing with importance sampling by dividing the equation into 2parts : direct illumination and indirect illumination. I'm using phong BRDF sampling for importance sampling. The problem that I have is with the glossy objects, all of them have a black line in the border. and it seems that the refraction is not completely correct and doesn't give the feeling of glass. Do you have any idea what the problem can be?


I've never implemented refraction in a raytracer before, but i'll take a stab in the dark and pose the question anyway; have you offset the position of the refracted rays by epsilon to prevent self-intersection at the ray's origin?

Share this post


Link to post
Share on other sites
Glass (and any other insulator) should have pretty intense reflection along glancing angles, due to fresnel effect. Have you implemented that?

Share this post


Link to post
Share on other sites
As the red wall is visible on both sides and the top of the sphere, there's even a speck in the middle (or is there perhaps a ball behind it?, EDIT: yepp, there's a shadow there, but the refracted ball has a strange inverted look it seems?), and green is nowhere to be seen. To me it seems like you must have some error in how you refract rays coming into the sphere.

Also, I have little hands on experience with raytracers... so while I do understand the reason for the image being grainy... it seems to me that red and green walls having such significant amounts of gray in them is a more fundamental issue... but perhaps I'm missing something important here.

Share this post


Link to post
Share on other sites
I would suggest you start with a fully specular (chrome) sphere. the circular red before it becomes black looks somehow wrong, like you'd splat one vector component into xyz (e.g. doing dot instead of mul).




Share this post


Link to post
Share on other sites
[quote name='Saghi' timestamp='1323353013' post='4891784']
Hi,

I'm trying to implement Monte Carlo path tracing with importance sampling by dividing the equation into 2parts : direct illumination and indirect illumination. I'm using phong BRDF sampling for importance sampling. The problem that I have is with the glossy objects, all of them have a black line in the border. and it seems that the refraction is not completely correct and doesn't give the feeling of glass. Do you have any idea what the problem can be?


I've never implemented refraction in a raytracer before, but i'll take a stab in the dark and pose the question anyway; have you offset the position of the refracted rays by epsilon to prevent self-intersection at the ray's origin?
[/quote]

Yes I have moved it a bit further in the ray direction but I still have this problem.

Share this post


Link to post
Share on other sites

As the red wall is visible on both sides and the top of the sphere, there's even a speck in the middle (or is there perhaps a ball behind it?, EDIT: yepp, there's a shadow there, but the refracted ball has a strange inverted look it seems?), and green is nowhere to be seen. To me it seems like you must have some error in how you refract rays coming into the sphere.

Also, I have little hands on experience with raytracers... so while I do understand the reason for the image being grainy... it seems to me that red and green walls having such significant amounts of gray in them is a more fundamental issue... but perhaps I'm missing something important here.


This is how I'm calculating the refractive ray :



if (alpha < m_scene.m_vMaterials[mindex]->kr) //transmission
{
double nT = m_scene.m_vMaterials[mindex]->nT;
double nC = 1.0;
bool TotalRef = false;
Vector3f refractionDir;


refr = true;

if (!bInside)
{
refractionDir = GetRefraction(normal,reindir,nC,nT,TotalRef);
raydir = (getSpecularRay(refractionDir, spec)*(1.0-spec))+ (refractionDir*spec);
raydir.normalize();
cont = true;
Scale = indir * normal;
}
else
{
Scale = indir * normal*(-1.0);
refractionDir = GetRefraction(normal * (-1.0),reindir,nT,nC,TotalRef);

raydir = refractionDir;
cont = true;
if (TotalRef)
{

cont = false;
}

}

}




and the functions that I've used are:



Vector3f Render::getSpecularRay(const Vector3f &reflectionDir, const double specular)
{
double n = 2000;
double r1 = double(rand()) / ((double)RAND_MAX);
double phi = r1 * M_PI * 2.0;
double r2 = double(rand()) / (double(RAND_MAX));
double theta = acos(pow(r2, 1/(1+n)));

//Vector3f specularray1(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
Vector3f specularray1(cos(theta) * sin(phi), sin(theta) * sin(phi), cos(phi));
double el = -acos(reflectionDir[2]);
double az = -atan2(reflectionDir[1], reflectionDir[0]);


// Y Rot
Vector3f specularray2(cos(el) * specularray1[0] - sin(el) * specularray1[2], specularray1[2], sin(el) * specularray1[0] + cos(el) * specularray1[2]);

// Z Rot
Vector3f specularray(cos(az) * specularray2[0] + sin(az) * specularray2[1], -sin(az) * specularray2[0] + cos(az) * specularray2[1], specularray2[2]);
specularray.normalize();
return specularray2;
}


Vector3f Render::GetRefraction( Vector3f &Nx,Vector3f &I, double n1 , double n2 , bool & InterRef )
{

double Ratio = n1/n2;
I.normalize();
Nx.normalize();

double cosTetha1 = -(Nx*I);

// Calculate refraction dir
double cosTetha2 = 1.0 - Ratio*Ratio*(1.0-(cosTetha1*cosTetha1));

// Brewster's angle
if (cosTetha2 < 0.0) //Tota; internal reflection
{
InterRef = true;
return Vector3f(0,0,0);
}

cosTetha2 = double(sqrtf(cosTetha2));

Vector3f r((I*Ratio)+ Nx *( Ratio*cosTetha1-cosTetha2));
r.normalize();

InterRef = false;

return r;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!