mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
The material colors for diffuse and emissive are now gamma corrected by default
This commit is contained in:
parent
1b1365fd40
commit
7bc815448e
3 changed files with 35 additions and 16 deletions
|
@ -44,9 +44,9 @@ Material& Material::operator= (const Material& material) {
|
|||
Material::~Material() {
|
||||
}
|
||||
|
||||
void Material::setDiffuse(const Color& diffuse) {
|
||||
void Material::setDiffuse(const Color& diffuse, bool isSRGB) {
|
||||
_key.setDiffuse(glm::any(glm::greaterThan(diffuse, Color(0.0f))));
|
||||
_schemaBuffer.edit<Schema>()._diffuse = diffuse;
|
||||
_schemaBuffer.edit<Schema>()._diffuse = (isSRGB ? ColorUtils::toLinearVec3(diffuse) : diffuse);
|
||||
}
|
||||
|
||||
void Material::setMetallic(float metallic) {
|
||||
|
@ -54,9 +54,9 @@ void Material::setMetallic(float metallic) {
|
|||
_schemaBuffer.edit<Schema>()._metallic = glm::vec3(metallic);
|
||||
}
|
||||
|
||||
void Material::setEmissive(const Color& emissive) {
|
||||
void Material::setEmissive(const Color& emissive, bool isSRGB) {
|
||||
_key.setEmissive(glm::any(glm::greaterThan(emissive, Color(0.0f))));
|
||||
_schemaBuffer.edit<Schema>()._emissive = emissive;
|
||||
_schemaBuffer.edit<Schema>()._emissive = (isSRGB ? ColorUtils::toLinearVec3(emissive) : emissive);
|
||||
}
|
||||
|
||||
void Material::setGloss(float gloss) {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <bitset>
|
||||
#include <map>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <ColorUtils.h>
|
||||
|
||||
#include <gpu/Resource.h>
|
||||
|
||||
|
@ -219,28 +219,31 @@ public:
|
|||
virtual ~Material();
|
||||
|
||||
const MaterialKey& getKey() const { return _key; }
|
||||
|
||||
const Color& getEmissive() const { return _schemaBuffer.get<Schema>()._emissive; }
|
||||
const Color& getDiffuse() const { return _schemaBuffer.get<Schema>()._diffuse; }
|
||||
float getMetallic() const { return _schemaBuffer.get<Schema>()._metallic.x; }
|
||||
float getGloss() const { return _schemaBuffer.get<Schema>()._gloss; }
|
||||
float getOpacity() const { return _schemaBuffer.get<Schema>()._opacity; }
|
||||
|
||||
void setEmissive(const Color& emissive);
|
||||
void setDiffuse(const Color& diffuse);
|
||||
void setEmissive(const Color& emissive, bool isSRGB = true);
|
||||
const Color& getEmissive(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get<Schema>()._emissive) : _schemaBuffer.get<Schema>()._emissive); }
|
||||
|
||||
void setDiffuse(const Color& diffuse, bool isSRGB = true);
|
||||
const Color& getDiffuse(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get<Schema>()._diffuse) : _schemaBuffer.get<Schema>()._diffuse); }
|
||||
|
||||
void setMetallic(float metallic);
|
||||
float getMetallic() const { return _schemaBuffer.get<Schema>()._metallic.x; }
|
||||
|
||||
void setGloss(float gloss);
|
||||
float getGloss() const { return _schemaBuffer.get<Schema>()._gloss; }
|
||||
|
||||
void setOpacity(float opacity);
|
||||
float getOpacity() const { return _schemaBuffer.get<Schema>()._opacity; }
|
||||
|
||||
// Schema to access the attribute values of the material
|
||||
class Schema {
|
||||
public:
|
||||
|
||||
Color _diffuse{0.5f};
|
||||
glm::vec3 _diffuse{ 0.5f };
|
||||
float _opacity{1.f};
|
||||
Color _metallic{0.03f};
|
||||
glm::vec3 _metallic{ 0.03f };
|
||||
float _gloss{0.1f};
|
||||
Color _emissive{0.0f};
|
||||
glm::vec3 _emissive{ 0.0f };
|
||||
float _spare0{0.0f};
|
||||
glm::vec4 _spareVec4{0.0f}; // for alignment beauty, Material size == Mat4x4
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
class ColorUtils {
|
||||
public:
|
||||
inline static glm::vec3 toVec3(const xColor& color);
|
||||
|
||||
// Convert from gamma 2.2 space to linear
|
||||
inline static glm::vec3 toLinearVec3(const glm::vec3& srgb);
|
||||
inline static glm::vec3 toGamma22Vec3(const glm::vec3& linear);
|
||||
};
|
||||
|
||||
inline glm::vec3 ColorUtils::toVec3(const xColor& color) {
|
||||
|
@ -27,4 +31,16 @@ inline glm::vec3 ColorUtils::toVec3(const xColor& color) {
|
|||
return glm::vec3(color.red * ONE_OVER_255, color.green * ONE_OVER_255, color.blue * ONE_OVER_255);
|
||||
}
|
||||
|
||||
inline glm::vec3 ColorUtils::toLinearVec3(const glm::vec3& srgb) {
|
||||
const float GAMMA_22 = 2.2f;
|
||||
// Couldn't find glm::pow(vec3, vec3) ? so did it myself...
|
||||
return glm::vec3(glm::pow(srgb.x, GAMMA_22), glm::pow(srgb.y, GAMMA_22), glm::pow(srgb.z, GAMMA_22));
|
||||
}
|
||||
|
||||
inline glm::vec3 ColorUtils::toGamma22Vec3(const glm::vec3& linear) {
|
||||
const float INV_GAMMA_22 = 1.0f / 2.2f;
|
||||
// Couldn't find glm::pow(vec3, vec3) ? so did it myself...
|
||||
return glm::vec3(glm::pow(linear.x, INV_GAMMA_22), glm::pow(linear.y, INV_GAMMA_22), glm::pow(linear.z, INV_GAMMA_22));
|
||||
}
|
||||
|
||||
#endif // hifi_ColorUtils_h
|
Loading…
Reference in a new issue