From d699201592a73e6bfb6ac8264207fe869ae247ec Mon Sep 17 00:00:00 2001 From: devZoGok Date: Wed, 26 Feb 2020 22:13:36 +0200 Subject: [PATCH] HDR and gamma correction --- gui.frag | 12 ++++++++++++ light.cpp | 2 +- material.cpp | 2 ++ material.h | 10 ++++++++-- root.cpp | 2 ++ texture.cpp | 2 +- texture.frag | 5 ++++- 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/gui.frag b/gui.frag index d371c44..ae0ee3c 100755 --- a/gui.frag +++ b/gui.frag @@ -6,6 +6,7 @@ out vec4 FragColor; uniform bool texturingEnabled; uniform bool diffuseColorEnabled; +uniform bool guiPlane; uniform vec4 diffuseColor; uniform sampler2D tex; @@ -15,5 +16,16 @@ void main(){ float alpha=texture(tex,texCoords).w; c=vec4(diffuseColor.xyz,alpha); } + if(guiPlane){ + float gamma=1,exposure=1; + + //Reinhardt + //c.rgb=c.rgb/(c.rgb+vec3(1.)); + + //Exp + c.rgb=vec3(1.)-exp(-c.rgb*exposure); + + c.rgb=pow(c.rgb,vec3(1/gamma)); + } FragColor=c; } diff --git a/light.cpp b/light.cpp index 9ccba16..aea4c60 100755 --- a/light.cpp +++ b/light.cpp @@ -139,7 +139,7 @@ namespace vb01{ shader->setVec3(color,"light["+to_string(thisId)+"].color"); shader->setFloat(nearPlane,"light["+to_string(thisId)+"].near"); shader->setFloat(farPlane,"light["+to_string(thisId)+"].far"); - shader->setInt(0,"tex"); + //shader->setInt(0,"tex"); if(type==POINT) shader->setInt(1,"light["+to_string(thisId)+"].depthMapCube"); else diff --git a/material.cpp b/material.cpp index 7b2b4dc..d404727 100755 --- a/material.cpp +++ b/material.cpp @@ -58,6 +58,8 @@ namespace vb01{ t->update(2); for(Texture *t : specularMapTextures) t->update(3); + for(Texture *t : parallaxMapTextures) + t->update(4); } else { shader->setVec4(diffuseColor,"diffuseColor"); diff --git a/material.h b/material.h index 8631e79..c614d78 100755 --- a/material.h +++ b/material.h @@ -34,12 +34,18 @@ namespace vb01{ } inline void addSpecularMap(std::string specularMap[],int numFrames){specularMapTextures.push_back(new Texture(specularMap,numFrames));} inline void setSpecularMap(Texture *texture, int i){specularMapTextures[i]=texture;} + inline void addParallaxMap(std::string parallaxMap){ + std::string p[]{parallaxMap}; + parallaxMapTextures.push_back(new Texture(p,1)); + } + inline void addParallaxMap(std::string parallaxMap[],int numFrames){parallaxMapTextures.push_back(new Texture(parallaxMap,numFrames));} inline void setDiffuseColor(Vector4 diffuse){this->diffuseColor=diffuse;} inline void setSpecularColor(Vector4 specular){this->specularColor=specular;} inline void setLightingEnabled(bool lighting){this->lightingEnabled=lighting;} inline void setTexturingEnabled(bool texturing){this->texturingEnabled=texturing;} inline void setDiffuseColorEnabled(bool diffuseColor){this->diffuseColorEnabled=diffuseColor;} inline void setNormalMapEnabled(bool enabled){this->normalMapEnabled=enabled;} + inline void setParallaxMapEnabled(bool enabled){this->parallaxMapEnabled=enabled;} inline bool isLightingEnabled(){return lightingEnabled;} inline bool isTexturingEnabled(){return texturingEnabled;} inline bool isDiffuseColorEnabled(){return diffuseColorEnabled;} @@ -50,8 +56,8 @@ namespace vb01{ inline Type getType(){return type;} private: Type type; - bool lightingEnabled=false,texturingEnabled=true,diffuseColorEnabled=false,normalMapEnabled=false; - std::vector diffuseMapTextures,normalMapTextures,specularMapTextures; + bool lightingEnabled=false,texturingEnabled=true,diffuseColorEnabled=false,normalMapEnabled=false,parallaxMapEnabled=false; + std::vector diffuseMapTextures,normalMapTextures,specularMapTextures,parallaxMapTextures; Vector4 diffuseColor=Vector4::VEC_IJKL,specularColor=Vector4::VEC_IJKL; Shader *shader=nullptr; }; diff --git a/root.cpp b/root.cpp index 82411be..bdcf9f2 100755 --- a/root.cpp +++ b/root.cpp @@ -79,6 +79,8 @@ namespace vb01{ Material *mat=new Material(Material::MATERIAL_GUI); mat->addDiffuseMap(texture); guiPlane->setMaterial(mat); + mat->getShader()->use(); + mat->getShader()->setBool(true,"guiPlane"); } void Root::update(){ diff --git a/texture.cpp b/texture.cpp index 8de2f25..54748f0 100755 --- a/texture.cpp +++ b/texture.cpp @@ -25,7 +25,7 @@ namespace vb01{ glTexParameterfv(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR,borderColor); } else{ - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,NULL); + glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,NULL); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); diff --git a/texture.frag b/texture.frag index cd0e95c..f83f41e 100755 --- a/texture.frag +++ b/texture.frag @@ -24,6 +24,8 @@ struct Light{ uniform sampler2D diffuseMap; uniform sampler2D normalMap; +uniform sampler2D specularMap; +uniform sampler2D parallaxMap; uniform Light light[numLights]; uniform bool lightingEnabled; uniform bool texturingEnabled; @@ -73,6 +75,7 @@ void main(){ vec3 n=vec3(texture(normalMap,texCoords)); normal=mat3(tan,biTan,norm)*n; } + vec3 diffuseColor=vec3(0),specularColor=vec3(0); float coef=1; for(int i=0;i