Skip to content

Commit

Permalink
Fix textures not being converted to linear RGB
Browse files Browse the repository at this point in the history
Previously, textures were being loaded in as SRGB and then used by the
lighting calculations as if they were in a linear RGB colour space. This
was resulting in the textures looking somewhat too bright.

Instead, textures are now converted into linear RGB with gamma 2.2 when
being loaded from their respective image.
  • Loading branch information
aviansie-ben committed Dec 17, 2017
1 parent 8b01462 commit 02f6828
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/texture.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cmath>
#include <sstream>

#include <stb_image.h>
Expand Down Expand Up @@ -26,9 +27,9 @@ namespace hw4 {
int off = y * width + x;

data_copy[off] = glm::vec3(
static_cast<float>(data[off * 3]) / 255,
static_cast<float>(data[off * 3 + 1]) / 255,
static_cast<float>(data[off * 3 + 2]) / 255
std::pow(static_cast<float>(data[off * 3]) / 255, 2.2),
std::pow(static_cast<float>(data[off * 3 + 1]) / 255, 2.2),
std::pow(static_cast<float>(data[off * 3 + 2]) / 255, 2.2)
);
}
}
Expand Down

0 comments on commit 02f6828

Please sign in to comment.