diff --git a/gui.frag b/gui.frag index ae0ee3c..476ec8b 100755 --- a/gui.frag +++ b/gui.frag @@ -11,21 +11,21 @@ uniform vec4 diffuseColor; uniform sampler2D tex; void main(){ - vec4 c=texturingEnabled?texture(tex,texCoords):diffuseColor; + vec4 c = texturingEnabled?texture(tex, texCoords) : diffuseColor; if(diffuseColorEnabled){ - float alpha=texture(tex,texCoords).w; - c=vec4(diffuseColor.xyz,alpha); + float alpha = texture(tex, texCoords).w; + c = vec4(diffuseColor.xyz, alpha); } if(guiPlane){ - float gamma=1,exposure=1; + float gamma = 1, exposure = 1; //Reinhardt - //c.rgb=c.rgb/(c.rgb+vec3(1.)); + //c.rgb = c.rgb / (c.rgb + vec3(1.)); //Exp - c.rgb=vec3(1.)-exp(-c.rgb*exposure); + c.rgb = vec3(1.) - exp(-c.rgb * exposure); - c.rgb=pow(c.rgb,vec3(1/gamma)); + c.rgb = pow(c.rgb, vec3(1 / gamma)); } - FragColor=c; + FragColor = c; } diff --git a/light.cpp b/light.cpp index b642f45..a4c921a 100755 --- a/light.cpp +++ b/light.cpp @@ -181,9 +181,9 @@ 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(5, "light[" + to_string(thisId) + "].depthMapCube"); - shader->setInt(6, "light[" + to_string(thisId) + "].depthMap"); - depthMap->select(type == POINT ? 5 : 6); + shader->setInt(12, "light[" + to_string(thisId) + "].depthMapCube"); + shader->setInt(13, "light[" + to_string(thisId) + "].depthMap"); + depthMap->select(type == POINT ? 12 : 13); switch(type){ case POINT: diff --git a/material.cpp b/material.cpp index 2b64511..1bff30e 100755 --- a/material.cpp +++ b/material.cpp @@ -55,15 +55,20 @@ namespace vb01{ void Material::update(){ shader->use(); shader->setBool(texturingEnabled, "texturingEnabled"); + const int DIFFUSE_SLOT = Texture::DIFFUSE * 2; + const int NORMAL_SLOT = Texture::NORMAL * 2; + const int SPECULAR_SLOT = Texture::SPECULAR * 2; + const int PARALLAX_SLOT = Texture::PARALLAX * 2; + const int ENVIRONMENT_SLOT = Texture::ENVIRONMENT * 2; if(type == MATERIAL_2D){ shader->setBool(lightingEnabled, "lightingEnabled"); shader->setBool(normalMapEnabled, "normalMapEnabled"); - shader->setInt(0, "diffuseMap"); - shader->setInt(1, "normalMap"); - shader->setInt(2, "specularMap"); - shader->setInt(3, "parallaxMap"); - shader->setInt(4, "environmentMap"); + shader->setInt(DIFFUSE_SLOT, "textures["+to_string(DIFFUSE_SLOT)+"].pastTexture"); + shader->setInt(NORMAL_SLOT, "textures["+to_string(NORMAL_SLOT)+"].pastTexture"); + shader->setInt(SPECULAR_SLOT, "textures["+to_string(SPECULAR_SLOT)+"].pastTexture"); + shader->setInt(PARALLAX_SLOT, "textures["+to_string(PARALLAX_SLOT)+"].pastTexture"); + shader->setInt(ENVIRONMENT_SLOT, "environmentMap"); } else if(type == MATERIAL_GUI){ shader->setBool(diffuseColorEnabled, "diffuseColorEnabled"); @@ -72,14 +77,18 @@ namespace vb01{ } if(texturingEnabled){ - for(Texture *t : diffuseMapTextures) - t->update(0); + int textureSlot = DIFFUSE_SLOT; + for(Texture *t : diffuseMapTextures){ + t->update(textureSlot); + if(t->getNumFrames() > 0) + shader->setBool(true, "textures[" + to_string(textureSlot) + "].animated"); + } for(Texture *t : normalMapTextures) - t->update(1); + t->update(NORMAL_SLOT); for(Texture *t : specularMapTextures) - t->update(2); + t->update(SPECULAR_SLOT); for(Texture *t : parallaxMapTextures) - t->update(3); + t->update(PARALLAX_SLOT); } else shader->setVec4(diffuseColor, "diffuseColor"); diff --git a/particle.frag b/particle.frag index c3e48be..820ae6e 100755 --- a/particle.frag +++ b/particle.frag @@ -9,7 +9,7 @@ layout (location = 1) out vec4 BrightColor; uniform sampler2D tex; uniform float lifePercentage[500]; -uniform vec4 startColor,endColor; +uniform vec4 startColor, endColor; void main(){ float alpha = texture(tex, texCoords).r; diff --git a/text.cpp b/text.cpp index 3ade0b8..c405177 100755 --- a/text.cpp +++ b/text.cpp @@ -1,12 +1,13 @@ -#include"root.h" -#include"text.h" -#include"shader.h" -#include"texture.h" -#include"node.h" -#include -#include -#include -#include +#include "root.h" +#include "text.h" +#include "shader.h" +#include "texture.h" +#include "node.h" + +#include +#include +#include +#include #include FT_FREETYPE_H using namespace std; diff --git a/texture.cpp b/texture.cpp index 0e6bbb7..e7415c3 100755 --- a/texture.cpp +++ b/texture.cpp @@ -150,14 +150,14 @@ namespace vb01{ void Texture::update(int id){ updateFrame(); select(id); + if(numFrames > 0) + select(id + 1); } void Texture::updateFrame(){ if(numFrames > 0){ if(getTime() - lastUpdateTime > updateRate){ - frame++; - if(frame == numFrames) - frame = 0; + frame = getNextFrame(frame); lastUpdateTime = getTime(); } } @@ -165,6 +165,6 @@ namespace vb01{ void Texture::select(int id){ glActiveTexture(GL_TEXTURE0 + id); - glBindTexture(type == TEXTURE_2D ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP, texture[numFrames > 0 ? frame : 0]); + glBindTexture(type == TEXTURE_2D ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP, texture[frame]); } } diff --git a/texture.frag b/texture.frag index 560bea0..e5cab48 100755 --- a/texture.frag +++ b/texture.frag @@ -8,25 +8,28 @@ in vec3 norm; in vec2 texCoords; in vec4 lightSpaceFragPos; -layout (location=0) out vec4 FragColor; -layout (location=1) out vec4 BrightColor; +layout (location = 0) out vec4 FragColor; +layout (location = 1) out vec4 BrightColor; //0-POINT,1-DIRECTIONAL,2-SPOT struct Light{ int type; - vec3 pos,color,direction; - float innerAngle,outerAngle; - float a,b,c,near,far; + vec3 pos, color, direction; + float innerAngle, outerAngle; + float a, b, c, near, far; sampler2D depthMap; samplerCube depthMapCube; mat4 lightMat; }; -uniform sampler2D diffuseMap; -uniform sampler2D normalMap; -uniform sampler2D specularMap; -uniform sampler2D parallaxMap; +struct Texture{ + float mixRatio; + sampler2D pastTexture, nextTexture; + bool animated; +}; + +uniform Texture textures[4]; uniform samplerCube environmentMap; uniform Light light[numLights]; uniform bool lightingEnabled; @@ -72,69 +75,69 @@ float getShadow(int id){ } void main(){ - vec4 finalColor=texturingEnabled?texture(diffuseMap,texCoords):diffuseColor; - vec3 normal=norm; + vec4 finalColor = texturingEnabled?texture(textures[0].pastTexture, texCoords) : diffuseColor; + vec3 normal = norm; if(lightingEnabled){ if(normalMapEnabled){ - vec3 n=vec3(texture(normalMap,texCoords)); - normal=mat3(tan,biTan,norm)*n; + vec3 n = vec3(texture(textures[1].pastTexture, texCoords)); + normal = mat3(tan, biTan, norm) * n; } - vec3 diffuseColor=vec3(0),specularColor=vec3(0); - float coef=1; + vec3 diffuseColor = vec3(0), specularColor = vec3(0); + float coef = 1; - for(int i=0;ilight[i].outerAngle){ - coef=0; + if(angle > light[i].outerAngle){ + coef = 0; } } - float specularSample=texture(specularMap,texCoords).r; - reflectVec=reflect(lightDir,normal); - float spec=pow(max(dot(viewDir,reflectVec),0),32); - specularColor+=vec3(1)*spec*specularSample; + float specularSample = texture(textures[2].pastTexture, texCoords).r; + reflectVec = reflect(lightDir, normal); + float spec = pow(max(dot(viewDir, reflectVec), 0), 32); + specularColor += vec3(1) * spec * specularSample; - factor=max(dot(lightDir,normal),0.); - diffuseColor+=light[i].color*(factor*attenuation*coef); + factor = max(dot(lightDir, normal), 0.); + diffuseColor += light[i].color * (factor * attenuation * coef); } /* - for(int i=0;i1) - BrightColor=vec4(finalColor.rgb,1); - FragColor=finalColor; + if(brightness > 1) + BrightColor = vec4(finalColor.rgb, 1); + FragColor = finalColor; } diff --git a/texture.h b/texture.h index cd51279..f5b21df 100755 --- a/texture.h +++ b/texture.h @@ -1,9 +1,9 @@ #ifndef TEXTURE_H #define TEXTURE_H -#include -#include -#include"util.h" +#include +#include +#include "util.h" #include FT_FREETYPE_H namespace vb01{ @@ -22,6 +22,7 @@ namespace vb01{ void update(int = 0); inline unsigned int* getTexture(int i = 0){return &(texture[i]);} inline std::string getPath(){return path;} + inline int getNumFrames(){return numFrames;} private: TextureType type = TextureType::TEXTURE_2D; u32 *texture = nullptr; @@ -34,6 +35,7 @@ namespace vb01{ void createCubemap(bool, bool); void updateFrame(); + inline int getNextFrame(int frameId){return (frameId + 1 < numFrames ? frameId + 1 : 0);} }; }