2014-02-13 23:46:34 -05:00
|
|
|
$input v_dir
|
|
|
|
|
|
|
|
/*
|
2016-02-28 19:15:12 -05:00
|
|
|
* Copyright 2014-2016 Dario Manesku. All rights reserved.
|
2016-01-01 03:11:04 -05:00
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
2014-02-13 23:46:34 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../common/common.sh"
|
2016-02-28 19:15:12 -05:00
|
|
|
#include "uniforms.sh"
|
2014-02-13 23:46:34 -05:00
|
|
|
|
2015-06-06 20:12:29 -04:00
|
|
|
SAMPLERCUBE(s_texCube, 0);
|
2016-02-28 19:15:12 -05:00
|
|
|
SAMPLERCUBE(s_texCubeIrr, 1);
|
2014-02-13 23:46:34 -05:00
|
|
|
|
2016-02-28 19:15:12 -05:00
|
|
|
// Ref: http://the-witness.net/news/2012/02/seamless-cube-map-filtering/
|
|
|
|
vec3 fixCubeLookup(vec3 _v, float _lod, float _topLevelCubeSize)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2014-02-13 23:46:34 -05:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 dir = normalize(v_dir);
|
|
|
|
|
2016-02-28 19:15:12 -05:00
|
|
|
vec4 color;
|
|
|
|
if (u_bgType == 7.0)
|
|
|
|
{
|
|
|
|
color = toLinear(textureCube(s_texCubeIrr, dir));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float lod = u_bgType;
|
|
|
|
dir = fixCubeLookup(dir, lod, 256.0);
|
|
|
|
color = toLinear(textureCubeLod(s_texCube, dir, lod));
|
|
|
|
}
|
2014-02-13 23:46:34 -05:00
|
|
|
color *= exp2(u_exposure);
|
|
|
|
|
|
|
|
gl_FragColor = toFilmic(color);
|
|
|
|
}
|