big fixes (shadowmaps, mipmapping)
This commit is contained in:
parent
c5d4d90463
commit
1ffba313fe
@ -112,7 +112,7 @@ void main(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AMBIENT_LIGHT
|
#ifdef AMBIENT_LIGHT
|
||||||
outColor = vec4(diffuse*0, 1);
|
outColor = vec4(diffuse*0.1, 1);
|
||||||
#else
|
#else
|
||||||
vec3 light = phongLighting(diffuse, specular, materialNs, lightColor, normal, lightDirInView, halfVecInView);
|
vec3 light = phongLighting(diffuse, specular, materialNs, lightColor, normal, lightDirInView, halfVecInView);
|
||||||
outColor = vec4(light*shadow*(1+cos(1.57 + att*1.57)), 1);
|
outColor = vec4(light*shadow*(1+cos(1.57 + att*1.57)), 1);
|
||||||
|
22
src/mesh.cpp
22
src/mesh.cpp
@ -232,6 +232,8 @@ unsigned int Mesh::getFlags()
|
|||||||
flags |= 1 << MESH_TANGENT_SPACE;
|
flags |= 1 << MESH_TANGENT_SPACE;
|
||||||
if(isBillboard)
|
if(isBillboard)
|
||||||
flags |= 1 << MESH_BILLBOARD;
|
flags |= 1 << MESH_BILLBOARD;
|
||||||
|
if(isShadowCaster)
|
||||||
|
flags |= 1 << MESH_SHADOWED;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
flags |= 1 << MESH_2D;
|
flags |= 1 << MESH_2D;
|
||||||
@ -400,3 +402,23 @@ void Mesh::computeTangents()
|
|||||||
tangents[vertexId2] = {tangentDir, binormalDir};
|
tangents[vertexId2] = {tangentDir, binormalDir};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mesh::computeBoundingBox(glm::vec3 &min, glm::vec3 &max)
|
||||||
|
{
|
||||||
|
min = max = positions3D[0];
|
||||||
|
for(const glm::vec3 &pos : positions3D)
|
||||||
|
{
|
||||||
|
if(pos.x < min.x)
|
||||||
|
min.x = pos.x;
|
||||||
|
else if(pos.x > max.x)
|
||||||
|
max.x = pos.x;
|
||||||
|
if(pos.y < min.y)
|
||||||
|
min.y = pos.y;
|
||||||
|
else if(pos.y > max.y)
|
||||||
|
max.y = pos.y;
|
||||||
|
if(pos.z < min.z)
|
||||||
|
min.z = pos.z;
|
||||||
|
else if(pos.z > max.z)
|
||||||
|
max.z = pos.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -177,7 +177,12 @@ public:
|
|||||||
* compute tangent space from a textured indexed mesh (positions + normals + texcoords + indices)
|
* compute tangent space from a textured indexed mesh (positions + normals + texcoords + indices)
|
||||||
*/
|
*/
|
||||||
void computeTangents();
|
void computeTangents();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compute the bounding box of the mesh based on the 3D positions
|
||||||
|
*/
|
||||||
|
void computeBoundingBox(glm::vec3 &min, glm::vec3 &max);
|
||||||
|
|
||||||
/*************************************************************/
|
/*************************************************************/
|
||||||
/* ADVANCED CUSTOMISATION */
|
/* ADVANCED CUSTOMISATION */
|
||||||
/*************************************************************/
|
/*************************************************************/
|
||||||
|
@ -13,7 +13,8 @@ Texture::Texture(GLenum format,
|
|||||||
m_internal_format(internal_format),
|
m_internal_format(internal_format),
|
||||||
m_width(width),
|
m_width(width),
|
||||||
m_height(height),
|
m_height(height),
|
||||||
m_dataType(dataType)
|
m_dataType(dataType),
|
||||||
|
m_hasMipMaps(false)
|
||||||
{
|
{
|
||||||
glGenTextures(1, &texId);
|
glGenTextures(1, &texId);
|
||||||
glBindTexture(m_target, texId);
|
glBindTexture(m_target, texId);
|
||||||
@ -38,24 +39,28 @@ Texture::Texture(GLenum format,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(Image* myImage) :
|
Texture::Texture(Image* myImage, bool makeMipMaps) :
|
||||||
m_target(GL_TEXTURE_2D),
|
m_target(GL_TEXTURE_2D),
|
||||||
m_width(myImage->width),
|
m_width(myImage->width),
|
||||||
m_height(myImage->height),
|
m_height(myImage->height),
|
||||||
m_dataType(GL_UNSIGNED_BYTE)
|
m_dataType(GL_UNSIGNED_BYTE),
|
||||||
|
m_hasMipMaps(makeMipMaps)
|
||||||
{
|
{
|
||||||
glGenTextures(1, &texId);
|
glGenTextures(1, &texId);
|
||||||
glBindTexture(m_target, texId);
|
glBindTexture(m_target, texId);
|
||||||
initPixels(myImage, GL_TEXTURE_2D);
|
initPixels(myImage, GL_TEXTURE_2D);
|
||||||
setWrap(GL_REPEAT);
|
setWrap(GL_REPEAT);
|
||||||
setFiltering(GL_LINEAR);
|
setFiltering(GL_LINEAR);
|
||||||
|
if(makeMipMaps)
|
||||||
|
createMipMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(Image* myCubemapImages[6]) :
|
Texture::Texture(Image* myCubemapImages[6], bool makeMipMaps) :
|
||||||
m_target(GL_TEXTURE_CUBE_MAP),
|
m_target(GL_TEXTURE_CUBE_MAP),
|
||||||
m_width(myCubemapImages[0]->width),
|
m_width(myCubemapImages[0]->width),
|
||||||
m_height(myCubemapImages[0]->height),
|
m_height(myCubemapImages[0]->height),
|
||||||
m_dataType(GL_UNSIGNED_BYTE)
|
m_dataType(GL_UNSIGNED_BYTE),
|
||||||
|
m_hasMipMaps(makeMipMaps)
|
||||||
{
|
{
|
||||||
glGenTextures(1, &texId);
|
glGenTextures(1, &texId);
|
||||||
glBindTexture(m_target, texId);
|
glBindTexture(m_target, texId);
|
||||||
@ -63,6 +68,8 @@ Texture::Texture(Image* myCubemapImages[6]) :
|
|||||||
initPixels(myCubemapImages[i], GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
|
initPixels(myCubemapImages[i], GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
|
||||||
setWrap(GL_CLAMP_TO_EDGE);
|
setWrap(GL_CLAMP_TO_EDGE);
|
||||||
setFiltering(GL_LINEAR);
|
setFiltering(GL_LINEAR);
|
||||||
|
if(makeMipMaps)
|
||||||
|
createMipMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(Texture* tex, bool halfDim) :
|
Texture::Texture(Texture* tex, bool halfDim) :
|
||||||
@ -71,7 +78,8 @@ Texture::Texture(Texture* tex, bool halfDim) :
|
|||||||
m_internal_format(tex->m_internal_format),
|
m_internal_format(tex->m_internal_format),
|
||||||
m_width(tex->m_width),
|
m_width(tex->m_width),
|
||||||
m_height(tex->m_height),
|
m_height(tex->m_height),
|
||||||
m_dataType(tex->m_dataType)
|
m_dataType(tex->m_dataType),
|
||||||
|
m_hasMipMaps(false)
|
||||||
{
|
{
|
||||||
glGenTextures(1, &texId);
|
glGenTextures(1, &texId);
|
||||||
glBindTexture(m_target, texId);
|
glBindTexture(m_target, texId);
|
||||||
@ -121,6 +129,13 @@ void Texture::setFiltering(GLint filter)
|
|||||||
glTexParameteri(m_target, GL_TEXTURE_MAG_FILTER, filter);
|
glTexParameteri(m_target, GL_TEXTURE_MAG_FILTER, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Texture::createMipMaps()
|
||||||
|
{
|
||||||
|
m_hasMipMaps = true;
|
||||||
|
glGenerateMipmap(m_target);
|
||||||
|
glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
}
|
||||||
|
|
||||||
void Texture::bind(int slot)
|
void Texture::bind(int slot)
|
||||||
{
|
{
|
||||||
glActiveTexture(GL_TEXTURE0+slot);
|
glActiveTexture(GL_TEXTURE0+slot);
|
||||||
|
@ -16,6 +16,7 @@ private:
|
|||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
GLenum m_dataType;
|
GLenum m_dataType;
|
||||||
|
bool m_hasMipMaps;
|
||||||
|
|
||||||
void initPixels(Image* myImage, GLenum textureSlot);
|
void initPixels(Image* myImage, GLenum textureSlot);
|
||||||
public:
|
public:
|
||||||
@ -29,9 +30,9 @@ public:
|
|||||||
GLenum dataType = GL_UNSIGNED_BYTE,
|
GLenum dataType = GL_UNSIGNED_BYTE,
|
||||||
GLenum texTarget = GL_TEXTURE_2D);
|
GLenum texTarget = GL_TEXTURE_2D);
|
||||||
// creates a standard texture from an image
|
// creates a standard texture from an image
|
||||||
Texture(Image* myImage);
|
Texture(Image* myImage, bool makeMipMaps = true);
|
||||||
// creates a cubeMap from 6 images
|
// creates a cubeMap from 6 images
|
||||||
Texture(Image* myCubemapImages[6]);
|
Texture(Image* myCubemapImages[6], bool makeMipMaps = true);
|
||||||
// creates a texture from another
|
// creates a texture from another
|
||||||
Texture(Texture* tex, bool halfDim = false);
|
Texture(Texture* tex, bool halfDim = false);
|
||||||
|
|
||||||
@ -41,7 +42,9 @@ public:
|
|||||||
GLenum getTarget() {return m_target;}
|
GLenum getTarget() {return m_target;}
|
||||||
void setWrap(GLint wrap);
|
void setWrap(GLint wrap);
|
||||||
void setFiltering(GLint filter);
|
void setFiltering(GLint filter);
|
||||||
|
void createMipMaps();
|
||||||
bool isCubeMap() {return m_target == GL_TEXTURE_CUBE_MAP;}
|
bool isCubeMap() {return m_target == GL_TEXTURE_CUBE_MAP;}
|
||||||
|
bool hasMipMaps() {return m_hasMipMaps;}
|
||||||
|
|
||||||
int getWidth() {return m_width;}
|
int getWidth() {return m_width;}
|
||||||
int getHeight() {return m_height;}
|
int getHeight() {return m_height;}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user