diff options
| author | Karen Webb <karen.webb@umbralsoftware.co.uk> | 2025-01-22 02:32:23 +0000 |
|---|---|---|
| committer | Charles Giessen <46324611+charles-lunarg@users.noreply.github.com> | 2025-01-21 20:31:17 -0700 |
| commit | 8e675c28b8b47fd763e2c1e080cb78aaa4e1736a (patch) | |
| tree | 9f9932b04317a9ee5fdbf4cdc7652830c829f134 /cube/cube.frag | |
| parent | 26c7bde34a4a253004af427d92b27656e386effc (diff) | |
| download | usermoji-8e675c28b8b47fd763e2c1e080cb78aaa4e1736a.tar.xz | |
cube: Correctly apply sRGB OETF/EOTF
Diffstat (limited to 'cube/cube.frag')
| -rw-r--r-- | cube/cube.frag | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/cube/cube.frag b/cube/cube.frag index 5bf6507a..c68b9854 100644 --- a/cube/cube.frag +++ b/cube/cube.frag @@ -29,10 +29,26 @@ layout (location = 0) out vec4 uFragColor; const vec3 lightDir= vec3(0.424, 0.566, 0.707); +float linearToSrgb(float linear) { + if (linear <= 0.0031308) { + return linear * 12.92; + } else { + return (1.055 * pow(linear, 1.0/2.4)) - 0.055; + } +} + +vec3 linearToSrgb(vec3 linear) { + return vec3(linearToSrgb(linear.r), linearToSrgb(linear.g), linearToSrgb(linear.b)); +} + +vec4 linearToSrgb(vec4 linear) { + return vec4(linearToSrgb(linear.rgb), linear.a); +} + void main() { vec3 dX = dFdx(frag_pos); vec3 dY = dFdy(frag_pos); vec3 normal = normalize(cross(dX,dY)); float light = max(0.0, dot(lightDir, normal)); - uFragColor = light * texture(tex, texcoord.xy); + uFragColor = linearToSrgb(light * texture(tex, texcoord.xy)); } |
