Started workaround for textured .objs (not really finished), addded depth buffer and fixed emplacement of the glClear
This commit is contained in:
parent
03be372af2
commit
284650a034
@ -11,11 +11,10 @@ uniform sampler2D tex;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gPosition = FragPos;
|
gPosition = FragPos;
|
||||||
|
//
|
||||||
gNormal = normalize(Normal);
|
//gPosition = normalize(abs(FragPos));
|
||||||
|
gNormal = normalize(Normal);
|
||||||
gAlbedoSpec.rgb = texture(tex, TexCoords).rgb;
|
gAlbedoSpec.rgb = texture(tex, TexCoords).rgb;
|
||||||
gAlbedoSpec.a = 1;
|
gAlbedoSpec.a = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ uniform mat4 ModelMatrix;
|
|||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
Normal = NormalMatrix * v_normal;
|
Normal = NormalMatrix * v_normal;
|
||||||
TexCoords = v_texmap;
|
TexCoords = v_texmap;
|
||||||
gl_Position = mvp * vec4(coord3d, 1.0f);
|
|
||||||
FragPos = (ModelMatrix * vec4(coord3d, 1.0f)).xyz;
|
FragPos = (ModelMatrix * vec4(coord3d, 1.0f)).xyz;
|
||||||
|
gl_Position = mvp * vec4(coord3d, 1.0f);
|
||||||
}
|
}
|
||||||
@ -374,10 +374,11 @@ public:
|
|||||||
{
|
{
|
||||||
// Add the uniform location value for the uniformName key
|
// Add the uniform location value for the uniformName key
|
||||||
uniformMap[uniformName] = glGetUniformLocation(programId, uniformName.c_str());
|
uniformMap[uniformName] = glGetUniformLocation(programId, uniformName.c_str());
|
||||||
|
|
||||||
// Check to ensure that the shader contains a uniform with this name
|
// Check to ensure that the shader contains a uniform with this name
|
||||||
if (uniformMap[uniformName] == -1)
|
if (uniformMap[uniformName] == -1)
|
||||||
{
|
{
|
||||||
|
int error = glGetError();
|
||||||
throw std::runtime_error("Could not add uniform: " + uniformName + " - location returned -1.");
|
throw std::runtime_error("Could not add uniform: " + uniformName + " - location returned -1.");
|
||||||
}
|
}
|
||||||
else // Valid uniform location? Inform user if we're in debug mode.
|
else // Valid uniform location? Inform user if we're in debug mode.
|
||||||
|
|||||||
@ -297,10 +297,8 @@ void Mesh::MeshEntry::render(SceneContext &ctx, Shader &shd) {
|
|||||||
/**
|
/**
|
||||||
* 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, std::string vert_shd, std::string frag_shd)
|
Mesh::Mesh(const char *filename, std::string vert_shd, std::string frag_shd) : shader(vert_shd, frag_shd)
|
||||||
{
|
{
|
||||||
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);
|
||||||
directory = fullname;
|
directory = fullname;
|
||||||
@ -320,6 +318,21 @@ Mesh::Mesh(const char *filename, std::string vert_shd, std::string frag_shd)
|
|||||||
|
|
||||||
for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
|
for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
|
||||||
meshEntries.push_back(new Mesh::MeshEntry(scene->mMeshes[i], scene, this));
|
meshEntries.push_back(new Mesh::MeshEntry(scene->mMeshes[i], scene, this));
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < scene->mNumMaterials; i++)
|
||||||
|
{
|
||||||
|
aiMaterial* material = scene->mMaterials[i];
|
||||||
|
if (material->GetTextureCount(aiTextureType_DIFFUSE) > 0)
|
||||||
|
{
|
||||||
|
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("0", Texture(FullPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -134,7 +134,7 @@ void Multipass::drawDeferredLightToScreen(SceneContext &scnctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Multipass::drawGBufferToScreen(SceneContext & scnctx)
|
void Multipass::drawGBufferToScreen(SceneContext & scnctx)
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
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);
|
||||||
|
|||||||
@ -97,12 +97,12 @@ void MyGlWindow::multipassSetup()
|
|||||||
_multipassManager.addTexture("position_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_FLOAT, false, _scnctx);
|
_multipassManager.addTexture("position_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_FLOAT, false, _scnctx);
|
||||||
_multipassManager.addTexture("normal_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_UNSIGNED_BYTE, false, _scnctx);
|
_multipassManager.addTexture("normal_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_UNSIGNED_BYTE, false, _scnctx);
|
||||||
_multipassManager.addTexture("color_buffer", GL_NEAREST, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false, _scnctx);
|
_multipassManager.addTexture("color_buffer", GL_NEAREST, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false, _scnctx);
|
||||||
//_multipassManager.addTexture("depth_tex", GL_LINEAR, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_FLOAT, true, _scnctx);
|
_multipassManager.addTexture("depth_tex", GL_LINEAR, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_FLOAT, true, _scnctx);
|
||||||
|
|
||||||
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, "position_buffer");
|
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, "position_buffer");
|
||||||
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, "normal_buffer");
|
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, "normal_buffer");
|
||||||
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, "color_buffer");
|
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, "color_buffer");
|
||||||
//_multipassManager.bindToFrameBuffer(GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, "depth_tex");
|
_multipassManager.bindToFrameBuffer(GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, "depth_tex");
|
||||||
|
|
||||||
_multipassManager.setDrawBuffers();
|
_multipassManager.setDrawBuffers();
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ void MyGlWindow::setup()
|
|||||||
{
|
{
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_DEPTH_BUFFER);
|
glEnable(GL_DEPTH_BUFFER);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
_scnctx.bg = glm::vec4(0.7, 0.7, 0.9, 1);
|
_scnctx.bg = glm::vec4(0.7, 0.7, 0.9, 1);
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ void MyGlWindow::setup()
|
|||||||
//Scene for GBuffer Testing
|
//Scene for GBuffer Testing
|
||||||
Mesh *mountain = new Mesh("mountain/mount.blend1.obj", "DSGeometryPass.vert", "DSGeometryPass.frag");
|
Mesh *mountain = new Mesh("mountain/mount.blend1.obj", "DSGeometryPass.vert", "DSGeometryPass.frag");
|
||||||
|
|
||||||
meshes.emplace("Nanosuit_A", mountain);
|
meshes.emplace("mountain", mountain);
|
||||||
|
|
||||||
_scnctx.lights.emplace("RandLight",
|
_scnctx.lights.emplace("RandLight",
|
||||||
Light(glm::vec3(1, 1, 1), glm::vec4(0, 2, 0, 1)));
|
Light(glm::vec3(1, 1, 1), glm::vec4(0, 2, 0, 1)));
|
||||||
@ -183,17 +183,14 @@ void MyGlWindow::drawDeferredLight()
|
|||||||
_scnctx.projectionMatrix = projection;
|
_scnctx.projectionMatrix = projection;
|
||||||
|
|
||||||
glClearColor(_scnctx.bg.r, _scnctx.bg.g, _scnctx.bg.b, _scnctx.bg.a);
|
glClearColor(_scnctx.bg.r, _scnctx.bg.g, _scnctx.bg.b, _scnctx.bg.a);
|
||||||
glViewport(0, 0, _scnctx.width, _scnctx.height);
|
glViewport(0, 0, _scnctx.width, _scnctx.height);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
_multipassManager.enableFrameBufferTexture(_scnctx.fboDisplayName);
|
_multipassManager.enableFrameBufferTexture(_scnctx.fboDisplayName);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
glCullFace(GL_BACK);
|
|
||||||
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);
|
||||||
|
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
_multipassManager.drawDeferredLightToScreen(_scnctx);
|
_multipassManager.drawDeferredLightToScreen(_scnctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,17 +213,14 @@ void MyGlWindow::drawDebugGBuffer()
|
|||||||
_scnctx.projectionMatrix = projection;
|
_scnctx.projectionMatrix = projection;
|
||||||
|
|
||||||
glClearColor(_scnctx.bg.r, _scnctx.bg.g, _scnctx.bg.b, _scnctx.bg.a);
|
glClearColor(_scnctx.bg.r, _scnctx.bg.g, _scnctx.bg.b, _scnctx.bg.a);
|
||||||
glViewport(0, 0, _scnctx.width, _scnctx.height);
|
glViewport(0, 0, _scnctx.width, _scnctx.height);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
_multipassManager.enableFrameBufferTexture(_scnctx.fboDisplayName);
|
_multipassManager.enableFrameBufferTexture(_scnctx.fboDisplayName);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
glCullFace(GL_BACK);
|
|
||||||
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);
|
||||||
|
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
_multipassManager.drawGBufferToScreen(_scnctx);
|
_multipassManager.drawGBufferToScreen(_scnctx);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user