// Copyright 2005 Mitsubishi Electric Research Laboratories All Rights Reserved. // Permission to use, copy and modify this software and its documentation without // fee for educational, research and non-profit purposes, is hereby granted, provided // that the above copyright notice and the following three paragraphs appear in all copies. // To request permission to incorporate this software into commercial products contact: // Vice President of Marketing and Business Development; // Mitsubishi Electric Research Laboratories (MERL), 201 Broadway, Cambridge, MA 02139 or // . // IN NO EVENT SHALL MERL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, // OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND // ITS DOCUMENTATION, EVEN IF MERL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. // MERL SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED // HEREUNDER IS ON AN "AS IS" BASIS, AND MERL HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, // UPDATES, ENHANCEMENTS OR MODIFICATIONS. #include "common/brdfread.h" BRDFRead::BRDFRead(const char *filename) { if (!readBrdf(filename)) { std::cerr << "Cannot read BRDF file: " << filename << std::endl; exit(0); } } Color BRDFRead::lookupBrdfValues(double theta_in, double phi_in, double theta_out, double phi_out) { // std::cerr << theta_in << "," << theta_out; // Convert to halfangle / difference angle coordinates double theta_half, phi_half, theta_diff, phi_diff; std_coords_to_half_diff_coords(theta_in, phi_in, theta_out, phi_out, theta_half, phi_half, theta_diff, phi_diff); // Find index. // Note that phi_half is ignored, since isotropic BRDFs are assumed int ind = phi_diff_index(phi_diff) + theta_diff_index(theta_diff) * BRDF_SAMPLING_RES_PHI_D / 2 + theta_half_index(theta_half) * BRDF_SAMPLING_RES_PHI_D / 2 * BRDF_SAMPLING_RES_THETA_D; Color color; color.r = static_cast(brdfData[ind] * RED_SCALE); color.g = static_cast( brdfData[ind + BRDF_SAMPLING_RES_THETA_H * BRDF_SAMPLING_RES_THETA_D * BRDF_SAMPLING_RES_PHI_D / 2] * GREEN_SCALE); color.b = static_cast( brdfData[ind + BRDF_SAMPLING_RES_THETA_H * BRDF_SAMPLING_RES_THETA_D * BRDF_SAMPLING_RES_PHI_D] * BLUE_SCALE); // std::cerr << red_val << "," <= BRDF_SAMPLING_RES_THETA_H) ret_val = BRDF_SAMPLING_RES_THETA_H - 1; return ret_val; } int BRDFRead::theta_diff_index(double theta_diff) { int tmp = int(theta_diff / (M_PI * 0.5) * BRDF_SAMPLING_RES_THETA_D); if (tmp < 0) return 0; else if (tmp < BRDF_SAMPLING_RES_THETA_D - 1) return tmp; else return BRDF_SAMPLING_RES_THETA_D - 1; } int BRDFRead::phi_diff_index(double phi_diff) { // Because of reciprocity, the BRDF is unchanged under // phi_diff -> phi_diff + M_PI if (phi_diff < 0.0) phi_diff += M_PI; // In: phi_diff in [0 .. pi] // Out: tmp in [0 .. 179] int tmp = int(phi_diff / M_PI * BRDF_SAMPLING_RES_PHI_D / 2); if (tmp < 0) return 0; else if (tmp < BRDF_SAMPLING_RES_PHI_D / 2 - 1) return tmp; else return BRDF_SAMPLING_RES_PHI_D / 2 - 1; }