diff --git a/BaseGLProject/BaseGLProject.vcxproj b/BaseGLProject/BaseGLProject.vcxproj index 6e687b5..608ebc7 100644 --- a/BaseGLProject/BaseGLProject.vcxproj +++ b/BaseGLProject/BaseGLProject.vcxproj @@ -194,6 +194,10 @@ + + + + diff --git a/BaseGLProject/BaseGLProject.vcxproj.filters b/BaseGLProject/BaseGLProject.vcxproj.filters index 1ea1d8b..3c1b08f 100644 --- a/BaseGLProject/BaseGLProject.vcxproj.filters +++ b/BaseGLProject/BaseGLProject.vcxproj.filters @@ -223,16 +223,16 @@ MankyuCode - + Shaders - + Shaders - + Shaders - + Shaders diff --git a/BaseGLProject/DSGeometryPass.frag b/BaseGLProject/DSGeometryPass.frag new file mode 100644 index 0000000..bdd4f1a --- /dev/null +++ b/BaseGLProject/DSGeometryPass.frag @@ -0,0 +1,10 @@ +#version 440 +//Copy of simple.frag + +in vec3 f_color; +out vec4 FragColors; + +void main() +{ + FragColors = vec4(f_color, 1.f); +} diff --git a/BaseGLProject/DSGeometryPass.vert b/BaseGLProject/DSGeometryPass.vert new file mode 100644 index 0000000..3fc7cf5 --- /dev/null +++ b/BaseGLProject/DSGeometryPass.vert @@ -0,0 +1,18 @@ +#version 440 +// Copy of simple.vert + +layout(location=0) in vec3 coord3d; +layout(location=1) in vec3 v_normal; +layout(location=2) in vec3 v_color; +layout(location=3) in vec2 v_texmap; + + +out vec3 f_color; + +uniform mat4 mvp; + +void main(void) +{ + f_color = v_color; + gl_Position = mvp * vec4(coord3d, 1.0f); +} \ No newline at end of file diff --git a/BaseGLProject/DSLightPass.frag b/BaseGLProject/DSLightPass.frag new file mode 100644 index 0000000..bdd4f1a --- /dev/null +++ b/BaseGLProject/DSLightPass.frag @@ -0,0 +1,10 @@ +#version 440 +//Copy of simple.frag + +in vec3 f_color; +out vec4 FragColors; + +void main() +{ + FragColors = vec4(f_color, 1.f); +} diff --git a/BaseGLProject/DSLightPass.vert b/BaseGLProject/DSLightPass.vert new file mode 100644 index 0000000..3fc7cf5 --- /dev/null +++ b/BaseGLProject/DSLightPass.vert @@ -0,0 +1,18 @@ +#version 440 +// Copy of simple.vert + +layout(location=0) in vec3 coord3d; +layout(location=1) in vec3 v_normal; +layout(location=2) in vec3 v_color; +layout(location=3) in vec2 v_texmap; + + +out vec3 f_color; + +uniform mat4 mvp; + +void main(void) +{ + f_color = v_color; + gl_Position = mvp * vec4(coord3d, 1.0f); +} \ No newline at end of file diff --git a/BaseGLProject/Models/Mesh.cpp b/BaseGLProject/Models/Mesh.cpp index ff1a971..324fea8 100644 --- a/BaseGLProject/Models/Mesh.cpp +++ b/BaseGLProject/Models/Mesh.cpp @@ -476,9 +476,12 @@ void Mesh::draw(SceneContext &ctx) { // Setting the space matrixes uniques to the object ctx.modelMatrix = model.getMatrix(); - ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix; - ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix; - ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix))); + if (shader->uniformFlags & MVP_FLAG) + ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix; + if (shader->uniformFlags & MODELVIEW_FLAG) + ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix; + if (shader->uniformFlags & NORMAL_MAT_FLAG) + ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix))); //Sending the uniform data to the shader @@ -516,6 +519,21 @@ void Mesh::effectTransformations() } } +void Mesh::addStartRotation(glm::vec4 vec) +{ + model.glRotate(vec.w, vec.x, vec.y, vec.z); +} + +void Mesh::addStartTranslation(glm::vec4 vec) +{ + model.glTranslate(vec.x, vec.y, vec.z); +} + +void Mesh::addStartScaling(glm::vec4 vec) +{ + model.glScale(vec.x, vec.y, vec.z); +} + void Mesh::addRotation(glm::vec4 vec) { _transformations.emplace_back(vec, Rotation); diff --git a/BaseGLProject/Models/Mesh.h b/BaseGLProject/Models/Mesh.h index 95afea0..6902160 100644 --- a/BaseGLProject/Models/Mesh.h +++ b/BaseGLProject/Models/Mesh.h @@ -88,6 +88,11 @@ public: void addRotation(glm::vec4 vec); void addTranslation(glm::vec4 vec); void addScaling(glm::vec4 vec); + + void addStartRotation(glm::vec4 vec); + void addStartTranslation(glm::vec4 vec); + void addStartScaling(glm::vec4 vec); + glm::vec4 translateToPivot(glm::vec3); void removeLastTransformations(int n); glm::vec3 getPosition(); diff --git a/BaseGLProject/MyGLWindow.cpp b/BaseGLProject/MyGLWindow.cpp index d84504b..65fb7f8 100644 --- a/BaseGLProject/MyGLWindow.cpp +++ b/BaseGLProject/MyGLWindow.cpp @@ -116,6 +116,12 @@ void MyGlWindow::shaderSetup() 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 | KA_FLAG | KD_FLAG | KS_FLAG | SHINE_FLAG; + + shaders["DSLightPass"] = new Shader("DSLightPass.vert", "DSLightPass.frag"); + shaders["DSLightPass"]->uniformFlags = LIGHTS_FLAG; + } void MyGlWindow::lightSetup() @@ -144,13 +150,13 @@ void MyGlWindow::multipassSetup() _multipassManager.setDrawBuffers(); - _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, "no_postprocess"); + _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() @@ -166,6 +172,30 @@ void MyGlWindow::setup() _scnctx.skybox_tex = skybox.getTexID(); lightSetup(); multipassSetup(); + + Dataset moddata; + moddata.checkeredFloor(100, 100, glm::vec3(0.1, 0.1, 0.1), glm::vec3(0.7, 0.7, 0.7)); + //TODO : replace by specific light shader that supports color channel (and not just materials) + meshes.emplace("Floor", new Mesh(moddata, shaders["BaseLight"])); + + moddata.simpleCube(); + + //Hardcoded seed for easy scene replication + std::srand(18); + + int zob = std::rand(); + for (int i = 0; i < 100; i++) + { + std::string cube_name = "Cube" + std::to_string(i); + meshes.emplace(cube_name, new Mesh(moddata, shaders["Simple"])); + meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0)); + meshes[cube_name]->addStartTranslation(glm::vec4(std::rand() % 100 - 50, 0, 0, 0)); + meshes[cube_name]->addStartTranslation(glm::vec4(0, 0, std::rand() % 100 - 50, 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.emplace("Ogre", new Mesh("ogre/ogre.obj", shaders["TexNmapLight"])); //meshes["Ogre"]->addTranslation(glm::vec4(-0.5, 1, 0, 0)); @@ -248,26 +278,12 @@ void MyGlWindow::draw() 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); - - //shaders["Skybox"]->addUniform("WorldCamPos", eye); + for (auto it = meshes.begin(); it != meshes.end(); it++) (*it).second->draw(_scnctx); - - GLuint depth_tex = _multipassManager.getCurrentTexture(); - /*_multipassManager.enableFrameBufferTexture("render_tex"); - - for (auto it = meshes.begin(); it != meshes.end(); it++) - { - (*it).second->shader = shaders["ShadowLight"]; - (*it).second->shader->addUniform("lightmvp", lightMVP); - (*it).second->shader->addUniform("depth_tex", (int)depth_tex); - (*it).second->draw(_scnctx); - }*/ - - _multipassManager.shader->enableSubroutine("depthing"); - _multipassManager.drawResultToScreen(_scnctx); - //skybox.draw(shaders["Skybox"], _scnctx); + + _multipassManager.drawResultToScreen(_scnctx); } diff --git a/BaseGLProject/Source.cpp b/BaseGLProject/Source.cpp index 6668ab9..de6a43b 100644 --- a/BaseGLProject/Source.cpp +++ b/BaseGLProject/Source.cpp @@ -165,6 +165,10 @@ int loop(GLFWwindow *window) glfwGetWindowSize(window, &width, &heigth); MyGlWindow glWin(width, heigth); + int frameCount = 0; + int fps = 60; + double previousTime = glfwGetTime(); + while (!glfwWindowShouldClose(window)) { ImGui_ImplOpenGL3_NewFrame(); @@ -188,7 +192,27 @@ int loop(GLFWwindow *window) } ImGui::End(); + + double currentTime = glfwGetTime(); + frameCount++; + // If a second has passed. + if (currentTime - previousTime >= 1.0) + { + fps = frameCount; + frameCount = 0; + previousTime = currentTime; + } + + if (ImGui::Begin("FPSCounter", false, + ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing)) + { + ImGui::TextColored(ImVec4(1, 1, 0, 1), std::to_string(fps).c_str()); + + } + ImGui::End(); + ImGui::SetWindowPos("FPSCounter", ImVec2(width - 50, 20), ImGuiCond_Once); + glfwSwapBuffers(window); glWin.draw(); diff --git a/BaseGLProject/imgui.ini b/BaseGLProject/imgui.ini index 44dd3c0..3e13a1e 100644 --- a/BaseGLProject/imgui.ini +++ b/BaseGLProject/imgui.ini @@ -48,3 +48,8 @@ Pos=20,20 Size=357,188 Collapsed=0 +[Window][FPSCounter] +Pos=1030,20 +Size=85,32 +Collapsed=0 + diff --git a/BaseGLProject/textureViewer.frag b/BaseGLProject/textureViewer.frag index 731ba1d..f325e33 100644 --- a/BaseGLProject/textureViewer.frag +++ b/BaseGLProject/textureViewer.frag @@ -17,6 +17,12 @@ vec2 offsets[9] = vec2[]( vec2(-f, -f), vec2(0.0, -f), vec2(f, -f) ); +subroutine(shading_t) +vec4 absolutely_no_postprocess(vec4 color) +{ + return color; +} + subroutine(shading_t) vec4 sepia(vec4 color) {