diff options
Diffstat (limited to '3rdparty/bgfx/examples/common/shaderlib.sh')
-rw-r--r-- | 3rdparty/bgfx/examples/common/shaderlib.sh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/3rdparty/bgfx/examples/common/shaderlib.sh b/3rdparty/bgfx/examples/common/shaderlib.sh index a6a51199a1f..51f9b6a445f 100644 --- a/3rdparty/bgfx/examples/common/shaderlib.sh +++ b/3rdparty/bgfx/examples/common/shaderlib.sh @@ -367,4 +367,20 @@ float random(vec2 _uv) return fract(sin(dot(_uv.xy, vec2(12.9898, 78.233) ) ) * 43758.5453); } +vec3 fixCubeLookup(vec3 _v, float _lod, float _topLevelCubeSize) +{ + // Reference: + // Seamless cube-map filtering + // http://the-witness.net/news/2012/02/seamless-cube-map-filtering/ + float ax = abs(_v.x); + float ay = abs(_v.y); + float az = abs(_v.z); + float vmax = max(max(ax, ay), az); + float scale = 1.0 - exp2(_lod) / _topLevelCubeSize; + if (ax != vmax) { _v.x *= scale; } + if (ay != vmax) { _v.y *= scale; } + if (az != vmax) { _v.z *= scale; } + return _v; +} + #endif // __SHADERLIB_SH__ |