Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/shader.cpp
| Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* maximal slope amplitude (range that contains 99.99% of the distribution) */ | /* maximal slope amplitude (range that contains 99.99% of the distribution) */ | ||||
| static float beckmann_table_slope_max() | static float beckmann_table_slope_max() | ||||
| { | { | ||||
| return 6.0; | return 6.0; | ||||
| } | } | ||||
| /* MSVC 2015 needs this ugly hack to prevent a codegen bug on x86 | |||||
| * see T50176 for details | |||||
| */ | |||||
| #if _MSC_VER==1900 | |||||
| # define MSVC_VOLATILE volatile | |||||
| #else | |||||
| # define MSVC_VOLATILE | |||||
| #endif | |||||
| /* Paper used: Importance Sampling Microfacet-Based BSDFs with the | /* Paper used: Importance Sampling Microfacet-Based BSDFs with the | ||||
| * Distribution of Visible Normals. Supplemental Material 2/2. | * Distribution of Visible Normals. Supplemental Material 2/2. | ||||
| * | * | ||||
| * http://hal.inria.fr/docs/01/00/66/20/ANNEX/supplemental2.pdf | * http://hal.inria.fr/docs/01/00/66/20/ANNEX/supplemental2.pdf | ||||
| */ | */ | ||||
| static void beckmann_table_rows(float *table, int row_from, int row_to) | static void beckmann_table_rows(float *table, int row_from, int row_to) | ||||
| { | { | ||||
| /* allocate temporary data */ | /* allocate temporary data */ | ||||
| const int DATA_TMP_SIZE = 512; | const int DATA_TMP_SIZE = 512; | ||||
| vector<double> slope_x(DATA_TMP_SIZE); | vector<double> slope_x(DATA_TMP_SIZE); | ||||
| vector<double> CDF_P22_omega_i(DATA_TMP_SIZE); | vector<double> CDF_P22_omega_i(DATA_TMP_SIZE); | ||||
| /* loop over incident directions */ | /* loop over incident directions */ | ||||
| for(int index_theta = row_from; index_theta < row_to; index_theta++) { | for(int index_theta = row_from; index_theta < row_to; index_theta++) { | ||||
| /* incident vector */ | /* incident vector */ | ||||
| const float cos_theta = index_theta / (BECKMANN_TABLE_SIZE - 1.0f); | const float cos_theta = index_theta / (BECKMANN_TABLE_SIZE - 1.0f); | ||||
| const float sin_theta = safe_sqrtf(1.0f - cos_theta*cos_theta); | const float sin_theta = safe_sqrtf(1.0f - cos_theta*cos_theta); | ||||
| /* for a given incident vector | /* for a given incident vector | ||||
| * integrate P22_{omega_i}(x_slope, 1, 1), Eq. (10) */ | * integrate P22_{omega_i}(x_slope, 1, 1), Eq. (10) */ | ||||
| slope_x[0] = (double)-beckmann_table_slope_max(); | slope_x[0] = (double)-beckmann_table_slope_max(); | ||||
| CDF_P22_omega_i[0] = 0; | CDF_P22_omega_i[0] = 0; | ||||
| for(int index_slope_x = 1; index_slope_x < DATA_TMP_SIZE; ++index_slope_x) { | for(MSVC_VOLATILE int index_slope_x = 1; index_slope_x < DATA_TMP_SIZE; ++index_slope_x) { | ||||
| /* slope_x */ | /* slope_x */ | ||||
| slope_x[index_slope_x] = (double)(-beckmann_table_slope_max() + 2.0f * beckmann_table_slope_max() * index_slope_x/(DATA_TMP_SIZE - 1.0f)); | slope_x[index_slope_x] = (double)(-beckmann_table_slope_max() + 2.0f * beckmann_table_slope_max() * index_slope_x/(DATA_TMP_SIZE - 1.0f)); | ||||
| /* dot product with incident vector */ | /* dot product with incident vector */ | ||||
| float dot_product = fmaxf(0.0f, -(float)slope_x[index_slope_x]*sin_theta + cos_theta); | float dot_product = fmaxf(0.0f, -(float)slope_x[index_slope_x]*sin_theta + cos_theta); | ||||
| /* marginalize P22_{omega_i}(x_slope, 1, 1), Eq. (10) */ | /* marginalize P22_{omega_i}(x_slope, 1, 1), Eq. (10) */ | ||||
| float P22_omega_i = 0.0f; | float P22_omega_i = 0.0f; | ||||
| Show All 27 Lines | for(int index_U = 0; index_U < BECKMANN_TABLE_SIZE; ++index_U) { | ||||
| /* store value */ | /* store value */ | ||||
| table[index_U + index_theta*BECKMANN_TABLE_SIZE] = (float)( | table[index_U + index_theta*BECKMANN_TABLE_SIZE] = (float)( | ||||
| interp * slope_x[index_slope_x - 1] + | interp * slope_x[index_slope_x - 1] + | ||||
| (1.0 - interp) * slope_x[index_slope_x]); | (1.0 - interp) * slope_x[index_slope_x]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #undef MSVC_VOLATILE | |||||
| static void beckmann_table_build(vector<float>& table) | static void beckmann_table_build(vector<float>& table) | ||||
| { | { | ||||
| table.resize(BECKMANN_TABLE_SIZE*BECKMANN_TABLE_SIZE); | table.resize(BECKMANN_TABLE_SIZE*BECKMANN_TABLE_SIZE); | ||||
| /* multithreaded build */ | /* multithreaded build */ | ||||
| TaskPool pool; | TaskPool pool; | ||||
| for(int i = 0; i < BECKMANN_TABLE_SIZE; i+=8) | for(int i = 0; i < BECKMANN_TABLE_SIZE; i+=8) | ||||
| ▲ Show 20 Lines • Show All 493 Lines • Show Last 20 Lines | |||||