// add diffuse and ambient lighting public void add_das(Vec3 normal, Geometry o, Vec3 light) { int s = 64; // the size of the specular lighting // diffuse and ambient factor = surface N * light N normal.normalize(); double theta = normal.dot(light); if (theta < 0.0) { theta = 0.0; } ret_color.diffuse_ambient(theta); // blinn phon specular model Vec3 eyeN = Program.proj.eye.get_normalized(); Vec3 h = eyeN.add(light); h.normalize(); double b = Math.Max(normal.dot(h), 0.0); // TODO add a shiny/diffuse factor for the object double amount = Math.Pow(b, s); ret_color.specular(amount, Program.scene.ls, o.shininess); }
public void add_reflection(Vec3 hit_point, Geometry o, int recursion_level) { Vec3 n = o.get_surface_n(hit_point); // reflection = 2(n · v)n - v Vec3 r_dir = n.scale((2 * n.dot(Program.proj.eye))).subtract(Program.proj.eye); r_dir.normalize(); Ray reflection = new Ray(hit_point, r_dir); reflection.prev_hit_id = o.get_id(); //System.out.println("Level: " + recursion_level); bool r_hit = reflection.trace(recursion_level + 1); if (r_hit) { // add in reflection reflection.ret_color.scalar_update(o.reflectiveness); this.ret_color.add_reflection(reflection.ret_color); } }