changeset 1326:41f3612ef38d

fix: add gamma correction to hex-string-color-converter
author sam <sam@basx.dev>
date Sat, 17 Aug 2024 11:34:15 +0700
parents fa774f3dc15f
children 373a4888f6ac
files semicongine/core/vector.nim
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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