mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Set shader lights once per frame instead of per entity
This commit is contained in:
@@ -16,6 +16,17 @@ 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|
|
||||||
|
lights.each_with_index do |light, i|
|
||||||
|
shader.uniform_float("lights[#{i}.end", -1.0);
|
||||||
|
shader.uniform_float("lights[#{i}.type", light.type);
|
||||||
|
shader.uniform_vec3("lights[#{i}].position", light.position)
|
||||||
|
shader.uniform_vec3("lights[#{i}].ambient", light.ambient)
|
||||||
|
shader.uniform_vec3("lights[#{i}].diffuse", light.diffuse)
|
||||||
|
shader.uniform_vec3("lights[#{i}].specular", light.specular)
|
||||||
|
end
|
||||||
|
|
||||||
|
shader.uniform_float("totalLights", lights.size)
|
||||||
|
|
||||||
entities.each do |entity|
|
entities.each do |entity|
|
||||||
next unless entity.visible && entity.renderable
|
next unless entity.visible && entity.renderable
|
||||||
|
|
||||||
@@ -25,18 +36,6 @@ class IMICFPS
|
|||||||
shader.uniform_boolean("hasTexture", entity.model.has_texture?)
|
shader.uniform_boolean("hasTexture", entity.model.has_texture?)
|
||||||
shader.uniform_vec3("cameraPosition", camera.position)
|
shader.uniform_vec3("cameraPosition", camera.position)
|
||||||
|
|
||||||
# TODO: Upload and use lights
|
|
||||||
lights.each_with_index do |light, i|
|
|
||||||
shader.uniform_float("lights[#{i}.end", -1.0);
|
|
||||||
shader.uniform_float("lights[#{i}.type", light.type);
|
|
||||||
shader.uniform_vec3("lights[#{i}].position", light.position)
|
|
||||||
shader.uniform_vec3("lights[#{i}].ambient", light.ambient)
|
|
||||||
shader.uniform_vec3("lights[#{i}].diffuse", light.diffuse)
|
|
||||||
shader.uniform_vec3("lights[#{i}].specular", light.specular)
|
|
||||||
end
|
|
||||||
|
|
||||||
shader.uniform_float("totalLights", lights.size)
|
|
||||||
|
|
||||||
gl_error?
|
gl_error?
|
||||||
draw_model(entity.model, shader)
|
draw_model(entity.model, shader)
|
||||||
entity.draw
|
entity.draw
|
||||||
|
|||||||
Reference in New Issue
Block a user