From b007d3f18e321621c69db589fc6bceb0d4b2e3ea Mon Sep 17 00:00:00 2001 From: "Grayson Riffe (Desktop)" <graysonriffe@yahoo.com> Date: Sun, 12 Sep 2021 20:18:56 -0500 Subject: [PATCH] Removed the 100 light limit --- Game/Game.rc | 2 +- Game/src/MainState.cpp | 2 +- .../base/shaders/entityFragment.shader | 14 ++++---- NothinFancy/src/Renderer/Renderer.cpp | 36 ++++++++++++++++--- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/Game/Game.rc b/Game/Game.rc index ba47f47..3d8c5a5 100644 --- a/Game/Game.rc +++ b/Game/Game.rc @@ -77,7 +77,7 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "CompanyName", "TODO: <Company name>" + VALUE "CompanyName", "Grayson Riffe" VALUE "FileDescription", "Nothin' Fancy Example Application" VALUE "FileVersion", "1.0.0.0" VALUE "InternalName", "Game.exe" diff --git a/Game/src/MainState.cpp b/Game/src/MainState.cpp index 7a9866e..bbf5ab6 100644 --- a/Game/src/MainState.cpp +++ b/Game/src/MainState.cpp @@ -13,7 +13,7 @@ void MainState::onEnter() { text.centered(true); uiTex.create(nf::BaseAssets::logo, nf::Vec2(0.025, 0.025), 0.5); button.create(nf::Vec2(0.8, 0.025), "Reset"); - light.create(nf::Vec3(0.0, 5.0, 0.0), nf::Vec3(1.0, 1.0, 1.0), 1.3); + light.create(nf::Vec3(0.0, 5.0, 0.0), nf::Vec3(1.0, 1.0, 1.0)); cm.create(nf::BaseAssets::cubemap); } diff --git a/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader b/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader index 2974135..023f976 100644 --- a/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader +++ b/NFPackCreator/AssetBuild/base/shaders/entityFragment.shader @@ -29,6 +29,7 @@ uniform Camera camera; uniform Material material; uniform Light light[100]; uniform int numberOfLights; +uniform bool isContinued; out vec4 outColor; @@ -42,14 +43,15 @@ void main() { matDiff = material.diffuseColor; vec3 matSpec = vec3(1.0); - if(material.hasSpecTex) - matSpec = texture(material.specularTexture, texCoord).rgb; + if (material.hasSpecTex) + matSpec = texture(material.specularTexture, texCoord).rgb; + float ambientStrength = 0.5f; + vec3 ambient = ambientStrength * matDiff; + if (!isContinued) + color += ambient; for (int i = 0; i < numberOfLights; i++) { - float ambientStrength = 0.2f; - vec3 ambient = ambientStrength * matDiff; if (i == numberOfLights - 1 && numberOfLights == 1) { - color += ambient; break; } @@ -81,7 +83,7 @@ void main() { float length = length(light[i].pos - fragPos); float att = clamp(10.0 / length, 0.0, 1.0) * light[i].strength; - color += ((ambient + diffuse + specular) * att); + color += ((diffuse + specular) * att); continue; } } diff --git a/NothinFancy/src/Renderer/Renderer.cpp b/NothinFancy/src/Renderer/Renderer.cpp index ca84f7d..ec617ad 100644 --- a/NothinFancy/src/Renderer/Renderer.cpp +++ b/NothinFancy/src/Renderer/Renderer.cpp @@ -148,15 +148,41 @@ namespace nf { m_entityShader->setUniform("proj", proj); for (Entity* draw : m_lGame) { Entity& curr = *draw; - //TODO: Clean this up a bit - m_entityShader->setUniform("numberOfLights", (int)m_lights.size() + 1); - for (unsigned int i = 0; i < m_lights.size(); i++) { - m_lights[i]->bind(m_entityShader, i); + unsigned int drawCount = (unsigned int)std::ceil(m_lights.size() / 100.0); + if (drawCount == 0) + drawCount++; + unsigned int lightsRemaining = m_lights.size(); + int currLight; + if (lightsRemaining > 100) + currLight = -100; + else + currLight = -(int)lightsRemaining; + for (unsigned int i = 0; i < drawCount; i++) { + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + m_entityShader->setUniform("isContinued", false); + if (i != 0) { + glBlendFunc(GL_ONE, GL_ONE); + glDepthFunc(GL_LEQUAL); + m_entityShader->setUniform("isContinued", true); + } + unsigned int currLightsDrawn; + if (lightsRemaining >= 100) + currLightsDrawn = 100; + else + currLightsDrawn = lightsRemaining; + lightsRemaining -= currLightsDrawn; + currLight += (int)currLightsDrawn; + m_entityShader->setUniform("numberOfLights", (int)currLightsDrawn + 1); + for (unsigned int j = 0; j < currLightsDrawn; j++) { + m_lights[j + (unsigned int)currLight]->bind(m_entityShader, j); + } + curr.render(m_entityShader); } - curr.render(m_entityShader); + glDepthFunc(GL_LESS); } m_lGame.clear(); m_lights.clear(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Draw cubemap where there isn't anything else if (m_cubemap != nullptr) {