Skip to content

Commit

Permalink
Add precisions to saturation shader
Browse files Browse the repository at this point in the history
This hopefully fixes the code with ANGLE.
  • Loading branch information
guillaumechereau committed Aug 21, 2018
1 parent 7ae1091 commit 57e7efd
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/core/SaturationShader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@
static inline QString makeSaturationShader()
{
return R"(
vec3 rgb2hsv(vec3 c)
mediump vec3 rgb2hsv(mediump vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
mediump vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
mediump vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
mediump vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
mediump float d = q.x - min(q.w, q.y);
mediump float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hsv2rgb(vec3 c)
mediump vec3 hsv2rgb(mediump vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
mediump vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
mediump vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
vec3 saturate(vec3 c, float x)
mediump vec3 saturate(mediump vec3 c, mediump float x)
{
c = rgb2hsv(c);
c.y *= x;
return hsv2rgb(c);
}
vec4 saturate(vec4 c, float x)
mediump vec4 saturate(mediump vec4 c, mediump float x)
{
return vec4(saturate(c.rgb, x), c.a);
}
Expand Down

0 comments on commit 57e7efd

Please sign in to comment.