diff --git a/Game/src/MainState.cpp b/Game/src/MainState.cpp index 1677927..858a619 100644 --- a/Game/src/MainState.cpp +++ b/Game/src/MainState.cpp @@ -14,18 +14,18 @@ void MainState::onEnter() { uiTex.create(nf::BaseAssets::logo, nf::Vec2(0.025, 0.025), 0.5); button.create(nf::Vec2(0.8, 0.025), "Reset"); button2.create(nf::Vec2(0.6, 0.025), "Play Sound"); - light.create(nf::Vec3(-5.0, 10.0, 5.0), nf::Vec3(1.0, 1.0, 1.0)); + light.create(nf::Vec3(0.0, 20.0, 0.0), nf::Vec3(1.0, 1.0, 1.0)); + light2.create(nf::Vec3(-10.0, 20.0, -10.0), nf::Vec3(1.0, 1.0, 1.0)); + light3.create(nf::Vec3(10.0, 20.0, 10.0), nf::Vec3(1.0, 1.0, 1.0)); cm.create(nf::BaseAssets::cubemap); sound.create(ap["sound.wav"]); for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { - for (int z = 0; z < 10; z++) { entities.push_back(new nf::Entity); entities.back()->create(ap["spec.obj"]); - entities.back()->setPosition(5.0 + x * 2.1, 0.05 + z * 2.1, -5.0 + y * 2.1); - } + entities.back()->setPosition(5.0 + x * 2.1, 0.05, -5.0 + y * 2.1); } } } @@ -61,7 +61,7 @@ void MainState::update(double deltaTime) { xrot += offset; if (app->isKeyHeld(NFI_RIGHT)) xrot -= offset; - plane.setRotation(nf::Vec3(yrot * 10.0, 0.0, yrot * 10.0)); + light.setPosition(nf::Vec3(0.0, yrot / 20.0 + 5.0, 0.0)); text.setText("FPS: " + std::to_string(app->getFPS())); @@ -78,6 +78,8 @@ void MainState::render(nf::Renderer& renderer) { renderer.render(test); renderer.render(plane); renderer.render(light); + renderer.render(light2); + renderer.render(light3); renderer.render(text); renderer.render(uiTex); renderer.render(button); @@ -91,4 +93,6 @@ void MainState::render(nf::Renderer& renderer) { void MainState::onExit() { Log("MainState onExit!"); xrot = yrot = 0.0f; + + entities.clear(); } \ No newline at end of file diff --git a/Game/src/include/MainState.h b/Game/src/include/MainState.h index bcc8e30..3febb4d 100644 --- a/Game/src/include/MainState.h +++ b/Game/src/include/MainState.h @@ -18,6 +18,8 @@ private: nf::Button button; nf::Button button2; nf::Light light; + nf::Light light2; + nf::Light light3; nf::Cubemap cm; nf::Sound sound; diff --git a/NFPackCreator/AssetBuild/base/shaders/fadeVertex.shader b/NFPackCreator/AssetBuild/base/shaders/fadeVertex.shader index 200a0c8..7260344 100644 --- a/NFPackCreator/AssetBuild/base/shaders/fadeVertex.shader +++ b/NFPackCreator/AssetBuild/base/shaders/fadeVertex.shader @@ -3,5 +3,5 @@ layout(location = 0) in vec2 pos; void main() { - gl_Position = vec4(pos.xy, 0.0, 1.0); + gl_Position = vec4(pos, 0.0, 1.0); } \ No newline at end of file diff --git a/NFPackCreator/AssetBuild/base/shaders/gBufferFragment.shader b/NFPackCreator/AssetBuild/base/shaders/gBufferFragment.shader index d0f79d9..1077c04 100644 --- a/NFPackCreator/AssetBuild/base/shaders/gBufferFragment.shader +++ b/NFPackCreator/AssetBuild/base/shaders/gBufferFragment.shader @@ -25,8 +25,10 @@ layout(location = 3) out vec3 specular; void main() { pos = fragPos; - if (material.hasNormTex) + if (material.hasNormTex) { normals = texture(material.normalTexture, texCoord).xyz; + normals = normalize(normals * 2.0 - 1.0); + } else normals = normalize(normal); @@ -40,4 +42,5 @@ void main() { specular.g = texture(material.specularTexture, texCoord).r; else specular.g = 1.0; + specular.b = 1.0; } \ No newline at end of file diff --git a/NFPackCreator/AssetBuild/base/shaders/lightingFragment.shader b/NFPackCreator/AssetBuild/base/shaders/lightingFragment.shader index 57d44e5..89981db 100644 --- a/NFPackCreator/AssetBuild/base/shaders/lightingFragment.shader +++ b/NFPackCreator/AssetBuild/base/shaders/lightingFragment.shader @@ -1,8 +1,6 @@ #version 330 core in vec2 texCoord; -in vec3 normals; -in vec3 fragPos; in vec4 fragPosLightSpace[16]; struct Camera { @@ -20,11 +18,16 @@ struct Light { }; uniform Camera camera; -uniform Light light[100]; +uniform Light light[12]; uniform int numberOfLights; uniform bool isContinued; uniform float farPlane; +uniform sampler2D gBPos; +uniform sampler2D gBNorm; +uniform sampler2D gBDiff; +uniform sampler2D gBSpec; + out vec4 outColor; float calcShadowDirectional(int lightNum, vec4 fragPosLight, vec3 no, vec3 lDir) { @@ -54,14 +57,14 @@ vec3 offsets[20] = vec3[]( vec3(0, 1, 1), vec3(0, -1, 1), vec3(0, -1, -1), vec3(0, 1, -1) ); -float calcShadowPoint(int lightNum, vec3 no, vec3 lDir) { - vec3 fragLight = fragPos - light[lightNum].pos; +float calcShadowPoint(int lightNum, vec3 no, vec3 lDir, vec3 fp) { + vec3 fragLight = fp - light[lightNum].pos; float current = length(fragLight); float bias = 0.15; float closest = 0.0f; float shad = 0.0f; int samples = 20; - float viewDist = length(camera.pos - fragPos); + float viewDist = length(camera.pos - fp); float disk = (1.0 + (viewDist / farPlane)) / 50.0f; for (int i = 0; i < samples; i++) { closest = texture(light[lightNum].pointDepthTex, fragLight + offsets[i] * disk).r; @@ -76,7 +79,16 @@ float calcShadowPoint(int lightNum, vec3 no, vec3 lDir) { void main() { vec3 color = vec3(0.0); - vec3 matDiff; + vec3 fragPos = texture(gBPos, texCoord).xyz; + vec3 norm = texture(gBNorm, texCoord).xyz; + vec3 matDiff = texture(gBDiff, texCoord).rgb; + vec3 specTemp = texture(gBSpec, texCoord).rgb; + float specPower = specTemp.r; + float matSpec = specTemp.g; + if (specTemp.b != 1.0) + discard; + + /*vec3 matDiff; if (material.hasDiffuseTex) matDiff = texture(material.diffuseTexture, texCoord).rgb; else @@ -93,9 +105,9 @@ void main() { } else { norm = normalize(normals); - } + }*/ - float ambientStrength = 0.2f; + float ambientStrength = 0.1f; vec3 ambient = ambientStrength * matDiff; if (!isContinued) color += ambient; @@ -108,7 +120,7 @@ void main() { vec3 viewDir = normalize(camera.pos - fragPos); vec3 reflectDir = reflect(-lightDir, norm); - float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.specPower); + float spec = pow(max(dot(viewDir, reflectDir), 0.0), specPower); vec3 specular = light[i].color * spec * matSpec * (light[i].strength / 2.0f); float shadow = calcShadowDirectional(i, fragPosLightSpace[i], norm, lightDir); @@ -118,22 +130,22 @@ void main() { if (light[i].type == 2) { vec3 lightDir = normalize(light[i].pos - fragPos); float diff = max(dot(norm, lightDir), 0.0); - vec3 diffuse = light[i].color * diff * matDiff * light[i].strength; + vec3 diffuse = light[i].color * diff * matDiff * (light[i].strength / 2.5f); vec3 viewDir = normalize(camera.pos - fragPos); vec3 halfway = normalize(lightDir + viewDir); - float spec = pow(max(dot(norm, halfway), 0.0), material.specPower); + float spec = pow(max(dot(norm, halfway), 0.0), specPower); vec3 specular = light[i].color * spec * matSpec * (light[i].strength / 2.5f); float length = length(light[i].pos - fragPos); float att = clamp(10.0 / length, 0.0, 1.0) * light[i].strength; - float shadow = calcShadowPoint(i, norm, lightDir); + float shadow = calcShadowPoint(i, norm, lightDir, fragPos); color += ((diffuse + specular) * (1.0 - shadow) * att); continue; } } - //TODO: Move this to a post-processing pass + //TODO: Move this to a post-processing pass (what about the UI textures?) float gamma = 2.2; color.rgb = pow(color.rgb, vec3(1.0 / gamma)); outColor = vec4(color, 1.0); diff --git a/NFPackCreator/AssetBuild/base/shaders/lightingVertex.shader b/NFPackCreator/AssetBuild/base/shaders/lightingVertex.shader index f08f9b2..ef78be7 100644 --- a/NFPackCreator/AssetBuild/base/shaders/lightingVertex.shader +++ b/NFPackCreator/AssetBuild/base/shaders/lightingVertex.shader @@ -1,26 +1,20 @@ #version 330 core -layout(location = 0) in vec3 pos; +layout(location = 0) in vec2 pos; layout(location = 1) in vec2 texCoords; -layout(location = 2) in vec3 normal; -uniform mat4 model; -uniform mat4 view; -uniform mat4 proj; uniform mat4 lightSpaceMat[16]; uniform int numMats; +uniform sampler2D gBPos; out vec2 texCoord; -out vec3 normals; -out vec3 fragPos; out vec4 fragPosLightSpace[16]; void main() { texCoord = texCoords; - normals = mat3(transpose(inverse(model))) * normal; - fragPos = vec3(model * vec4(pos, 1.0)); + vec3 fragPos = texture(gBPos, texCoord).xyz; for (int i = 0; i < numMats; i++) { fragPosLightSpace[i] = lightSpaceMat[i] * vec4(fragPos, 1.0); } - gl_Position = proj * view * vec4(fragPos, 1.0); + gl_Position = vec4(pos, 0.0, 1.0); } \ No newline at end of file diff --git a/NothinFancy/src/NFObject/Text.cpp b/NothinFancy/src/NFObject/Text.cpp index 3e55b78..b1894ee 100644 --- a/NothinFancy/src/NFObject/Text.cpp +++ b/NothinFancy/src/NFObject/Text.cpp @@ -156,12 +156,12 @@ namespace nf { 1.0, 1.0, 1.0, 0.0 }; - glActiveTexture(GL_TEXTURE10); + glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, c.texID); m_vao->bind(); m_vao->setBufferData(0, vb, sizeof(vb)); m_vao->setBufferData(1, tc, sizeof(tc)); - shader->setUniform("text", 10); + shader->setUniform("text", 4); glDrawArrays(GL_TRIANGLES, 0, 6); currX += (c.advance >> 6) * scale * m_scale; } diff --git a/NothinFancy/src/Renderer/Camera.cpp b/NothinFancy/src/Renderer/Camera.cpp index c73e48d..c0f104f 100644 --- a/NothinFancy/src/Renderer/Camera.cpp +++ b/NothinFancy/src/Renderer/Camera.cpp @@ -114,7 +114,7 @@ namespace nf { gBufferShader->setUniform("view", view); glm::vec3 pos(m_position.x, m_position.y, m_position.z); - //lightingShader->setUniform("camera.pos", pos); + lightingShader->setUniform("camera.pos", pos); glm::mat4 cubemapView = glm::mat4(glm::mat3(view)); cubemapShader->setUniform("view", cubemapView); diff --git a/NothinFancy/src/Renderer/GBuffer.cpp b/NothinFancy/src/Renderer/GBuffer.cpp index 7ff3db8..109e50d 100644 --- a/NothinFancy/src/Renderer/GBuffer.cpp +++ b/NothinFancy/src/Renderer/GBuffer.cpp @@ -54,9 +54,6 @@ namespace nf { //TODO: Blit depth buffer for transparent objects later glBindFramebuffer(GL_FRAMEBUFFER, prevFBO); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_textures[1]); } void GBuffer::bindTextures(Shader* shader) { diff --git a/NothinFancy/src/Renderer/Renderer.cpp b/NothinFancy/src/Renderer/Renderer.cpp index b66f31c..1d70110 100644 --- a/NothinFancy/src/Renderer/Renderer.cpp +++ b/NothinFancy/src/Renderer/Renderer.cpp @@ -19,6 +19,7 @@ namespace nf { Renderer::Renderer(Application* app) : + m_app(app), m_gBuffer(nullptr), m_shadowMapFBO(0), m_directionalDepthTexSize(0), @@ -29,7 +30,6 @@ namespace nf { m_fadeNoText(false), m_fadeOutComplete(false) { - m_app = app; m_hdc = GetDC(m_app->getWindow()); PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), @@ -60,11 +60,12 @@ namespace nf { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 3, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0, 0 + 0 }; wglDeleteContext(m_hglrc); m_hglrc = wglCreateContextAttribsARB(m_hdc, NULL, attrib); wglMakeCurrent(m_hdc, m_hglrc); + //TODO: Configure V-Sync with a custom max FPS wglSwapIntervalEXT(0); Log("OpenGL version: " + std::string((char*)glGetString(GL_VERSION))); glDepthFunc(GL_LESS); @@ -72,7 +73,7 @@ namespace nf { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); loadBaseAssets(); @@ -98,21 +99,22 @@ namespace nf { SendMessage(m_app->getWindow(), WM_SETICON, ICON_SMALL, (LPARAM)windowIcon); } - float fadeVB[] = { - -1.0, -1.0, - 1.0, -1.0, - 1.0, 1.0, - -1.0, 1.0 + float quadVB[] = { + -1.0, -1.0, 0.0, 0.0, + 1.0, -1.0, 1.0, 0.0, + 1.0, 1.0, 1.0, 1.0, + -1.0, 1.0, 0.0, 1.0 }; - unsigned int fadeIB[] = { + unsigned int quadIB[] = { 0, 1, 2, 2, 3, 0 }; - m_fadeVAO = new VertexArray; - m_fadeVAO->addBuffer(fadeVB, sizeof(fadeVB)); - m_fadeVAO->push<float>(2); - m_fadeVAO->finishBufferLayout(); - m_fadeIB = new IndexBuffer(fadeIB, 6); + m_quadVAO = new VertexArray; + m_quadVAO->addBuffer(quadVB, sizeof(quadVB)); + m_quadVAO->push<float>(2); + m_quadVAO->push<float>(2); + m_quadVAO->finishBufferLayout(); + m_quadIB = new IndexBuffer(quadIB, 6); m_loadingText.create("NFLoadingText", Vec2(0.025, 0.044), Vec3(0.7, 0.7, 0.7)); } @@ -156,60 +158,60 @@ namespace nf { glm::mat4 proj = glm::perspective(glm::radians(45.0f), (float)m_app->getConfig().width / (float)m_app->getConfig().height, 0.1f, 10000.0f); camera->bind(m_gBufferShader, m_lightingShader, m_cubemapShader); - //First, draw the cubemap if one is currently set + //First, fill the gBuffer with entities + m_gBufferShader->setUniform("proj", proj); + m_gBuffer->render(m_lGame, m_gBufferShader); + + //Light entities using the gBuffer + unsigned int lightsRemaining = m_lights.size(); + if (!lightsRemaining) { + m_quadVAO->bind(); + m_quadIB->bind(); + m_lightingShader->bind(); + m_gBuffer->bindTextures(m_lightingShader); + glDrawElements(GL_TRIANGLES, m_quadIB->getCount(), GL_UNSIGNED_INT, nullptr); + } + unsigned int drawCount = 0; + while (lightsRemaining > 0) { + unsigned int currLightsDrawn; + if (lightsRemaining > m_texSlots) + currLightsDrawn = m_texSlots; + else + currLightsDrawn = lightsRemaining; + lightsRemaining -= currLightsDrawn; + m_lightingShader->setUniform("numberOfLights", (int)currLightsDrawn); + if(drawCount == 0) + m_lightingShader->setUniform("isContinued", false); + else { + m_lightingShader->setUniform("isContinued", true); + glBlendFunc(GL_ONE, GL_ONE); + glDepthFunc(GL_LEQUAL); + } + for (unsigned int i = 0; i < currLightsDrawn; i++) + m_lights[i]->bind(m_lightingShader, i); + renderShadowMaps(currLightsDrawn); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glViewport(0, 0, m_app->getConfig().width, m_app->getConfig().height); + m_quadVAO->bind(); + m_quadIB->bind(); + m_lightingShader->bind(); + m_gBuffer->bindTextures(m_lightingShader); + glDrawElements(GL_TRIANGLES, m_quadIB->getCount(), GL_UNSIGNED_INT, nullptr); + m_lights.erase(m_lights.begin(), m_lights.begin() + currLightsDrawn); + drawCount++; + } + m_lGame.clear(); + m_lights.clear(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthFunc(GL_LESS); + + //Draw the cubemap if one is currently set if (m_cubemap != nullptr) { m_cubemapShader->setUniform("proj", proj); m_cubemap->render(m_cubemapShader); } m_cubemap = nullptr; - //Fill gBuffer with entities - m_gBufferShader->setUniform("proj", proj); - m_gBuffer->render(m_lGame, m_gBufferShader); - m_lGame.clear(); - - //Light entities using the gBuffer - /*for (Entity* draw : m_lGame) { - Entity& curr = *draw; - unsigned int drawCount = (unsigned int)std::ceil(m_lights.size() / (double)m_texSlots); - if (drawCount == 0) - drawCount++; - unsigned int lightsRemaining = m_lights.size(); - int currLight; - if (lightsRemaining > m_texSlots) - currLight = -(int)m_texSlots; - else - currLight = -(int)lightsRemaining; - for (unsigned int i = 0; i < drawCount; i++) { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - m_lightingShader->setUniform("isContinued", false); - if (i != 0) { - glBlendFunc(GL_ONE, GL_ONE); - glDepthFunc(GL_LEQUAL); - m_lightingShader->setUniform("isContinued", true); - } - unsigned int currLightsDrawn; - if (lightsRemaining >= m_texSlots) - currLightsDrawn = m_texSlots; - else - currLightsDrawn = lightsRemaining; - lightsRemaining -= currLightsDrawn; - currLight += (int)currLightsDrawn; - m_lightingShader->setUniform("numberOfLights", (int)currLightsDrawn); - for (unsigned int j = 0; j < currLightsDrawn; j++) { - m_lights[j + (unsigned int)currLight]->bind(m_lightingShader, j); - } - renderShadowMaps(currLight, currLightsDrawn); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(0, 0, m_app->getConfig().width, m_app->getConfig().height); - curr.render(m_lightingShader); - } - glDepthFunc(GL_LESS); - } - m_lGame.clear();*/ - m_lights.clear(); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - //Draw UI elements glDisable(GL_DEPTH_TEST); proj = glm::ortho(0.0f, (float)m_app->getConfig().width, 0.0f, (float)m_app->getConfig().height); @@ -233,12 +235,13 @@ namespace nf { } m_lUI.clear(); + //Fade over everything when states change if (m_fadeIn) { static double opacity = 1.0; m_fadeShader->setUniform("opacity", (float)opacity); - m_fadeVAO->bind(); - m_fadeIB->bind(); - glDrawElements(GL_TRIANGLES, m_fadeIB->getCount(), GL_UNSIGNED_INT, nullptr); + m_quadVAO->bind(); + m_quadIB->bind(); + glDrawElements(GL_TRIANGLES, m_quadIB->getCount(), GL_UNSIGNED_INT, nullptr); if (!m_fadeNoText) { m_textShader->setUniform("proj", proj); m_loadingText.setOpacity(opacity); @@ -256,9 +259,9 @@ namespace nf { else if (m_fadeOut) { static double opacity = 0.0; m_fadeShader->setUniform("opacity", (float)opacity); - m_fadeVAO->bind(); - m_fadeIB->bind(); - glDrawElements(GL_TRIANGLES, m_fadeIB->getCount(), GL_UNSIGNED_INT, nullptr); + m_quadVAO->bind(); + m_quadIB->bind(); + glDrawElements(GL_TRIANGLES, m_quadIB->getCount(), GL_UNSIGNED_INT, nullptr); if (!m_fadeNoText) { m_textShader->setUniform("proj", proj); m_loadingText.setOpacity(opacity); @@ -278,17 +281,16 @@ namespace nf { if (err != GL_NO_ERROR) Error("OpenGL error " + std::to_string(err)); + //Show completed frame SwapBuffers(m_hdc); } - void Renderer::renderShadowMaps(unsigned int startingLight, unsigned int count) { + void Renderer::renderShadowMaps(unsigned int count) { float nearP = 0.1f, farP = 400.0f; glm::mat4 directionalLightProj = glm::ortho(-50.0f, 50.0f, -50.0f, 50.0f, nearP, farP); glm::mat4 pointLightProj = glm::perspective(glm::radians(90.0f), 1.0f, nearP, farP); glm::mat4 lightView; glm::mat4 lightSpaceMat; - int prevFBO; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFBO); glBindFramebuffer(GL_FRAMEBUFFER, m_shadowMapFBO); for (unsigned int i = 0; i < count; i++) { Light::Type type = m_lights[i]->getType(); @@ -300,7 +302,7 @@ namespace nf { glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); glClear(GL_DEPTH_BUFFER_BIT); - Vec3 posTemp = m_lights[startingLight + i]->getPosition(); + Vec3 posTemp = m_lights[i]->getPosition(); glm::vec3 lightPos(posTemp.x, posTemp.y, posTemp.z); lightView = glm::lookAt(lightPos, glm::vec3(0.0), glm::vec3(0.0, 1.0, 0.0)); lightSpaceMat = directionalLightProj * lightView; @@ -315,9 +317,9 @@ namespace nf { stringPos = "light["; stringPos += std::to_string(i); stringPos += "].directionalDepthTex"; - glActiveTexture(GL_TEXTURE3 + i); + glActiveTexture(GL_TEXTURE4 + i); glBindTexture(GL_TEXTURE_2D, tex); - m_lightingShader->setUniform(stringPos, 3 + (int)i); + m_lightingShader->setUniform(stringPos, 4 + (int)i); break; } case Light::Type::POINT: { @@ -326,7 +328,7 @@ namespace nf { glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); glClear(GL_DEPTH_BUFFER_BIT); - Vec3 posTemp = m_lights[startingLight + i]->getPosition(); + Vec3 posTemp = m_lights[i]->getPosition(); glm::vec3 lightPos(posTemp.x, posTemp.y, posTemp.z); std::vector<glm::mat4> lightSpaceMats; lightSpaceMats.push_back(pointLightProj * glm::lookAt(lightPos, lightPos + glm::vec3(1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0))); @@ -349,17 +351,15 @@ namespace nf { std::string stringPos = "light["; stringPos += std::to_string(i); stringPos += "].pointDepthTex"; - glActiveTexture(GL_TEXTURE3 + i); + glActiveTexture(GL_TEXTURE4 + i); glBindTexture(GL_TEXTURE_CUBE_MAP, tex); - m_lightingShader->setUniform(stringPos, 3 + (int)i); + m_lightingShader->setUniform(stringPos, 4 + (int)i); m_lightingShader->setUniform("farPlane", farP); break; } } } m_lightingShader->setUniform("numMats", (int)count); - glViewport(0, 0, m_app->getConfig().width, m_app->getConfig().height); - glBindFramebuffer(GL_FRAMEBUFFER, prevFBO); } void Renderer::loadBaseAssets() { @@ -369,7 +369,7 @@ namespace nf { m_gBufferShader = new Shader(gBufferVertex, gBufferFragment); const char* lightingVertex = m_baseAP["lightingVertex.shader"]->data; const char* lightingFragment = m_baseAP["lightingFragment.shader"]->data; - //m_lightingShader = new Shader(lightingVertex, lightingFragment); + m_lightingShader = new Shader(lightingVertex, lightingFragment); const char* textVertex = m_baseAP["textVertex.shader"]->data; const char* textFragment = m_baseAP["textFragment.shader"]->data; m_textShader = new Shader(textVertex, textFragment); @@ -403,9 +403,8 @@ namespace nf { } void Renderer::createShadowMaps() { - m_texSlots = 13; + m_texSlots = 12; glGenFramebuffers(1, &m_shadowMapFBO); - glBindFramebuffer(GL_FRAMEBUFFER, m_shadowMapFBO); for (unsigned int i = 0; i < m_texSlots; i++) { unsigned int directionalDepthMap, pointDepthMap; glGenTextures(1, &directionalDepthMap); @@ -442,8 +441,8 @@ namespace nf { delete m_fadeShader; delete m_directionalShadowShader; delete m_gBuffer; - delete m_fadeVAO; - delete m_fadeIB; + delete m_quadVAO; + delete m_quadIB; ReleaseDC(m_app->getWindow(), m_hdc); wglMakeCurrent(NULL, NULL); wglDeleteContext(m_hglrc); diff --git a/NothinFancy/src/include/NothinFancy.h b/NothinFancy/src/include/NothinFancy.h index 65300f0..c7d0297 100644 --- a/NothinFancy/src/include/NothinFancy.h +++ b/NothinFancy/src/include/NothinFancy.h @@ -23,6 +23,7 @@ namespace nf { class Drawable; class Shader; class Model; + class GBuffer; class AudioEngine; class Renderer { @@ -41,7 +42,7 @@ namespace nf { ~Renderer(); private: - void renderShadowMaps(unsigned int startingLight, unsigned int count); + void renderShadowMaps(unsigned int count); void loadBaseAssets(); void createShadowMaps(); @@ -53,6 +54,8 @@ namespace nf { AssetPack m_baseAP; + GBuffer* m_gBuffer; + unsigned int m_shadowMapFBO; int m_directionalDepthTexSize; int m_pointDepthTexSize; @@ -65,7 +68,7 @@ namespace nf { Cubemap* m_cubemap; std::vector<UIElement*> m_lUI; Shader* m_gBufferShader; - Shader* m_entityShader; + Shader* m_lightingShader; Shader* m_textShader; Shader* m_uiTextureShader; Shader* m_cubemapShader; @@ -77,8 +80,9 @@ namespace nf { bool m_fadeNoText; bool m_fadeOutComplete; Text m_loadingText; - VertexArray* m_fadeVAO; - IndexBuffer* m_fadeIB; + + VertexArray* m_quadVAO; + IndexBuffer* m_quadIB; }; class Application { diff --git a/NothinFancy/src/include/Renderer.h b/NothinFancy/src/include/Renderer.h index fbdaf42..f106079 100644 --- a/NothinFancy/src/include/Renderer.h +++ b/NothinFancy/src/include/Renderer.h @@ -33,7 +33,7 @@ namespace nf { ~Renderer(); private: - void renderShadowMaps(unsigned int startingLight, unsigned int count); + void renderShadowMaps(unsigned int count); void loadBaseAssets(); void createShadowMaps(); @@ -71,7 +71,8 @@ namespace nf { bool m_fadeNoText; bool m_fadeOutComplete; Text m_loadingText; - VertexArray* m_fadeVAO; - IndexBuffer* m_fadeIB; + + VertexArray* m_quadVAO; + IndexBuffer* m_quadIB; }; } \ No newline at end of file