graphics - glossy reflection in ray tracing -
i doing project ray tracing, right can basic rendering.
the image below have:
mirror reflection, refraction, texture mapping , shadow.

i trying glossy reflection, far getting. tell me if there problem in glossy reflection image?

in comparison, image below mirror reflection

this code glossy reflection, basically, once primary ray intersect object. intersection, randomly shot 80 rays, , take average of 80 rays color. problem having code magnitude of x , y, have divide them value, in case 16, such glossy reflect ray wouldn't random. there wrong logic?
colour c(0, 0, 0); (int = 0; < 80; i++) { ray3d testray; double = rand() / (double) rand_max; double b = rand() / (double) rand_max; double theta = acos(pow((1 - a), ray.intersection.mat->reflectivity)); double phi = 2 * m_pi * b; double x = sin(phi) * cos(theta)/16; double y = sin(phi) * sin(theta)/16; double z = cos(phi); vector3d u = reflect.dir.cross(ray.intersection.normal); vector3d v = reflect.dir.cross(u); testray.dir = x * u + y * v + reflect.dir; testray.dir.normalize(); testray.origin = reflect.origin; testray.nbounces = reflect.nbounces; c = c + (ray.intersection.mat->reflectivity)*shaderay(testray); } col = col + c / 80;
apart hard coded constants never great when coding, there more subtle issue, although images overall good.
monte-carlo integration consists in summing integrand divided probability density function (pdf) generated these samples. there 2 problems in code:
- you haven't divided pdf although seem have used pdf phong models (if recognized ; @ least not uniform pdf)
- you have further scaled
x,ycomponents1./16.apparently no reason further changes pdf.
the idea if able sample rays according phong's model times cosine law don't have multiply integrand brdf. in practice, there no exact formula allow sample brdf (apart lambertian ones), need compute:
pixel value = sum brdf*cosine*incoming_light / pdf
cancels out if brdf*cosine = pdf.
of course, images overall good, if you're not interested in physical plausibility, may good.
source various pdfs used in computer graphics , monte-carlo integration (with appropriate formulas) global illumination compendium philip dutré.
Comments
Post a Comment