diff options
author | Michael Brasser <mbrasser@ford.com> | 2020-03-24 10:07:15 -0500 |
---|---|---|
committer | Michael Brasser <mbrasser@ford.com> | 2020-03-27 07:58:28 -0500 |
commit | adc9c3e6ab2cdda50cce6d2623959adf94f7845e (patch) | |
tree | dc1b798894522ac15a205d2d488414c050a9b141 /src/extras/shaders/gl3 | |
parent | 4d1ca5a7afc78ad4676d54ff168170bd7abe7273 (diff) |
Implement MetalRough shader optimization TODO
Calculate specularMipLevels only once, on the CPU.
Change-Id: I694e3d5e45ea369875ac3ecff36f885b3f669bcf
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/extras/shaders/gl3')
-rw-r--r-- | src/extras/shaders/gl3/light.inc.frag | 1 | ||||
-rw-r--r-- | src/extras/shaders/gl3/metalrough.inc.frag | 11 |
2 files changed, 2 insertions, 10 deletions
diff --git a/src/extras/shaders/gl3/light.inc.frag b/src/extras/shaders/gl3/light.inc.frag index 0b642638f..a1b07a976 100644 --- a/src/extras/shaders/gl3/light.inc.frag +++ b/src/extras/shaders/gl3/light.inc.frag @@ -20,6 +20,7 @@ uniform int lightCount; struct EnvironmentLight { samplerCube irradiance; // For diffuse contribution samplerCube specular; // For specular contribution + int specularMipLevels; }; uniform EnvironmentLight envLight; uniform int envLightCount = 0; diff --git a/src/extras/shaders/gl3/metalrough.inc.frag b/src/extras/shaders/gl3/metalrough.inc.frag index f7e3eecb7..f5fb81f51 100644 --- a/src/extras/shaders/gl3/metalrough.inc.frag +++ b/src/extras/shaders/gl3/metalrough.inc.frag @@ -55,13 +55,6 @@ uniform float gamma = 2.2; #pragma include light.inc.frag -int mipLevelCount(const in samplerCube cube) -{ - int baseSize = textureSize(cube, 0).x; - int nMips = int(log2(float(baseSize > 0 ? baseSize : 1))) + 1; - return nMips; -} - float remapRoughness(const in float roughness) { // As per page 14 of @@ -87,10 +80,8 @@ float alphaToMipLevel(float alpha) const float k1 = 0.9921; float glossiness = (pow(2.0, -10.0 / sqrt(specPower)) - k0) / k1; - // TODO: Optimize by doing this on CPU and set as - // uniform int envLight.specularMipLevels say (if present in shader). // Lookup the number of mips in the specular envmap - int mipLevels = mipLevelCount(envLight.specular); + int mipLevels = envLight.specularMipLevels; // Offset of smallest miplevel we should use (corresponds to specular // power of 1). I.e. in the 32x32 sized mip. |