// Copyright 2016 Activision Publishing, Inc. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the Software // is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #define BASE_RESOLUTION 128 #define PROBE_REFLECTION_MIPS 7 #define PROBE_REFLECTION_MIPS_FULL 8 float R_SpecParamFromGloss( float gloss ) { const float GGX_MAX_SPEC_POWER = 18; float exponent = powf( 2.0f, gloss * GGX_MAX_SPEC_POWER ); // returns roughness == sqrt(alpha) for GGX physically-based shader return powf( 2.0f / ( 1 + exponent ), .25f ); } void create_cubemap_level_params(vector &level_params) { for (int mip = 0; mip < PROBE_REFLECTION_MIPS; ++mip) { const float ENVMAP_MIPLEVEL_0_PB = 6.0f; const float ENVMAP_MIPLEVEL_1_PB = 0.0f; level_params[mip].level = mip; level_params[mip].gloss = (ENVMAP_MIPLEVEL_0_PB - mip) / (ENVMAP_MIPLEVEL_0_PB - ENVMAP_MIPLEVEL_1_PB); level_params[mip].roughness = R_SpecParamFromGloss(level_params[mip].gloss); level_params[mip].res = BASE_RESOLUTION >> mip; } }