Advertisement
Advertisement
| 05.17.2008 at 11:47PM PDT, ID: 23411535 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: |
RGBA rayColor(Ray ray, HitRecord hit, int depth, float n1)
{
....*Code that Calculates diffuse and specular components of each ray for every light in the scene*.....
.......
.....
//Use Beer's law to claculate absorbance and transmittance coefficient
float dist = distanceBetweenPoints(ray.origin,hit.intersection.point);
RGBA a =(ray.color*EPSILON)*(-dist);
RGBA k;
k.r = exp(a.r)*hit.intersection.obj.mat.refractivity;
k.b = exp(a.b)*hit.intersection.obj.mat.refractivity;
k.g = exp(a.g)*hit.intersection.obj.mat.refractivity;
k.a = exp(a.a)*hit.intersection.obj.mat.refractivity;
//Calculate reflectance
float R_0 = (n1-hit.intersection.obj.mat.refractivity)/(n1+hit.intersection.obj.mat.refractivity);
R_0 = pow(R_0,2);
float cosTheta = dot(eye,hit.normal);
float RTheta = R_0 + (1.0 - R_0) * pow(1.0 - cosTheta, 5.0);
if (hit.intersection.obj.mat.material_specular.r != 0 ||
hit.intersection.obj.mat.material_specular.g != 0 ||
hit.intersection.obj.mat.material_specular.b != 0 ||
hit.intersection.obj.mat.material_specular.a != 0) {
//Get intersectionpoint
vec3 intersect;
intersect.x = hit.intersection.point.x;
intersect.y = hit.intersection.point.y;
intersect.z = hit.intersection.point.z;
vec3 refDirection = (ray.direction - 2 * (dot(hit.normal, ray.direction) * hit.normal));
normalize(refDirection);
refRay = generateRay(intersect + EPSILON * refDirection,refDirection);
shootRay(refRay,refRecord);
float objreflectivity = hit.intersection.obj.mat.reflectivity;
float objrefractivity = hit.intersection.obj.mat.refractivity;
ray.color = ray.color + hit.intersection.obj.mat.material_specular*rayColor(refRay,refRecord,depth + 1,1.0);
if(hit.intersection.obj.mat.refractivity!=0)
{
bool notTotallyReflective = generateTransmissionRay(ray, hit, n1,transray);
if(notTotallyReflective)
{
shootRay(transray,transRecord);
//ray.color = ray.color + k*rayColor(transray,transRecord,depth + 1,hit.intersection.obj.mat.refractivity);
}
}
}
if (ray.color.r > 1)
ray.color.r = 1;
if (ray.color.b > 1)
ray.color.b = 1;
if (ray.color.g > 1)
ray.color.g = 1;
return ray.color;
}
|