Removed the 100 light limit
This commit is contained in:
parent
0105eeb075
commit
b007d3f18e
@ -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"
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user