Removed the 100 light limit
This commit is contained in:
parent
0105eeb075
commit
b007d3f18e
@ -77,7 +77,7 @@ BEGIN
|
|||||||
BEGIN
|
BEGIN
|
||||||
BLOCK "040904b0"
|
BLOCK "040904b0"
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "TODO: <Company name>"
|
VALUE "CompanyName", "Grayson Riffe"
|
||||||
VALUE "FileDescription", "Nothin' Fancy Example Application"
|
VALUE "FileDescription", "Nothin' Fancy Example Application"
|
||||||
VALUE "FileVersion", "1.0.0.0"
|
VALUE "FileVersion", "1.0.0.0"
|
||||||
VALUE "InternalName", "Game.exe"
|
VALUE "InternalName", "Game.exe"
|
||||||
|
@ -13,7 +13,7 @@ void MainState::onEnter() {
|
|||||||
text.centered(true);
|
text.centered(true);
|
||||||
uiTex.create(nf::BaseAssets::logo, nf::Vec2(0.025, 0.025), 0.5);
|
uiTex.create(nf::BaseAssets::logo, nf::Vec2(0.025, 0.025), 0.5);
|
||||||
button.create(nf::Vec2(0.8, 0.025), "Reset");
|
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);
|
cm.create(nf::BaseAssets::cubemap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ uniform Camera camera;
|
|||||||
uniform Material material;
|
uniform Material material;
|
||||||
uniform Light light[100];
|
uniform Light light[100];
|
||||||
uniform int numberOfLights;
|
uniform int numberOfLights;
|
||||||
|
uniform bool isContinued;
|
||||||
|
|
||||||
out vec4 outColor;
|
out vec4 outColor;
|
||||||
|
|
||||||
@ -45,11 +46,12 @@ void main() {
|
|||||||
if (material.hasSpecTex)
|
if (material.hasSpecTex)
|
||||||
matSpec = texture(material.specularTexture, texCoord).rgb;
|
matSpec = texture(material.specularTexture, texCoord).rgb;
|
||||||
|
|
||||||
for (int i = 0; i < numberOfLights; i++) {
|
float ambientStrength = 0.5f;
|
||||||
float ambientStrength = 0.2f;
|
|
||||||
vec3 ambient = ambientStrength * matDiff;
|
vec3 ambient = ambientStrength * matDiff;
|
||||||
if (i == numberOfLights - 1 && numberOfLights == 1) {
|
if (!isContinued)
|
||||||
color += ambient;
|
color += ambient;
|
||||||
|
for (int i = 0; i < numberOfLights; i++) {
|
||||||
|
if (i == numberOfLights - 1 && numberOfLights == 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +83,7 @@ void main() {
|
|||||||
float length = length(light[i].pos - fragPos);
|
float length = length(light[i].pos - fragPos);
|
||||||
float att = clamp(10.0 / length, 0.0, 1.0) * light[i].strength;
|
float att = clamp(10.0 / length, 0.0, 1.0) * light[i].strength;
|
||||||
|
|
||||||
color += ((ambient + diffuse + specular) * att);
|
color += ((diffuse + specular) * att);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,15 +148,41 @@ namespace nf {
|
|||||||
m_entityShader->setUniform("proj", proj);
|
m_entityShader->setUniform("proj", proj);
|
||||||
for (Entity* draw : m_lGame) {
|
for (Entity* draw : m_lGame) {
|
||||||
Entity& curr = *draw;
|
Entity& curr = *draw;
|
||||||
//TODO: Clean this up a bit
|
unsigned int drawCount = (unsigned int)std::ceil(m_lights.size() / 100.0);
|
||||||
m_entityShader->setUniform("numberOfLights", (int)m_lights.size() + 1);
|
if (drawCount == 0)
|
||||||
for (unsigned int i = 0; i < m_lights.size(); i++) {
|
drawCount++;
|
||||||
m_lights[i]->bind(m_entityShader, i);
|
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_lGame.clear();
|
||||||
m_lights.clear();
|
m_lights.clear();
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
//Draw cubemap where there isn't anything else
|
//Draw cubemap where there isn't anything else
|
||||||
if (m_cubemap != nullptr) {
|
if (m_cubemap != nullptr) {
|
||||||
|
Reference in New Issue
Block a user