Looks like the G-buffer debug is working alright

This commit is contained in:
Hugo Willaume 2019-06-10 14:02:05 +09:00
parent fe5a3b2541
commit fe58218c7e
8 changed files with 40 additions and 19 deletions

View File

@ -12,8 +12,6 @@ uniform sampler2D tex;
void main() void main()
{ {
gPosition = FragPos; gPosition = FragPos;
//gPosition = normalize(abs(FragPos));
//gPosition = vec3(1,1,1);
gNormal = normalize(Normal); gNormal = normalize(Normal);

View File

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

View File

@ -96,7 +96,9 @@ private:
glGetShaderiv(shaderId, GL_COMPILE_STATUS, &shaderStatus); glGetShaderiv(shaderId, GL_COMPILE_STATUS, &shaderStatus);
if (shaderStatus == GL_FALSE) if (shaderStatus == GL_FALSE)
{ {
throw std::runtime_error(shaderTypeString + " compilation failed: " + getInfoLog(ObjectType::SHADER, shaderId)); std::string err = getInfoLog(ObjectType::SHADER, shaderId);
std::cout << err << std::endl;
throw std::runtime_error(shaderTypeString + " compilation failed: " + err);
} }
else else
{ {

View File

@ -352,11 +352,11 @@ void Mesh::draw(SceneContext &ctx) {
ctx.modelMatrix = model.getMatrix(); ctx.modelMatrix = model.getMatrix();
ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix; ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix;
ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix; ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix;
ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix))); ctx.normalMatrix = glm::transpose(glm::inverse(glm::mat3(ctx.modelMatrix)));
shader.addUniform("mvp", ctx.mvpMatrix); shader.addUniform("mvp", ctx.mvpMatrix);
//shader.addUniform("NormalMatrix", ctx.normalMatrix); shader.addUniform("NormalMatrix", ctx.normalMatrix);
//shader.addUniform("ModelMatrix", ctx.modelMatrix); shader.addUniform("ModelMatrix", ctx.modelMatrix);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);

View File

@ -150,12 +150,12 @@ void MyGlWindow::setup()
float pos_x = std::rand() % 100 - 50; float pos_x = std::rand() % 100 - 50;
float pos_z = 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(0, 1, 0, 0));
meshes[cube_name]->addStartTranslation(glm::vec4(pos_x, 0, 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]->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(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, 1, 0, std::rand() % 360));
meshes[cube_name]->addStartRotation(glm::vec4(0, 0, 1, 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;
@ -184,12 +184,17 @@ 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(_scnctx.fbo_display_name);
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.drawResultToScreen(_scnctx); _multipassManager.drawResultToScreen(_scnctx);
} }
void MyGlWindow::resize(int w, int h) void MyGlWindow::resize(int w, int h)

View File

@ -27,6 +27,8 @@ struct SceneContext
GLuint width; GLuint width;
glm::vec4 bg; glm::vec4 bg;
std::string fbo_display_name;
void adjustSpots() void adjustSpots()
{ {
for (auto it : lights) for (auto it : lights)

View File

@ -169,21 +169,32 @@ int loop(GLFWwindow *window)
int fps = 60; int fps = 60;
double previousTime = glfwGetTime(); double previousTime = glfwGetTime();
glWin._scnctx.fbo_display_name = "position_buffer";
bool is_selected = false;
while (!glfwWindowShouldClose(window)) while (!glfwWindowShouldClose(window))
{ {
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
/*if (ImGui::Begin("First Window")) if (ImGui::Begin("Scene settings"))
{ {
ImGui::SetWindowPos(ImVec2(20, 20)); if (ImGui::BeginCombo("Debug Buffer", "Choose here"))
{
if (ImGui::Selectable("Position buffer", &is_selected, 0, ImVec2(120, 10)))
glWin._scnctx.fbo_display_name = "position_buffer";
if (ImGui::Selectable("Normal buffer", &is_selected, 0, ImVec2(120, 10)))
glWin._scnctx.fbo_display_name = "normal_buffer";
if (ImGui::Selectable("Color buffer", &is_selected, 0, ImVec2(120, 10)))
glWin._scnctx.fbo_display_name = "color_buffer";
static float bgColor[3] = { 0.6f, 0.6f, 0.9f }; ImGui::EndCombo();
ImGui::ColorEdit3("Background", bgColor, 0);
glWin.setBgColor(bgColor);
} }
ImGui::End();*/
ImGui::SetWindowPos(ImVec2(20, 20));
}
ImGui::End();
double currentTime = glfwGetTime(); double currentTime = glfwGetTime();
frameCount++; frameCount++;

View File

@ -53,3 +53,8 @@ Pos=1030,20
Size=85,32 Size=85,32
Collapsed=0 Collapsed=0
[Window][Scene settings]
Pos=20,20
Size=309,85
Collapsed=0