diff options
| author | 3gg <3gg@shellblade.net> | 2026-02-16 09:49:45 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2026-02-16 09:49:45 -0800 |
| commit | dcb77dcaad1fb0be23bfadbaad688a7b7eb1135e (patch) | |
| tree | 60fba9740fa9620cbfbe853be77a16c3e4fe21d7 /src/swgfx.c | |
| parent | 117c310e8baf60aa5f052214e1747b5846f34b4e (diff) | |
Diffstat (limited to 'src/swgfx.c')
| -rw-r--r-- | src/swgfx.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/swgfx.c b/src/swgfx.c index 1901057..1e22ade 100644 --- a/src/swgfx.c +++ b/src/swgfx.c | |||
| @@ -96,8 +96,10 @@ static inline sgVec3 sub3(sgVec3 a, sgVec3 b) { return (sgVec3){a.x - b.x, a.y - | |||
| 96 | static inline sgVec3 mul3(sgVec3 a, sgVec3 b) { return (sgVec3){a.x * b.x, a.y * b.y, a.z * b.z}; } | 96 | static inline sgVec3 mul3(sgVec3 a, sgVec3 b) { return (sgVec3){a.x * b.x, a.y * b.y, a.z * b.z}; } |
| 97 | static inline sgVec3 div3(sgVec3 a, sgVec3 b) { return (sgVec3){a.x / b.x, a.y / b.y, a.z / b.z}; } | 97 | static inline sgVec3 div3(sgVec3 a, sgVec3 b) { return (sgVec3){a.x / b.x, a.y / b.y, a.z / b.z}; } |
| 98 | static inline sgVec3 scale3(sgVec3 v, R s) { return (sgVec3){v.x * s, v.y * s, v.z * s}; } | 98 | static inline sgVec3 scale3(sgVec3 v, R s) { return (sgVec3){v.x * s, v.y * s, v.z * s}; } |
| 99 | static inline sgVec3 lerp3(sgVec3 a, sgVec3 b, R t) { return add3(a, scale3(sub3(b,a), t)); } | 99 | static inline sgVec3 lerp3(sgVec3 a, sgVec3 b, R t) { return add3(a, scale3(sub3(b,a), t)); } |
| 100 | static inline sgVec3 exp3(sgVec3 v, R exp) { return (sgVec3){powf(v.x, exp), powf(v.y, exp), powf(v.z, exp)};} | 100 | static inline sgVec3 exp3(sgVec3 v, R exp) { return (sgVec3){powf(v.x, exp), powf(v.y, exp), powf(v.z, exp)};} |
| 101 | static inline sgVec3 square3(sgVec3 v) { return (sgVec3){v.x*v.x, v.y*v.y, v.z*v.z }; } | ||
| 102 | static inline sgVec3 sqrt3 (sgVec3 v) { return (sgVec3){sqrt(v.x), sqrt(v.y), sqrt(v.z) }; } | ||
| 101 | static inline R dot3(sgVec3 a, sgVec3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; } | 103 | static inline R dot3(sgVec3 a, sgVec3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; } |
| 102 | static inline R normsq3(sgVec3 v) { return v.x * v.x + v.y * v.y + v.z * v.z; } | 104 | static inline R normsq3(sgVec3 v) { return v.x * v.x + v.y * v.y + v.z * v.z; } |
| 103 | static inline R norm3 (sgVec3 v) { return (R)sqrt(normsq3(v)); } | 105 | static inline R norm3 (sgVec3 v) { return (R)sqrt(normsq3(v)); } |
| @@ -1058,23 +1060,22 @@ void sgNormals(swgfx* gfx) { | |||
| 1058 | } | 1060 | } |
| 1059 | } | 1061 | } |
| 1060 | 1062 | ||
| 1061 | void sgGamma(swgfx* gfx, sgTexel* texels, int width, int height) { | 1063 | void sgGamma(sgTexel* texels, int width, int height) { |
| 1062 | assert(gfx); | ||
| 1063 | assert(texels); | 1064 | assert(texels); |
| 1064 | constexpr R exp = 2.2f; | ||
| 1065 | for (int i = 0; i < width * height; ++i) { | 1065 | for (int i = 0; i < width * height; ++i) { |
| 1066 | sgTexel* const p = &texels[i]; | 1066 | sgTexel* const p = &texels[i]; |
| 1067 | *p = Colour3ToTexel(exp3(TexelToColour3(*p), exp), p->a); | 1067 | //*p = Colour3ToTexel(exp3(TexelToColour3(*p), 2.2f), p->a); |
| 1068 | *p = Colour3ToTexel(square3(TexelToColour3(*p)), p->a); | ||
| 1068 | } | 1069 | } |
| 1069 | } | 1070 | } |
| 1070 | 1071 | ||
| 1071 | void sgGammaInv(swgfx* gfx, sgColour4* pixels, int width, int height) { | 1072 | void sgGammaInv(sgColour4* pixels, int width, int height) { |
| 1072 | assert(gfx); | ||
| 1073 | assert(pixels); | 1073 | assert(pixels); |
| 1074 | constexpr R exp = 1.0f/2.2f; | ||
| 1075 | for (int i = 0; i < width * height; ++i) { | 1074 | for (int i = 0; i < width * height; ++i) { |
| 1076 | sgColour4* const p = &pixels[i]; | 1075 | sgColour4* const p = &pixels[i]; |
| 1077 | *p = Vec4FromVec3(exp3(Vec3FromVec4(*p), exp), p->a); | 1076 | // sqrt() is faster (~500us at 320x240) than pow(). |
| 1077 | //*p = Vec4FromVec3(exp3(Vec3FromVec4(*p), 1.0f/2.2f), p->a); | ||
| 1078 | *p = Vec4FromVec3(sqrt3(Vec3FromVec4(*p)), p->a); | ||
| 1078 | } | 1079 | } |
| 1079 | } | 1080 | } |
| 1080 | 1081 | ||
