Skip to content

Commit

Permalink
Linearize colors in frag shader
Browse files Browse the repository at this point in the history
  • Loading branch information
mkskelet committed Apr 10, 2023
1 parent fbad122 commit bd61569
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion backends/vulkan/glsl_shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ layout(location = 0) in struct {
vec2 UV;
} In;

vec4 to_linear(vec4 sRGB)
{
bvec3 cutoff = lessThan(sRGB.rgb, vec3(0.04045));
vec3 higher = pow((sRGB.rgb + vec3(0.055)) / vec3(1.055), vec3(2.4));
vec3 lower = sRGB.rgb / vec3(12.92);

return vec4(mix(higher, lower, cutoff), sRGB.a);
}

void main()
{
fColor = In.Color * texture(sTexture, In.UV.st);
fColor = to_linear(In.Color) * to_linear(texture(sTexture, In.UV.st));
}

0 comments on commit bd61569

Please sign in to comment.