Decided to start off a cleaner base, deleted most of uneeded code for this specific demo
This commit is contained in:
parent
32071d672e
commit
a9fc5d0cf5
@ -158,7 +158,6 @@
|
|||||||
<ClCompile Include="Multipass.cpp" />
|
<ClCompile Include="Multipass.cpp" />
|
||||||
<ClCompile Include="MyGLWindow.cpp" />
|
<ClCompile Include="MyGLWindow.cpp" />
|
||||||
<ClCompile Include="Shader.cpp" />
|
<ClCompile Include="Shader.cpp" />
|
||||||
<ClCompile Include="Skybox.cpp" />
|
|
||||||
<ClCompile Include="Source.cpp" />
|
<ClCompile Include="Source.cpp" />
|
||||||
<ClCompile Include="Texture.cpp" />
|
<ClCompile Include="Texture.cpp" />
|
||||||
<ClCompile Include="Viewer.cpp" />
|
<ClCompile Include="Viewer.cpp" />
|
||||||
@ -182,7 +181,6 @@
|
|||||||
<ClInclude Include="MyGLWindow.h" />
|
<ClInclude Include="MyGLWindow.h" />
|
||||||
<ClInclude Include="SceneContext.h" />
|
<ClInclude Include="SceneContext.h" />
|
||||||
<ClInclude Include="Shader.h" />
|
<ClInclude Include="Shader.h" />
|
||||||
<ClInclude Include="Skybox.h" />
|
|
||||||
<ClInclude Include="Texture.h" />
|
<ClInclude Include="Texture.h" />
|
||||||
<ClInclude Include="Viewer.h" />
|
<ClInclude Include="Viewer.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -69,9 +69,6 @@
|
|||||||
<ClCompile Include="Texture.cpp">
|
<ClCompile Include="Texture.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Skybox.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Multipass.cpp">
|
<ClCompile Include="Multipass.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -134,9 +131,6 @@
|
|||||||
<ClInclude Include="Texture.h">
|
<ClInclude Include="Texture.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Skybox.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Multipass.h">
|
<ClInclude Include="Multipass.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|||||||
@ -1,23 +1,29 @@
|
|||||||
#version 440
|
#version 440
|
||||||
layout (location = 0) out vec3 gPosition;
|
//layout (location = 0) out vec3 gPosition;
|
||||||
layout (location = 1) out vec3 gNormal;
|
//layout (location = 1) out vec3 gNormal;
|
||||||
layout (location = 2) out vec4 gAlbedoSpec;
|
//layout (location = 2) out vec4 gAlbedoSpec;
|
||||||
|
|
||||||
in vec2 TexCoords;
|
in vec2 TexCoords;
|
||||||
in vec3 FragPos;
|
in vec3 FragPos;
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
|
in vec3 RawColor;
|
||||||
|
|
||||||
uniform sampler2D[32] tex;
|
out vec3 FragColor;
|
||||||
|
|
||||||
|
uniform sampler2D tex;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// store the fragment position vector in the first gbuffer texture
|
//gPosition = FragPos;
|
||||||
gPosition = FragPos;
|
//gPosition = normalize(abs(FragPos));
|
||||||
// also store the per-fragment normals into the gbuffer
|
// gPosition = vec3(1,1,1);
|
||||||
gNormal = normalize(Normal);
|
//
|
||||||
// and the diffuse per-fragment color
|
// gNormal = normalize(Normal);
|
||||||
gAlbedoSpec.rgb = texture(tex[0], TexCoords).rgb;
|
//
|
||||||
// store specular intensity in gAlbedoSpec's alpha component
|
// gAlbedoSpec.rgb = vec3(1,0,1);
|
||||||
|
// gAlbedoSpec.a = 1;
|
||||||
|
//gAlbedoSpec.rgb = texture(tex, TexCoords).rgb;
|
||||||
//gAlbedoSpec.a = texture(texture_specular1, TexCoords).r;
|
//gAlbedoSpec.a = texture(texture_specular1, TexCoords).r;
|
||||||
gAlbedoSpec.a = 1;
|
|
||||||
|
FragColor = RawColor;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,20 +2,23 @@
|
|||||||
|
|
||||||
layout(location=0) in vec3 coord3d;
|
layout(location=0) in vec3 coord3d;
|
||||||
layout(location=1) in vec3 v_normal;
|
layout(location=1) in vec3 v_normal;
|
||||||
|
layout(location=2) in vec3 v_color;
|
||||||
layout(location=3) in vec2 v_texmap;
|
layout(location=3) in vec2 v_texmap;
|
||||||
|
|
||||||
out vec2 TexCoords;
|
out vec2 TexCoords;
|
||||||
out vec3 FragPos;
|
out vec3 FragPos;
|
||||||
|
out vec3 RawColor;
|
||||||
out vec3 Normal;
|
out vec3 Normal;
|
||||||
|
|
||||||
|
uniform mat4 mvp;
|
||||||
uniform mat3 NormalMatrix;
|
uniform mat3 NormalMatrix;
|
||||||
uniform mat4 ModelMatrix;
|
uniform mat4 ModelMatrix;
|
||||||
uniform mat4 mvp;
|
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
Normal = v_normal * NormalMatrix;
|
Normal = v_normal * NormalMatrix;
|
||||||
TexCoords = v_texmap;
|
TexCoords = v_texmap;
|
||||||
FragPos = (ModelMatrix * vec4(coord3d, 1.0f)).xyz;
|
|
||||||
gl_Position = mvp * vec4(coord3d, 1.0f);
|
gl_Position = mvp * vec4(coord3d, 1.0f);
|
||||||
|
FragPos = (ModelMatrix * vec4(coord3d, 1.0f)).xyz;
|
||||||
|
//FragPos = gl_Position.xyz;
|
||||||
}
|
}
|
||||||
@ -278,9 +278,8 @@ Mesh::MeshEntry::~MeshEntry() {
|
|||||||
/**
|
/**
|
||||||
* Renders this MeshEntry
|
* Renders this MeshEntry
|
||||||
**/
|
**/
|
||||||
void Mesh::MeshEntry::render(SceneContext &ctx, Shader *shd) {
|
void Mesh::MeshEntry::render(SceneContext &ctx, Shader &shd) {
|
||||||
|
|
||||||
textureBinding(shd);
|
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
if (renderType == NO_INDEX)
|
if (renderType == NO_INDEX)
|
||||||
{
|
{
|
||||||
@ -292,37 +291,15 @@ void Mesh::MeshEntry::render(SceneContext &ctx, Shader *shd) {
|
|||||||
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
||||||
glDrawElements(GL_TRIANGLES, size / sizeof(unsigned int), GL_UNSIGNED_INT, NULL);
|
glDrawElements(GL_TRIANGLES, size / sizeof(unsigned int), GL_UNSIGNED_INT, NULL);
|
||||||
}
|
}
|
||||||
textureUnbinding();
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::MeshEntry::textureBinding(Shader * shd)
|
|
||||||
{
|
|
||||||
for (GLuint i = 0; i < textures.size(); i++)
|
|
||||||
{
|
|
||||||
glActiveTexture(GL_TEXTURE0 + i);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textures[i].tex_ref);
|
|
||||||
shd->addUniform("tex[" + std::to_string(i) + "]", (int)i);
|
|
||||||
}
|
|
||||||
//if (textures.size() > 0)
|
|
||||||
//shd->addUniform("TexCount", (int)textures.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mesh::MeshEntry::textureUnbinding()
|
|
||||||
{
|
|
||||||
for (GLuint i = 0; i < textures.size(); i++)
|
|
||||||
{
|
|
||||||
glActiveTexture(GL_TEXTURE0 + i);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mesh constructor, loads the specified filename if supported by Assimp
|
* Mesh constructor, loads the specified filename if supported by Assimp
|
||||||
**/
|
**/
|
||||||
Mesh::Mesh(const char *filename, Shader *sh)
|
Mesh::Mesh(const char *filename, std::string vert_shd, std::string frag_shd)
|
||||||
{
|
{
|
||||||
shader = sh;
|
shader = Shader(vert_shd, frag_shd);
|
||||||
|
|
||||||
std::string fullname;
|
std::string fullname;
|
||||||
fullname = std::string("./Models/")+ std::string(filename);
|
fullname = std::string("./Models/")+ std::string(filename);
|
||||||
@ -340,31 +317,10 @@ Mesh::Mesh(const char *filename, Shader *sh)
|
|||||||
std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl;
|
std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load all textures
|
Mesh::Mesh(Dataset &set, std::string vert_shd, std::string frag_shd) : shader(vert_shd, frag_shd)
|
||||||
for (unsigned int i = 0; i < scene->mNumMaterials; i++)
|
|
||||||
{
|
{
|
||||||
aiMaterial* material = scene->mMaterials[i];
|
|
||||||
if (material->GetTextureCount(aiTextureType_DIFFUSE) > 0) { //we only care diffuse texture
|
|
||||||
aiString Path;
|
|
||||||
if (material->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL,
|
|
||||||
NULL, NULL) == AI_SUCCESS) {
|
|
||||||
std::string FullPath = directory + Path.data; //texture file
|
|
||||||
textures.emplace(FullPath, Texture(FullPath));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
|
|
||||||
meshEntries.push_back(new Mesh::MeshEntry(scene->mMeshes[i], scene, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Mesh::Mesh(Dataset &set, Shader *sh)
|
|
||||||
{
|
|
||||||
shader = sh;
|
|
||||||
|
|
||||||
meshEntries.push_back(new Mesh::MeshEntry(set, this));
|
meshEntries.push_back(new Mesh::MeshEntry(set, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,57 +336,9 @@ Mesh::~Mesh(void)
|
|||||||
meshEntries.clear();
|
meshEntries.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::enableCulling()
|
|
||||||
{
|
|
||||||
if (cullMode == NONE)
|
|
||||||
return;
|
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
glCullFace(cullMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mesh::disableCulling()
|
|
||||||
{
|
|
||||||
if (cullMode == NONE)
|
|
||||||
return;
|
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mesh::textureUnbinding()
|
|
||||||
{
|
|
||||||
for (GLuint i = 0; i < textures.size(); i++)
|
|
||||||
{
|
|
||||||
glActiveTexture(GL_TEXTURE0 + i);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mesh::textureBinding(Shader *shd)
|
|
||||||
{
|
|
||||||
int nmap_counter = 0;
|
|
||||||
int i = 0;
|
|
||||||
for (std::map<std::string, Texture>::iterator it = textures.begin(); it != textures.end(); ++it)
|
|
||||||
{
|
|
||||||
glActiveTexture(GL_TEXTURE0 + i);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, it->second.tex_ref);
|
|
||||||
//shd->applyTextureMaterial(it->second);
|
|
||||||
if (it->second.isNmap)
|
|
||||||
{
|
|
||||||
shd->addUniform("nmap", (int)i);
|
|
||||||
nmap_counter++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
shd->addUniform("tex[" + std::to_string(i - nmap_counter) + "]", (int)i);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
/*if (textures.size() > 0)
|
|
||||||
shd->addUniform("TexCount", (int)textures.size() - nmap_counter);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mesh::draw(SceneContext &ctx) {
|
void Mesh::draw(SceneContext &ctx) {
|
||||||
|
|
||||||
shader->enable();
|
shader.enable();
|
||||||
textureBinding(shader);
|
|
||||||
enableCulling();
|
|
||||||
for (unsigned int i = 0; i < meshEntries.size(); ++i) {
|
for (unsigned int i = 0; i < meshEntries.size(); ++i) {
|
||||||
|
|
||||||
MeshEntry * m = meshEntries[i];
|
MeshEntry * m = meshEntries[i];
|
||||||
@ -440,62 +348,20 @@ void Mesh::draw(SceneContext &ctx) {
|
|||||||
model.glPushMatrix();
|
model.glPushMatrix();
|
||||||
effectTransformations();
|
effectTransformations();
|
||||||
|
|
||||||
//Retrieving material data from the vertex
|
|
||||||
|
|
||||||
float shininess = meshEntries.at(i)->shininessStrength;
|
|
||||||
glm::vec3 diffuse = glm::vec3(meshEntries.at(i)->dcolor.r, meshEntries.at(i)->dcolor.g, meshEntries.at(i)->dcolor.b);
|
|
||||||
glm::vec3 specular = glm::vec3(meshEntries.at(i)->scolor.r, meshEntries.at(i)->scolor.g, meshEntries.at(i)->scolor.b);
|
|
||||||
glm::vec3 ambient = glm::vec3(meshEntries.at(i)->acolor.r, meshEntries.at(i)->acolor.g, meshEntries.at(i)->acolor.b);
|
|
||||||
|
|
||||||
if (glm::length(ambient) == 0 && textures.size() > 0 && textures.begin()->second.mat.enabled)
|
|
||||||
ambient = textures.begin()->second.mat.ka;
|
|
||||||
else if (glm::length(ambient) == 0)
|
|
||||||
ambient = glm::vec3(0.1, 0.1, 0.1);
|
|
||||||
|
|
||||||
if (glm::length(diffuse) == 0 && textures.size() > 0 && textures.begin()->second.mat.enabled)
|
|
||||||
diffuse = textures.begin()->second.mat.ks;
|
|
||||||
else if (glm::length(diffuse) == 0)
|
|
||||||
diffuse = glm::vec3(0.9, 0.9, 0.9);
|
|
||||||
|
|
||||||
if (glm::length(specular) == 0 && textures.size() > 0 && textures.begin()->second.mat.enabled)
|
|
||||||
specular = textures.begin()->second.mat.ks;
|
|
||||||
else if (glm::length(specular) == 0)
|
|
||||||
specular = glm::vec3(0.4, 0.4, 0.4);
|
|
||||||
|
|
||||||
if (shininess == 0 && textures.size() > 0 && textures.begin()->second.mat.enabled)
|
|
||||||
shininess = textures.begin()->second.mat.shininess;
|
|
||||||
else if (shininess == 0)
|
|
||||||
shininess = 150.0f;
|
|
||||||
|
|
||||||
shader->mat.ka = ambient;
|
|
||||||
shader->mat.kd = diffuse;
|
|
||||||
shader->mat.ks = specular;
|
|
||||||
shader->mat.shininess = shininess;
|
|
||||||
|
|
||||||
// Setting the space matrixes uniques to the object
|
// Setting the space matrixes uniques to the object
|
||||||
ctx.modelMatrix = model.getMatrix();
|
ctx.modelMatrix = model.getMatrix();
|
||||||
if (shader->uniformFlags & MVP_FLAG)
|
|
||||||
ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix;
|
ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix;
|
||||||
if (shader->uniformFlags & MODELVIEW_FLAG)
|
|
||||||
ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix;
|
ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix;
|
||||||
if (shader->uniformFlags & NORMAL_MAT_FLAG)
|
|
||||||
ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix)));
|
ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix)));
|
||||||
|
|
||||||
//Sending the uniform data to the shader
|
shader.addUniform("mvp", ctx.mvpMatrix);
|
||||||
|
shader.addUniform("NormalMatrix", ctx.normalMatrix);
|
||||||
shader->setUniforms(ctx);
|
shader.addUniform("ModelMatrix", ctx.modelMatrix);
|
||||||
|
|
||||||
meshEntries.at(i)->render(ctx, shader);
|
meshEntries.at(i)->render(ctx, shader);
|
||||||
model.glPopMatrix();
|
model.glPopMatrix();
|
||||||
}
|
}
|
||||||
disableCulling();
|
shader.disable();
|
||||||
textureUnbinding();
|
|
||||||
shader->disable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mesh::assignTexture(Texture &texture)
|
|
||||||
{
|
|
||||||
//textures.emplace_back(texture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::effectTransformations()
|
void Mesh::effectTransformations()
|
||||||
|
|||||||
@ -60,15 +60,15 @@ public:
|
|||||||
MeshEntry(Dataset &set, Mesh *m);
|
MeshEntry(Dataset &set, Mesh *m);
|
||||||
~MeshEntry();
|
~MeshEntry();
|
||||||
Mesh * parent;
|
Mesh * parent;
|
||||||
void render(SceneContext &ctx, Shader *shd);
|
void render(SceneContext &ctx, Shader &shd);
|
||||||
private:
|
private:
|
||||||
void textureBinding(Shader *shd);
|
void textureBinding(Shader *shd);
|
||||||
void textureUnbinding();
|
void textureUnbinding();
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mesh(const char *filename, Shader *sh);
|
Mesh(const char *filename, std::string vert_shd, std::string frag_shd);
|
||||||
Mesh(Dataset &dataset, Shader *sh);
|
Mesh(Dataset &dataset, std::string vert_shd, std::string frag_shd);
|
||||||
~Mesh(void);
|
~Mesh(void);
|
||||||
std::string directory;
|
std::string directory;
|
||||||
std::vector<MeshEntry*> meshEntries;
|
std::vector<MeshEntry*> meshEntries;
|
||||||
@ -97,7 +97,7 @@ public:
|
|||||||
void removeLastTransformations(int n);
|
void removeLastTransformations(int n);
|
||||||
glm::vec3 getPosition();
|
glm::vec3 getPosition();
|
||||||
|
|
||||||
Shader *shader;
|
Shader shader;
|
||||||
void draw(SceneContext &ctx);
|
void draw(SceneContext &ctx);
|
||||||
|
|
||||||
void assignTexture(Texture &texture);
|
void assignTexture(Texture &texture);
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
#include "MyGlWindow.h"
|
#include "MyGlWindow.h"
|
||||||
#include "FreeImage.h"
|
|
||||||
|
|
||||||
//Getting the projection matrix
|
//Getting the projection matrix
|
||||||
glm::mat4x4 perspective(float fovy, float aspect, float near, float far)
|
glm::mat4x4 perspective(float fovy, float aspect, float near, float far)
|
||||||
@ -84,62 +83,9 @@ void MyGlWindow::textureSetup()
|
|||||||
_scnctx.textures["CubeNmap"].isNmap = true;
|
_scnctx.textures["CubeNmap"].isNmap = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::shaderSetup()
|
|
||||||
{
|
|
||||||
shaders["Simple"] = new Shader("simple.vert", "simple.frag");
|
|
||||||
shaders["Simple"]->uniformFlags = ShaderFlags::MVP_FLAG;
|
|
||||||
|
|
||||||
shaders["BaseLight"] = new Shader("base_light.vert", "base_light.frag");
|
|
||||||
shaders["ShadowLight"] = new Shader("shadow_light.vert", "shadow_light.frag");
|
|
||||||
shaders["LightPOV"] = new Shader("light_pov.vert", "light_pov.frag");
|
|
||||||
shaders["LightPOV"]->uniformFlags = 0;
|
|
||||||
shaders["Fog"] = new Shader("fog.vert", "fog.frag");
|
|
||||||
|
|
||||||
shaders["TexBaseLight"] = new Shader("tex_base_light.vert", "tex_base_light.frag");
|
|
||||||
shaders["TexNmapLight"] = new Shader("nmap.vert", "nmap.frag");
|
|
||||||
shaders["TexNmapLight"]->uniformFlags &= ~ShaderFlags::KD_FLAG;
|
|
||||||
|
|
||||||
shaders["SpotLight"] = new Shader("spotlight.vert", "spotlight.frag");
|
|
||||||
shaders["SpotLight"]->light_type = Light::LightType::SPOT;
|
|
||||||
shaders["TexSpotLight"] = new Shader("tex_spotlight.vert", "tex_spotlight.frag");
|
|
||||||
shaders["TexSpotLight"]->light_type = Light::LightType::SPOT;
|
|
||||||
|
|
||||||
shaders["Silhouette"] = new Shader("silhouette.vert", "silhouette.frag");
|
|
||||||
shaders["Silhouette"]->uniformFlags = ShaderFlags::MVP_FLAG;
|
|
||||||
shaders["Silhouette"]->addUniform("fColor", glm::vec3(237 / 255, 229 / 255, 194 / 255));
|
|
||||||
shaders["Silhouette"]->addUniform("sil_offset", 0.1f);
|
|
||||||
|
|
||||||
shaders["Toon"] = new Shader("base_light.vert", "toon.frag");
|
|
||||||
//Removing useless specular component
|
|
||||||
shaders["Toon"]->uniformFlags &= ~ShaderFlags::KS_FLAG;
|
|
||||||
shaders["Toon"]->uniformFlags &= ~ShaderFlags::SHINE_FLAG;
|
|
||||||
|
|
||||||
shaders["Skybox"] = new Shader("skybox.vert", "skybox.frag");
|
|
||||||
shaders["Skybox"]->uniformFlags = MVP_FLAG | MODEL_MATRIX_FLAG | SKYBOX_TEX_FLAG;
|
|
||||||
shaders["Skybox"]->addUniform("RefractionIndex", glm::vec3(0.65, 0.67, 0.69));
|
|
||||||
|
|
||||||
shaders["DSGeometryPass"] = new Shader("DSGeometryPass.vert", "DSGeometryPass.frag");
|
|
||||||
shaders["DSGeometryPass"]->uniformFlags = MVP_FLAG;
|
|
||||||
|
|
||||||
shaders["DSLightPass"] = new Shader("DSLightPass.vert", "DSLightPass.frag");
|
|
||||||
shaders["DSLightPass"]->uniformFlags = LIGHTS_FLAG;
|
|
||||||
|
|
||||||
shaders["GBufferVisual"] = new Shader("GBufferVisual.vert", "GBufferVisual.frag");
|
|
||||||
shaders["GBufferVisual"]->uniformFlags = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyGlWindow::lightSetup()
|
void MyGlWindow::lightSetup()
|
||||||
{
|
{
|
||||||
//Showcase lights
|
|
||||||
_scnctx.lights.emplace("Spotlight1", Light(glm::vec3(0.8f), glm::vec4(10, 10, 10, 1)));
|
_scnctx.lights.emplace("Spotlight1", Light(glm::vec3(0.8f), glm::vec4(10, 10, 10, 1)));
|
||||||
// 24, 12, 2, glm::vec4(0, 1, 0, 1)));
|
|
||||||
|
|
||||||
//Party lights
|
|
||||||
//_scnctx.lights.emplace("Light1", Light(glm::vec3(0.0f, 0.5f, 0.5f), glm::vec4(10, 10, 0, 1)));
|
|
||||||
//_scnctx.lights.emplace("Light2", Light(glm::vec3(0.0f, 0.0f, 0.5f), glm::vec4(3.09, 10, 9.51, 1)));
|
|
||||||
//_scnctx.lights.emplace("Light3", Light(glm::vec3(0.5f, 0.0f, 0.0f), glm::vec4(-8.09, 10, 5.87, 1)));
|
|
||||||
//_scnctx.lights.emplace("Light4", Light(glm::vec3(0.0f, 0.5f, 0.0f), glm::vec4(-8.09, 10, -5.87, 1)));
|
|
||||||
//_scnctx.lights.emplace("Light5", Light(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec4(3.09, 10, -9.51, 1)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::multipassSetup()
|
void MyGlWindow::multipassSetup()
|
||||||
@ -152,16 +98,6 @@ void MyGlWindow::multipassSetup()
|
|||||||
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, "color_buffer");
|
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, "color_buffer");
|
||||||
|
|
||||||
_multipassManager.setDrawBuffers();
|
_multipassManager.setDrawBuffers();
|
||||||
|
|
||||||
|
|
||||||
//Standard post-process shader
|
|
||||||
/*_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "depthing");
|
|
||||||
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "blurring");
|
|
||||||
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "sharpening");
|
|
||||||
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "sepia");
|
|
||||||
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "grayscale");
|
|
||||||
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "sobel_filter");
|
|
||||||
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "absolutely_no_postprocess");*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::setup()
|
void MyGlWindow::setup()
|
||||||
@ -173,7 +109,6 @@ void MyGlWindow::setup()
|
|||||||
_scnctx.bg = glm::vec4(0.7, 0.7, 0.9, 1);
|
_scnctx.bg = glm::vec4(0.7, 0.7, 0.9, 1);
|
||||||
|
|
||||||
textureSetup();
|
textureSetup();
|
||||||
shaderSetup();
|
|
||||||
lightSetup();
|
lightSetup();
|
||||||
multipassSetup();
|
multipassSetup();
|
||||||
|
|
||||||
@ -205,22 +140,23 @@ void MyGlWindow::setup()
|
|||||||
std::srand(18);
|
std::srand(18);
|
||||||
|
|
||||||
int zob = std::rand();
|
int zob = std::rand();
|
||||||
for (int i = 0; i < 30; i++)
|
for (int i = 0; i < 1; i++)
|
||||||
{
|
{
|
||||||
std::string cube_name = "Cube" + std::to_string(i);
|
std::string cube_name = "Cube" + std::to_string(i);
|
||||||
meshes.emplace(cube_name, new Mesh("cube/cube.obj", shaders["DSGeometryPass"]));
|
meshes.emplace(cube_name, new Mesh(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag"));
|
||||||
meshes[cube_name]->textures["cube_tex"] = Texture("./Models/cube/color_map.png");
|
|
||||||
|
|
||||||
//float pos_x = std::rand() % 100 + 50;
|
/*meshes[cube_name]->textures["cube_tex"] = Texture("./Models/cube/color_map.png");
|
||||||
//float pos_z = std::rand() % 100 + 50;
|
|
||||||
|
float pos_x = std::rand() % 100 + 50;
|
||||||
|
float pos_z = std::rand() % 100 + 50;
|
||||||
|
|
||||||
|
meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0));
|
||||||
|
meshes[cube_name]->addStartTranslation(glm::vec4(pos_x, 0, 0, 0));
|
||||||
|
meshes[cube_name]->addStartTranslation(glm::vec4(0, 0, pos_z, 0));
|
||||||
|
meshes[cube_name]->addStartRotation(glm::vec4(1, 0, 0, std::rand() % 360));
|
||||||
|
meshes[cube_name]->addStartRotation(glm::vec4(0, 1, 0, std::rand() % 360));
|
||||||
|
meshes[cube_name]->addStartRotation(glm::vec4(0, 0, 1, std::rand() % 360));*/
|
||||||
|
|
||||||
//meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0));
|
|
||||||
//meshes[cube_name]->addStartTranslation(glm::vec4(pos_x, 0, 0, 0));
|
|
||||||
//meshes[cube_name]->addStartTranslation(glm::vec4(0, 0, pos_z, 0));
|
|
||||||
//meshes[cube_name]->addStartRotation(glm::vec4(1, 0, 0, std::rand() % 360));
|
|
||||||
//meshes[cube_name]->addStartRotation(glm::vec4(0, 1, 0, std::rand() % 360));
|
|
||||||
//meshes[cube_name]->addStartRotation(glm::vec4(0, 0, 1, std::rand() % 360));
|
|
||||||
//
|
|
||||||
//float light_r = (40 + std::rand() % 60) / 100.f;
|
//float light_r = (40 + std::rand() % 60) / 100.f;
|
||||||
//float light_g = (40 + std::rand() % 60) / 100.f;
|
//float light_g = (40 + std::rand() % 60) / 100.f;
|
||||||
//float light_b = (40 + std::rand() % 60) / 100.f;
|
//float light_b = (40 + std::rand() % 60) / 100.f;
|
||||||
@ -248,11 +184,12 @@ void MyGlWindow::draw()
|
|||||||
glViewport(0, 0, _scnctx.width, _scnctx.height);
|
glViewport(0, 0, _scnctx.width, _scnctx.height);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
_multipassManager.enableFrameBufferTexture("position_buffer");
|
//_multipassManager.enableFrameBufferTexture("position_buffer");
|
||||||
|
|
||||||
for (auto it = meshes.begin(); it != meshes.end(); it++)
|
for (auto it = meshes.begin(); it != meshes.end(); it++)
|
||||||
(*it).second->draw(_scnctx);
|
(*it).second->draw(_scnctx);
|
||||||
_multipassManager.drawResultToScreen(_scnctx);
|
|
||||||
|
//_multipassManager.drawResultToScreen(_scnctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::resize(int w, int h)
|
void MyGlWindow::resize(int w, int h)
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
#include "GL/glew.h"
|
#include "GL/glew.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Skybox.h"
|
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
#include "ModelView.h"
|
#include "ModelView.h"
|
||||||
#include "Viewer.h"
|
#include "Viewer.h"
|
||||||
@ -42,7 +41,6 @@ private:
|
|||||||
|
|
||||||
Multipass _multipassManager;
|
Multipass _multipassManager;
|
||||||
|
|
||||||
Skybox skybox;
|
|
||||||
GLuint _vaoHandle;
|
GLuint _vaoHandle;
|
||||||
GLuint _iboHandle;
|
GLuint _iboHandle;
|
||||||
|
|
||||||
|
|||||||
@ -19,75 +19,3 @@ void Shader::disable()
|
|||||||
_program.disable();
|
_program.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Shader::addSubroutine(GLenum shadertype, const std::string uniformName)
|
|
||||||
{
|
|
||||||
return _program.addSubroutine(shadertype, uniformName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shader::enableSubroutine(const std::string uniformName)
|
|
||||||
{
|
|
||||||
return _program.enableSubroutine(uniformName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shader::setMaterial(SceneContext ctx)
|
|
||||||
{
|
|
||||||
if ((uniformFlags & ShaderFlags::KA_FLAG) == ShaderFlags::KA_FLAG)
|
|
||||||
glUniform3fv(_program.addUniform("Ka"), 1, glm::value_ptr(mat.ka));
|
|
||||||
if ((uniformFlags & ShaderFlags::KD_FLAG) == ShaderFlags::KD_FLAG)
|
|
||||||
glUniform3fv(_program.addUniform("Kd"), 1, glm::value_ptr(mat.kd));
|
|
||||||
if ((uniformFlags & ShaderFlags::KS_FLAG) == ShaderFlags::KS_FLAG)
|
|
||||||
glUniform3fv(_program.addUniform("Ks"), 1, glm::value_ptr(mat.ks));
|
|
||||||
if ((uniformFlags & ShaderFlags::SHINE_FLAG) == ShaderFlags::SHINE_FLAG)
|
|
||||||
glUniform1f(_program.addUniform("Shininess"), mat.shininess);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shader::setCamera(SceneContext ctx)
|
|
||||||
{
|
|
||||||
if ((uniformFlags & ShaderFlags::MVP_FLAG) == ShaderFlags::MVP_FLAG)
|
|
||||||
glUniformMatrix4fv(_program.addUniform("mvp"), 1, GL_FALSE, glm::value_ptr(ctx.mvpMatrix));
|
|
||||||
if ((uniformFlags & ShaderFlags::NORMAL_MAT_FLAG) == ShaderFlags::NORMAL_MAT_FLAG)
|
|
||||||
glUniformMatrix3fv(_program.addUniform("NormalMatrix"), 1, GL_FALSE, glm::value_ptr(ctx.normalMatrix));
|
|
||||||
if ((uniformFlags & ShaderFlags::MODELVIEW_FLAG) == ShaderFlags::MODELVIEW_FLAG)
|
|
||||||
glUniformMatrix4fv(_program.addUniform("ModelViewMatrix"), 1, GL_FALSE, glm::value_ptr(ctx.modelViewMatrix));
|
|
||||||
if ((uniformFlags & ShaderFlags::MODEL_MATRIX_FLAG) == ShaderFlags::MODEL_MATRIX_FLAG)
|
|
||||||
glUniformMatrix4fv(_program.addUniform("ModelMatrix"), 1, GL_FALSE, glm::value_ptr(ctx.modelMatrix));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shader::setLights(SceneContext ctx)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
if ((uniformFlags & ShaderFlags::LIGHTS_FLAG) != ShaderFlags::LIGHTS_FLAG)
|
|
||||||
return;
|
|
||||||
for (auto light: ctx.lights)
|
|
||||||
{
|
|
||||||
if (light.second.activated && light.second.type == light_type)
|
|
||||||
{
|
|
||||||
std::string lightname = "Light[" + std::to_string(i) + "].";
|
|
||||||
|
|
||||||
glUniform4fv(_program.addUniform(lightname + "Position"), 1, glm::value_ptr(ctx.viewMatrix * light.second.location));
|
|
||||||
glUniform3fv(_program.addUniform(lightname + "Intensity"), 1, glm::value_ptr(light.second.intensity));
|
|
||||||
if (light.second.type == Light::LightType::SPOT)
|
|
||||||
{
|
|
||||||
glUniform1f(_program.addUniform(lightname + "SpotCutoff"), light.second.spot_cutoff);
|
|
||||||
glUniform1f(_program.addUniform(lightname + "SpotInnerCutoff"), light.second.spot_inner_cutoff);
|
|
||||||
glUniform1f(_program.addUniform(lightname + "SpotExponent"), light.second.spot_exponent);
|
|
||||||
glUniform3fv(_program.addUniform(lightname + "SpotDirection"), 1, glm::value_ptr(light.second.direction));
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glUniform1i(_program.addUniform("LightCount"), i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shader::setUniforms(SceneContext ctx)
|
|
||||||
{
|
|
||||||
setCamera(ctx);
|
|
||||||
setLights(ctx);
|
|
||||||
setMaterial(ctx);
|
|
||||||
|
|
||||||
if ((uniformFlags & ShaderFlags::SKYBOX_TEX_FLAG) == ShaderFlags::SKYBOX_TEX_FLAG)
|
|
||||||
{
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, ctx.skybox_tex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -11,21 +11,6 @@
|
|||||||
#include "Loader.h"
|
#include "Loader.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
enum ShaderFlags
|
|
||||||
{
|
|
||||||
NO_UNIFORM = 0,
|
|
||||||
KD_FLAG = 1,
|
|
||||||
KA_FLAG = 2,
|
|
||||||
KS_FLAG = 4,
|
|
||||||
SHINE_FLAG = 8,
|
|
||||||
MVP_FLAG = 16,
|
|
||||||
NORMAL_MAT_FLAG = 32,
|
|
||||||
MODELVIEW_FLAG = 64,
|
|
||||||
LIGHTS_FLAG = 128,
|
|
||||||
MODEL_MATRIX_FLAG = 256,
|
|
||||||
SKYBOX_TEX_FLAG = 512,
|
|
||||||
};
|
|
||||||
|
|
||||||
class Shader
|
class Shader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -33,16 +18,11 @@ public:
|
|||||||
Shader(const std::string vtx_name, const std::string frag_name);
|
Shader(const std::string vtx_name, const std::string frag_name);
|
||||||
~Shader();
|
~Shader();
|
||||||
|
|
||||||
int uniformFlags = KD_FLAG | KA_FLAG | KS_FLAG | SHINE_FLAG | MVP_FLAG | NORMAL_MAT_FLAG | MODELVIEW_FLAG | LIGHTS_FLAG;
|
|
||||||
Light::LightType light_type = Light::LightType::BASE;
|
|
||||||
Material mat;
|
Material mat;
|
||||||
|
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
int addSubroutine(GLenum shadertype, const std::string uniformName);
|
|
||||||
void enableSubroutine(const std::string uniformName);
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setUniforms(SceneContext ctx);
|
void setUniforms(SceneContext ctx);
|
||||||
@ -62,25 +42,15 @@ public:
|
|||||||
_program.use(); glUniform1fv(_program.addUniform(name), 1, &data);
|
_program.use(); glUniform1fv(_program.addUniform(name), 1, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addUniform(const std::string name, glm::mat3x3 &data)
|
||||||
|
{
|
||||||
|
_program.use(); glUniformMatrix3fv(_program.addUniform(name), 1, GL_FALSE, glm::value_ptr(data));
|
||||||
|
}
|
||||||
|
|
||||||
void addUniform(const std::string name, glm::mat4x4 &data)
|
void addUniform(const std::string name, glm::mat4x4 &data)
|
||||||
{
|
{
|
||||||
_program.use(); glUniformMatrix4fv(_program.addUniform(name), 1, GL_FALSE, glm::value_ptr(data));
|
_program.use(); glUniformMatrix4fv(_program.addUniform(name), 1, GL_FALSE, glm::value_ptr(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyTextureMaterial(Texture &tex)
|
|
||||||
{
|
|
||||||
if (mat.enabled)
|
|
||||||
{
|
|
||||||
addUniform("Ka", tex.mat.ka);
|
|
||||||
addUniform("Kd", tex.mat.kd);
|
|
||||||
addUniform("Ks", tex.mat.ks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setMaterial(SceneContext ctx);
|
|
||||||
void setCamera(SceneContext ctx);
|
|
||||||
void setLights(SceneContext ctx);
|
|
||||||
|
|
||||||
ShaderProgram _program;
|
ShaderProgram _program;
|
||||||
};
|
};
|
||||||
@ -1,141 +0,0 @@
|
|||||||
#include "Skybox.h"
|
|
||||||
#include "imgui/stb_image.h"
|
|
||||||
|
|
||||||
Skybox::Skybox()
|
|
||||||
{
|
|
||||||
float side = 50.0f; //size of cube
|
|
||||||
float side2 = side / 2.0f;
|
|
||||||
float v[24 * 3] = {
|
|
||||||
// Front
|
|
||||||
-side2, -side2, side2,
|
|
||||||
side2, -side2, side2,
|
|
||||||
side2, side2, side2,
|
|
||||||
-side2, side2, side2,
|
|
||||||
// Right
|
|
||||||
side2, -side2, side2,
|
|
||||||
side2, -side2, -side2,
|
|
||||||
side2, side2, -side2,
|
|
||||||
side2, side2, side2,
|
|
||||||
// Back
|
|
||||||
-side2, -side2, -side2,
|
|
||||||
-side2, side2, -side2,
|
|
||||||
side2, side2, -side2,
|
|
||||||
side2, -side2, -side2,
|
|
||||||
// Left
|
|
||||||
-side2, -side2, side2, //12
|
|
||||||
-side2, side2, side2, //13
|
|
||||||
-side2, side2, -side2, //14
|
|
||||||
-side2, -side2, -side2, //15
|
|
||||||
// Bottom
|
|
||||||
-side2, -side2, side2,
|
|
||||||
-side2, -side2, -side2,
|
|
||||||
side2, -side2, -side2,
|
|
||||||
side2, -side2, side2,
|
|
||||||
// Top
|
|
||||||
-side2, side2, side2,
|
|
||||||
side2, side2, side2,
|
|
||||||
side2, side2, -side2,
|
|
||||||
-side2, side2, -side2
|
|
||||||
};
|
|
||||||
|
|
||||||
GLuint el[] = {
|
|
||||||
0,2,1, 0,3,2, 4,6,5, 4,7,6,
|
|
||||||
8,10,9, 8,11,10, 12,14,13, 12,15,14,
|
|
||||||
16,18,17, 16,19,18, 20,22,21, 20,23,22
|
|
||||||
};
|
|
||||||
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
glGenBuffers(1, &vector_vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vector_vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, 24 * 3 * sizeof(GLfloat), v, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, NULL);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
|
|
||||||
glGenBuffers(1, &ibo);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 36 * sizeof(GLuint), el, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
|
||||||
glEnableVertexAttribArray(4);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Skybox::initialize(std::string skybox_dir, Shader *sky)
|
|
||||||
{
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glGenTextures(1, &texID); //set the texID as a member variable
|
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
|
|
||||||
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
||||||
|
|
||||||
const char * suffixes[] = { "left", "right", "top", "down", "back", "front"};
|
|
||||||
|
|
||||||
GLuint targets[] = {
|
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
int channel, width, height;
|
|
||||||
unsigned char *image;
|
|
||||||
std::string filename;
|
|
||||||
filename = std::string(skybox_dir + suffixes[i]) + std::string(".JPG");
|
|
||||||
image = stbi_load(filename.c_str(), &width, &height, &channel, 0);
|
|
||||||
glTexImage2D(targets[i], 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
stbi_image_free(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
|
||||||
sky->enable();
|
|
||||||
sky->addUniform("DrawSkyBox", (int)GL_FALSE);
|
|
||||||
sky->addUniform("CubeMapTex", (int)0);
|
|
||||||
sky->disable();
|
|
||||||
}
|
|
||||||
|
|
||||||
Skybox::~Skybox()
|
|
||||||
{
|
|
||||||
glDeleteBuffers(1, &vector_vbo);
|
|
||||||
glDeleteBuffers(1, &ibo);
|
|
||||||
glDeleteVertexArrays(1, &vao);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// //Things to add
|
|
||||||
// //Per model :
|
|
||||||
// // - ModelMatrix
|
|
||||||
// // - MaterialColor
|
|
||||||
|
|
||||||
void Skybox::draw(Shader *sky_shader, SceneContext &ctx)
|
|
||||||
{
|
|
||||||
sky_shader->enable();
|
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
glCullFace(GL_BACK);
|
|
||||||
glm::mat4x4 modelMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(scale));
|
|
||||||
glm::mat4x4 mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * modelMatrix;
|
|
||||||
sky_shader->addUniform("mvp", mvpMatrix);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
sky_shader->addUniform("DrawSkyBox", (int)GL_TRUE);
|
|
||||||
|
|
||||||
|
|
||||||
int size;
|
|
||||||
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
|
||||||
glDrawElements(GL_TRIANGLES, size / sizeof(GLuint), GL_UNSIGNED_INT, 0);
|
|
||||||
|
|
||||||
sky_shader->addUniform("DrawSkyBox", (int)GL_FALSE);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
sky_shader->disable();
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <GL/glew.h>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
|
|
||||||
#include <glm/mat4x4.hpp>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
#include <glm/gtc/matrix_inverse.hpp>
|
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
|
||||||
#include "Shader.h"
|
|
||||||
#include "SceneContext.h"
|
|
||||||
|
|
||||||
class Skybox
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
unsigned int vao;
|
|
||||||
unsigned int vector_vbo;
|
|
||||||
unsigned int ibo;
|
|
||||||
GLuint texID;
|
|
||||||
public:
|
|
||||||
Skybox();
|
|
||||||
float scale = 1;
|
|
||||||
void initialize(std::string skybox_dir, Shader *sky);
|
|
||||||
GLuint getTexID() { return texID; }
|
|
||||||
~Skybox();
|
|
||||||
void draw(Shader *sky_shader, SceneContext &ctx);
|
|
||||||
};
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user