Spectrum BSDF::evaluate_f(glm::vec3 outgoing_w, glm::vec3 incident_w) const { //translate world coords to local hemisphere coords glm::vec3 local_outgoing = world_to_local(outgoing_w); glm::vec3 local_incident = world_to_local(incident_w); Spectrum f; for (int i = 0; i < _brdf_count; ++i) { f += _brdfs[i]->evaluate_f(local_outgoing, local_incident) * _brdf_scales[i]; } return f; }
float BSDF::calc_pdf(const glm::vec3 &outgoing_w, const glm::vec3 &incident_w) const { glm::vec3 local_outgoing = world_to_local(outgoing_w); glm::vec3 local_incident = world_to_local(incident_w); float pdf = 0; for (int i = 0; i < _brdf_count; ++i) { pdf += _brdfs[i]->calc_pdf(local_outgoing, local_incident) * _brdf_scales[i]; } if (_brdf_count == 0) { return 1; } return pdf / _brdf_count; }
int point_at_world(struct robot *robot, struct vect *point) { struct vect local_point; world_to_local(robot, &local_point, point); return point_at_local(&robot->turret, &local_point); }
Spectrum BSDF::evaluate_sample_f(glm::vec3 outgoing_w, glm::vec3* incident_w, float u1, float u2, float* pdf) const { assert(u1 <= 1.0); if (_brdf_count < 1) { return Spectrum(0, 0, 0); } int brdf_num = glm::round(u1 * (_brdf_count-1)); BRDF* brdf = _brdfs[brdf_num]; glm::vec3 local_outgoing = world_to_local(outgoing_w); glm::vec3 local_incident; Spectrum f = brdf->evaluate_sample_f(local_outgoing, &local_incident, u1, u2, pdf) * _brdf_scales[brdf_num]; *incident_w = local_to_world(local_incident); return f; }
void get_up_vector(struct robot *robot, struct vect *result) { struct vect up, local_up, forward, look; up.x = robot->position2.position.x; up.y = robot->position2.position.y; up.z = 1; world_to_local(robot, &local_up, &up); forward.x = 0; forward.y = -1; forward.z = 0; struct vect normalized_look; rotate_vector(&look, &forward, &robot->turret.turret_rotation); // printf("%f, %f, %f\n", look.x, look.y, look.z); float normal; struct vect right_vector, raw; cross(&local_up, &look, &right_vector); // printf("%f, %f, %f\n", right_vector.x, right_vector.y, right_vector.z); // printf("%f\n", norm(&right_vector)); cross(&right_vector, &look, &raw); // printf("%f, %f, %f\n", raw.x, raw.y, raw.z); normal = norm(&raw); result->x = raw.x / normal; result->y = raw.y / normal; result->z = raw.z / normal; }