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:
now, specular highlights should little more these:
as understand, lighting model (for these diffuse spheres) looks this:
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
Post a Comment