Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/6.pbr/1.2.lighting_textured/1.2.pbr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ uniform sampler2D aoMap;
// lights
uniform vec3 lightPositions[4];
uniform vec3 lightColors[4];
uniform int lightsNumber;

uniform vec3 camPos;

Expand Down Expand Up @@ -97,7 +98,7 @@ void main()

// reflectance equation
vec3 Lo = vec3(0.0);
for(int i = 0; i < 4; ++i)
for(int i = 0; i < lightsNumber; ++i)
{
// calculate per-light radiance
vec3 L = normalize(lightPositions[i] - WorldPos);
Expand Down
9 changes: 6 additions & 3 deletions src/6.pbr/1.2.lighting_textured/lighting_textured.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ int main()
shader.use();
shader.setMat4("projection", projection);

const int lightsNumber = sizeof(lightPositions) / sizeof(lightPositions[0]);
shader.setInt("lightsNumber", lightsNumber);

// render loop
// -----------
while (!glfwWindowShouldClose(window))
Expand Down Expand Up @@ -167,9 +170,9 @@ int main()
}

// render light source (simply re-render sphere at light positions)
// this looks a bit off as we use the same shader, but it'll make their positions obvious and
// this looks a bit off as we use the same shader, but it'll make their positions obvious and
// keeps the codeprint small.
for (unsigned int i = 0; i < sizeof(lightPositions) / sizeof(lightPositions[0]); ++i)
for (unsigned int i = 0; i < lightsNumber; ++i)
{
glm::vec3 newPos = lightPositions[i] + glm::vec3(sin(glfwGetTime() * 5.0) * 5.0, 0.0, 0.0);
newPos = lightPositions[i];
Expand Down Expand Up @@ -216,7 +219,7 @@ void processInput(GLFWwindow *window)
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
Expand Down