Started workaround for textured .objs (not really finished), addded depth buffer and fixed emplacement of the glClear

This commit is contained in:
Hurlu 2019-06-14 17:31:36 +09:00
parent 03be372af2
commit 284650a034
6 changed files with 37 additions and 30 deletions

View File

@ -11,11 +11,10 @@ uniform sampler2D tex;
void main()
{
gPosition = FragPos;
gNormal = normalize(Normal);
gAlbedoSpec.rgb = texture(tex, TexCoords).rgb;
gPosition = FragPos;
//
//gPosition = normalize(abs(FragPos));
gNormal = normalize(Normal);
gAlbedoSpec.rgb = texture(tex, TexCoords).rgb;
gAlbedoSpec.a = 1;
}

View File

@ -16,7 +16,7 @@ uniform mat4 ModelMatrix;
void main(void)
{
Normal = NormalMatrix * v_normal;
TexCoords = v_texmap;
gl_Position = mvp * vec4(coord3d, 1.0f);
TexCoords = v_texmap;
FragPos = (ModelMatrix * vec4(coord3d, 1.0f)).xyz;
gl_Position = mvp * vec4(coord3d, 1.0f);
}

View File

@ -374,10 +374,11 @@ public:
{
// Add the uniform location value for the uniformName key
uniformMap[uniformName] = glGetUniformLocation(programId, uniformName.c_str());
// Check to ensure that the shader contains a uniform with this name
if (uniformMap[uniformName] == -1)
{
int error = glGetError();
throw std::runtime_error("Could not add uniform: " + uniformName + " - location returned -1.");
}
else // Valid uniform location? Inform user if we're in debug mode.

View File

@ -297,10 +297,8 @@ void Mesh::MeshEntry::render(SceneContext &ctx, Shader &shd) {
/**
* 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;
fullname = std::string("./Models/")+ std::string(filename);
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) {
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));
}
}
}
}
}

View File

@ -134,7 +134,7 @@ void Multipass::drawDeferredLightToScreen(SceneContext &scnctx)
}
void Multipass::drawGBufferToScreen(SceneContext & scnctx)
{
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, scnctx.width, scnctx.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

View File

@ -97,12 +97,12 @@ void MyGlWindow::multipassSetup()
_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("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_ATTACHMENT1, GL_TEXTURE_2D, "normal_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();
}
@ -111,7 +111,7 @@ void MyGlWindow::setup()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_DEPTH_BUFFER);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
_scnctx.bg = glm::vec4(0.7, 0.7, 0.9, 1);
@ -124,7 +124,7 @@ void MyGlWindow::setup()
//Scene for GBuffer Testing
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",
Light(glm::vec3(1, 1, 1), glm::vec4(0, 2, 0, 1)));
@ -183,17 +183,14 @@ void MyGlWindow::drawDeferredLight()
_scnctx.projectionMatrix = projection;
glClearColor(_scnctx.bg.r, _scnctx.bg.g, _scnctx.bg.b, _scnctx.bg.a);
glViewport(0, 0, _scnctx.width, _scnctx.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, _scnctx.width, _scnctx.height);
_multipassManager.enableFrameBufferTexture(_scnctx.fboDisplayName);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (auto it = meshes.begin(); it != meshes.end(); it++)
(*it).second->draw(_scnctx);
glDisable(GL_CULL_FACE);
_multipassManager.drawDeferredLightToScreen(_scnctx);
}
@ -216,17 +213,14 @@ void MyGlWindow::drawDebugGBuffer()
_scnctx.projectionMatrix = projection;
glClearColor(_scnctx.bg.r, _scnctx.bg.g, _scnctx.bg.b, _scnctx.bg.a);
glViewport(0, 0, _scnctx.width, _scnctx.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, _scnctx.width, _scnctx.height);
_multipassManager.enableFrameBufferTexture(_scnctx.fboDisplayName);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (auto it = meshes.begin(); it != meshes.end(); it++)
(*it).second->draw(_scnctx);
glDisable(GL_CULL_FACE);
_multipassManager.drawGBufferToScreen(_scnctx);
}