mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-24 16:48:18 -05:00
Added toLinear/GammaAccurate shader functions.
This commit is contained in:
parent
b8d065da79
commit
8c1518f259
1 changed files with 26 additions and 0 deletions
|
@ -183,6 +183,19 @@ vec4 toLinear(vec4 _rgba)
|
|||
return vec4(toLinear(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toLinearAccurate(vec3 _rgb)
|
||||
{
|
||||
vec3 lo = _rgb / 12.92;
|
||||
vec3 hi = pow( (_rgb + 0.055) / 1.055, vec3_splat(2.4) );
|
||||
vec3 rgb = mix(hi, lo, vec3(lessThanEqual(_rgb, vec3_splat(0.04045) ) ) );
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec4 toLinearAccurate(vec4 _rgba)
|
||||
{
|
||||
return vec4(toLinearAccurate(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
float toGamma(float _r)
|
||||
{
|
||||
return pow(abs(_r), 1.0/2.2);
|
||||
|
@ -198,6 +211,19 @@ vec4 toGamma(vec4 _rgba)
|
|||
return vec4(toGamma(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toGammaAccurate(vec3 _rgb)
|
||||
{
|
||||
vec3 lo = _rgb * 12.92;
|
||||
vec3 hi = pow(abs(_rgb), vec3_splat(1.0/2.4) ) * 1.055 - 0.055;
|
||||
vec3 rgb = mix(hi, lo, vec3(lessThanEqual(_rgb, vec3_splat(0.0031308) ) ) );
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec4 toGammaAccurate(vec4 _rgba)
|
||||
{
|
||||
return vec4(toGammaAccurate(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toReinhard(vec3 _rgb)
|
||||
{
|
||||
return toGamma(_rgb/(_rgb+vec3_splat(1.0) ) );
|
||||
|
|
Loading…
Reference in a new issue