diff --git a/light.cpp b/light.cpp index d9d39d3..f168857 100755 --- a/light.cpp +++ b/light.cpp @@ -92,7 +92,7 @@ namespace vb01{ vec3 dir=vec3(direction.x,direction.y,direction.z); vec3 up=vec3(upDir.x,upDir.y,upDir.z); vec3 p=type==DIRECTIONAL?vec3(pos.x,pos.y,pos.z)-.5f*farPlane*dir:vec3(position.x,position.y,position.z); - view=lookAt(p,p+dir,up); + view=lookAt(vec3(0,30,0),vec3(0,0,0),vec3(1,0,0)); proj=ortho(-10.f,10.f,-10.f,10.f,nearPlane,farPlane); depthMapShader->use(); diff --git a/material.cpp b/material.cpp index d20c5ff..eacc5b8 100755 --- a/material.cpp +++ b/material.cpp @@ -49,8 +49,10 @@ namespace vb01{ shader->setVec4(diffuseColor,"diffuseColor"); } if(texturingEnabled){ - for(Texture *t : diffuseMapTextures) + for(Texture *t : diffuseMapTextures){ + t->update(); t->select(); + } for(Texture *t : normalMapTextures) t->select(); for(Texture *t : specularMapTextures) diff --git a/texture.cpp b/texture.cpp index b6db7e4..6816844 100755 --- a/texture.cpp +++ b/texture.cpp @@ -77,6 +77,35 @@ namespace vb01{ stbi_image_free(data); } + Texture::Texture(string path[],int numFrames,s64 updateRate,bool flip){ + this->updateRate=updateRate; + this->numFrames=numFrames; + frames=new u32; + for(int i=0;itype=TextureType::TEXTURE_CUBEMAP; @@ -109,8 +138,17 @@ namespace vb01{ glDeleteTextures(1,&texture); } + void Texture::update(){ + if(numFrames>0){ + if(getTime()-lastUpdateTime>updateRate){ + currentFrame=(currentFrame==numFrames-1?0:currentFrame+1); + lastUpdateTime=getTime(); + } + } + } + void Texture::select(int id){ glActiveTexture(GL_TEXTURE0+id); - glBindTexture(type==TEXTURE_2D?GL_TEXTURE_2D:GL_TEXTURE_CUBE_MAP,texture); + glBindTexture(type==TEXTURE_2D?GL_TEXTURE_2D:GL_TEXTURE_CUBE_MAP,numFrames==0?texture:frames[currentFrame]); } } diff --git a/texture.frag b/texture.frag index cf6d20a..0cad3ba 100755 --- a/texture.frag +++ b/texture.frag @@ -35,7 +35,7 @@ float getShadow(int id,int shadowId){ float closestDepth=texture(light[id].depthMap[shadowId],projCoords.xy).r; float currentDepth=projCoords.z; float bias=.005; - return currentDepth-bias>closestDepth?.7:0; + return (currentDepth-bias>closestDepth)&&projCoords.z<=1.?.7:0; } void main(){ diff --git a/texture.h b/texture.h index a38e9d6..def2331 100755 --- a/texture.h +++ b/texture.h @@ -3,6 +3,7 @@ #include #include +#include"util.h" #include FT_FREETYPE_H namespace vb01{ @@ -14,16 +15,19 @@ namespace vb01{ Texture(int,int,bool=true); Texture(FT_Face&,char); Texture(std::string,bool=false); + Texture(std::string[],int,s64,bool=false); Texture(std::string[6],bool=false); + void update(); void select(int=0); inline unsigned int* getTexture(){return &texture;} inline std::string getPath(){return path;} private: TextureType type=TextureType::TEXTURE_2D; - unsigned int texture; - int width,height,numChannels; + s64 updateRate=0,lastUpdateTime=0; + u32 texture,*frames; + int width,height,numChannels,numFrames=0,currentFrame=0; float weight; - unsigned char *data; + u8 *data; std::string path="",paths[6]; }; }