Technique : base("ReflectionCubemap") = { Language = "HLSL11"; Pass = { Common = { #define REFLECTION_MIP_OFFSET 2 /** * Calculates a mip level to sample from based on roughness value. * * @param roughness Roughness in range [0, 1]. Higher values yield more roughness. * @param numMips Total number of mip-map levels in the texture we'll be sampling from. * @return Index of the mipmap level to sample. */ float getMipFromRoughness(float roughness, float numMips) { // Note: This is just a heuristic as we don't calculate the exact size of the specular lobe, // and neither do our filtered maps // We add an offset because we want to ignore the highest few mip levels return numMips - 1 - REFLECTION_MIP_OFFSET - log2(roughness); } }; }; }; Technique : base("ReflectionCubemap") = { Language = "GLSL"; Pass = { Common = { #define REFLECTION_MIP_OFFSET 2 /** * Calculates a mip level to sample from based on roughness value. * * @param roughness Roughness in range [0, 1]. Higher values yield more roughness. * @param numMips Total number of mip-map levels in the texture we'll be sampling from. * @return Index of the mipmap level to sample. */ void getMipFromRoughness(float roughness, float numMips, out float mipLevel) { // Note: This is just a heuristic as we don't calculate the exact size of the specular lobe, // and neither do our filtered maps // We add an offset because we want to ignore the highest few mip levels mipLevel = numMips - 1 - REFLECTION_MIP_OFFSET - log2(roughness); } }; }; };