Set shader lights once per frame instead of per entity

This commit is contained in:
2020-03-22 17:46:50 -05:00
parent 0d1d7ff6bc
commit f32dbfabeb

View File

@@ -16,16 +16,6 @@ class IMICFPS
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Shader.use("default") do |shader| Shader.use("default") do |shader|
entities.each do |entity|
next unless entity.visible && entity.renderable
shader.uniform_transform("projection", camera.projection_matrix)
shader.uniform_transform("view", camera.view_matrix)
shader.uniform_transform("model", entity.model_matrix)
shader.uniform_boolean("hasTexture", entity.model.has_texture?)
shader.uniform_vec3("cameraPosition", camera.position)
# TODO: Upload and use lights
lights.each_with_index do |light, i| lights.each_with_index do |light, i|
shader.uniform_float("lights[#{i}.end", -1.0); shader.uniform_float("lights[#{i}.end", -1.0);
shader.uniform_float("lights[#{i}.type", light.type); shader.uniform_float("lights[#{i}.type", light.type);
@@ -37,6 +27,15 @@ class IMICFPS
shader.uniform_float("totalLights", lights.size) shader.uniform_float("totalLights", lights.size)
entities.each do |entity|
next unless entity.visible && entity.renderable
shader.uniform_transform("projection", camera.projection_matrix)
shader.uniform_transform("view", camera.view_matrix)
shader.uniform_transform("model", entity.model_matrix)
shader.uniform_boolean("hasTexture", entity.model.has_texture?)
shader.uniform_vec3("cameraPosition", camera.position)
gl_error? gl_error?
draw_model(entity.model, shader) draw_model(entity.model, shader)
entity.draw entity.draw