java - Sphere raytracing - specular highlights -


i having trouble getting lighting model correct spheres. specifically, can't specular highlights spheres correct. here seeing when raytrace spheres:
wrong specular highlights

now, specular highlights should little more these:
correct specular highlights

as understand, lighting model (for these diffuse spheres) looks this:
lighting model

where cr color of sphere, ca ambient component of light, cl color of light, n normal @ point of intersection on sphere, l direction of light, cp color of specular highlight, e eye/look from, r reflection vector off surface of sphere, , p in exponent refers phong constant/exponent (how tight/loose lightlight is).

here process:

public color calculateilluminationmodel(vector normal, scene scene) {     //c = cr * ca + cr * cl * max(0, n \dot l)) + cl * cp * max(0, e \dot r)^p     vector lightsourcecolor = getcolorvector(scene.getlight().getlightcolor()); //cl     vector diffusereflectancecolor = getcolorvector(getmaterialcolor()); //cr     vector ambientcolor = getcolorvector(scene.getlight().getambientlightcolor()); //ca     vector specularhighlightcolor = getcolorvector(getspecularhighlight()); //cp     vector directiontolight = scene.getlight().getdirectiontolight(); //l     vector reflectionvector = normal.multiply(2).multiply(normal.crossproduct(directiontolight)).subtract(directiontolight); //r = 2n(n \dot l) - l      vector ambientterm = diffusereflectancecolor.multiply(ambientcolor);     double anglebetweenlightandnormal = directiontolight.dotproduct(normal);     vector diffuseterm = diffusereflectancecolor.multiply(lightsourcecolor).multiply(math.max(0, anglebetweenlightandnormal));     vector phongterm = lightsourcecolor.multiply(specularhighlightcolor).multiply(math.pow(math.max(0, scene.getcamerasettings().getlookfrom().dotproduct(reflectionvector)), (double) getphongconstant()));     return getvectorcolor(ambientterm.add(diffuseterm).add(phongterm)); } 

note in case, eye component phong term camera's from, (0, 0, 1), , direction light (1, 0, 0).

any ideas why specular highlights on top of spheres instead of facing direction of light?

let me know if let out important details need me out.

reflection vector should calculated based on surface normal , incoming ray direction, not on light direction now.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -