HDR and gamma correction

This commit is contained in:
devZoGok
2021-10-19 19:06:40 +03:00
parent e95e40177a
commit d699201592
7 changed files with 30 additions and 5 deletions
+12
View File
@@ -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;
}
+1 -1
View File
@@ -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
+2
View File
@@ -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");
+8 -2
View File
@@ -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<Texture*> diffuseMapTextures,normalMapTextures,specularMapTextures;
bool lightingEnabled=false,texturingEnabled=true,diffuseColorEnabled=false,normalMapEnabled=false,parallaxMapEnabled=false;
std::vector<Texture*> diffuseMapTextures,normalMapTextures,specularMapTextures,parallaxMapTextures;
Vector4 diffuseColor=Vector4::VEC_IJKL,specularColor=Vector4::VEC_IJKL;
Shader *shader=nullptr;
};
+2
View File
@@ -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(){
+1 -1
View File
@@ -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);
+4 -1
View File
@@ -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<numLights;i++){
@@ -100,7 +103,7 @@ void main(){
coef=0;
}
}
float specularStrength=.5;
float specularStrength=1;
reflectVec=reflect(lightDir,normal);
float spec=pow(max(dot(viewDir,reflectVec),0),32);
specularColor+=vec3(1)*spec*specularStrength;