# HG changeset patch # User sam # Date 1723869255 -25200 # Node ID 41f3612ef38d89f86caee1814289fdde6cfaabc6 # Parent fa774f3dc15f8417872564a3d87a119932488916 fix: add gamma correction to hex-string-color-converter diff -r fa774f3dc15f -r 41f3612ef38d semicongine/core/vector.nim --- a/semicongine/core/vector.nim Fri Aug 16 23:41:57 2024 +0700 +++ b/semicongine/core/vector.nim Sat Aug 17 11:34:15 2024 +0700 @@ -79,7 +79,8 @@ func vec3i8*(): Vec3i8 = vec3i8(0, 0, 0) # shortcuts color -func toVec*(value: string): Vec4f = +func toVec*(value: string, gamma=2.2'f32): Vec4f = + # converts hex-string to color, also applies gamma of 2.2 assert value != "" var hex = value if hex[0] == '#': @@ -98,7 +99,7 @@ g = parseHexInt(hex[2 .. 3]).float32 / 255'f32 b = parseHexInt(hex[4 .. 5]).float32 / 255'f32 a = parseHexInt(hex[6 .. 7]).float32 / 255'f32 - return vec4(r, g, b, a) + return vec4(pow(r, gamma), pow(g, gamma), pow(b, gamma), a) const