mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 03:58:07 +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() {
|
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))));
|
_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) {
|
void Material::setMetallic(float metallic) {
|
||||||
|
@ -54,9 +54,9 @@ void Material::setMetallic(float metallic) {
|
||||||
_schemaBuffer.edit<Schema>()._metallic = glm::vec3(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))));
|
_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) {
|
void Material::setGloss(float gloss) {
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <ColorUtils.h>
|
||||||
|
|
||||||
#include <gpu/Resource.h>
|
#include <gpu/Resource.h>
|
||||||
|
|
||||||
|
@ -220,27 +220,30 @@ public:
|
||||||
|
|
||||||
const MaterialKey& getKey() const { return _key; }
|
const MaterialKey& getKey() const { return _key; }
|
||||||
|
|
||||||
const Color& getEmissive() const { return _schemaBuffer.get<Schema>()._emissive; }
|
void setEmissive(const Color& emissive, bool isSRGB = true);
|
||||||
const Color& getDiffuse() const { return _schemaBuffer.get<Schema>()._diffuse; }
|
const Color& getEmissive(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get<Schema>()._emissive) : _schemaBuffer.get<Schema>()._emissive); }
|
||||||
float getMetallic() const { return _schemaBuffer.get<Schema>()._metallic.x; }
|
|
||||||
float getGloss() const { return _schemaBuffer.get<Schema>()._gloss; }
|
void setDiffuse(const Color& diffuse, bool isSRGB = true);
|
||||||
float getOpacity() const { return _schemaBuffer.get<Schema>()._opacity; }
|
const Color& getDiffuse(bool SRGB = true) const { return (SRGB ? ColorUtils::toGamma22Vec3(_schemaBuffer.get<Schema>()._diffuse) : _schemaBuffer.get<Schema>()._diffuse); }
|
||||||
|
|
||||||
void setEmissive(const Color& emissive);
|
|
||||||
void setDiffuse(const Color& diffuse);
|
|
||||||
void setMetallic(float metallic);
|
void setMetallic(float metallic);
|
||||||
|
float getMetallic() const { return _schemaBuffer.get<Schema>()._metallic.x; }
|
||||||
|
|
||||||
void setGloss(float gloss);
|
void setGloss(float gloss);
|
||||||
|
float getGloss() const { return _schemaBuffer.get<Schema>()._gloss; }
|
||||||
|
|
||||||
void setOpacity(float opacity);
|
void setOpacity(float opacity);
|
||||||
|
float getOpacity() const { return _schemaBuffer.get<Schema>()._opacity; }
|
||||||
|
|
||||||
// Schema to access the attribute values of the material
|
// Schema to access the attribute values of the material
|
||||||
class Schema {
|
class Schema {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Color _diffuse{0.5f};
|
glm::vec3 _diffuse{ 0.5f };
|
||||||
float _opacity{1.f};
|
float _opacity{1.f};
|
||||||
Color _metallic{0.03f};
|
glm::vec3 _metallic{ 0.03f };
|
||||||
float _gloss{0.1f};
|
float _gloss{0.1f};
|
||||||
Color _emissive{0.0f};
|
glm::vec3 _emissive{ 0.0f };
|
||||||
float _spare0{0.0f};
|
float _spare0{0.0f};
|
||||||
glm::vec4 _spareVec4{0.0f}; // for alignment beauty, Material size == Mat4x4
|
glm::vec4 _spareVec4{0.0f}; // for alignment beauty, Material size == Mat4x4
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
class ColorUtils {
|
class ColorUtils {
|
||||||
public:
|
public:
|
||||||
inline static glm::vec3 toVec3(const xColor& color);
|
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) {
|
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);
|
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
|
#endif // hifi_ColorUtils_h
|
Loading…
Reference in a new issue