mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-15 20:52:35 +00:00
Added support for rendering multiple lights, standardized shaders to use snake case for variables and camel case for functions, stubbed PBR material shader include.
This commit is contained in:
@@ -49,9 +49,9 @@ module CyberarmEngine
|
||||
|
||||
@objects.each { |o| @vertex_count += o.vertices.size }
|
||||
|
||||
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
||||
build_collision_tree
|
||||
puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_time) / 1000.0).round(2)} seconds"
|
||||
# start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
||||
# build_collision_tree
|
||||
# puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_time) / 1000.0).round(2)} seconds"
|
||||
end
|
||||
|
||||
def parse(parser)
|
||||
@@ -151,24 +151,24 @@ module CyberarmEngine
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
||||
gl_error?
|
||||
|
||||
# inPosition
|
||||
# in_position
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
||||
gl_error?
|
||||
# colors
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
|
||||
# inColor
|
||||
# in_color
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
||||
gl_error?
|
||||
# normals
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
|
||||
# inNormal
|
||||
# in_normal
|
||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, nil)
|
||||
gl_error?
|
||||
|
||||
if has_texture?
|
||||
# uvs
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
||||
# inUV
|
||||
# in_uv
|
||||
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
||||
gl_error?
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@ module CyberarmEngine
|
||||
shader.uniform_transform("projection", camera.projection_matrix)
|
||||
shader.uniform_transform("view", camera.view_matrix)
|
||||
shader.uniform_transform("model", entity.model_matrix)
|
||||
shader.uniform_vec3("cameraPosition", camera.position)
|
||||
shader.uniform_vector3("camera_position", camera.position)
|
||||
|
||||
gl_error?
|
||||
draw_model(entity.model, shader)
|
||||
@@ -154,15 +154,21 @@ module CyberarmEngine
|
||||
glBindTexture(GL_TEXTURE_2D, @g_buffer.texture(:depth))
|
||||
shader.uniform_integer("depth", 4)
|
||||
|
||||
lights.each_with_index do |light, _i|
|
||||
shader.uniform_integer("light[0].type", light.type)
|
||||
shader.uniform_vec3("light[0].direction", light.direction)
|
||||
shader.uniform_vec3("light[0].position", light.position)
|
||||
shader.uniform_vec3("light[0].diffuse", light.diffuse)
|
||||
shader.uniform_vec3("light[0].ambient", light.ambient)
|
||||
shader.uniform_vec3("light[0].specular", light.specular)
|
||||
# FIXME: Try to figure out how to up this to 32 and/or beyond
|
||||
# (currently fails with more then 7 lights passed in to shader)
|
||||
lights.each_slice(7).each do |light_group|
|
||||
light_group.each_with_index do |light, _i|
|
||||
shader.uniform_integer("light_count", light_group.size)
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, @g_buffer.vertices.size)
|
||||
shader.uniform_integer("lights[#{_i}].type", light.type)
|
||||
shader.uniform_vector3("lights[#{_i}].direction", light.direction)
|
||||
shader.uniform_vector3("lights[#{_i}].position", light.position)
|
||||
shader.uniform_vector3("lights[#{_i}].diffuse", light.diffuse)
|
||||
shader.uniform_vector3("lights[#{_i}].ambient", light.ambient)
|
||||
shader.uniform_vector3("lights[#{_i}].specular", light.specular)
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, @g_buffer.vertices.size)
|
||||
end
|
||||
end
|
||||
|
||||
glBindVertexArray(0)
|
||||
@@ -215,7 +221,7 @@ module CyberarmEngine
|
||||
|
||||
offset = 0
|
||||
model.objects.each do |object|
|
||||
shader.uniform_boolean("hasTexture", object.has_texture?)
|
||||
shader.uniform_boolean("has_texture", object.has_texture?)
|
||||
|
||||
if object.has_texture?
|
||||
glBindTexture(GL_TEXTURE_2D, object.materials.find { |mat| mat.texture_id }.texture_id)
|
||||
|
||||
@@ -385,7 +385,7 @@ module CyberarmEngine
|
||||
# @param value [Vector]
|
||||
# @param location [Integer]
|
||||
# @return [void]
|
||||
def uniform_vec3(variable, value, location = nil)
|
||||
def uniform_vector3(variable, value, location = nil)
|
||||
attr_loc = location || attribute_location(variable)
|
||||
|
||||
glUniform3f(attr_loc, *value.to_a[0..2])
|
||||
@@ -397,7 +397,7 @@ module CyberarmEngine
|
||||
# @param value [Vector]
|
||||
# @param location [Integer]
|
||||
# @return [void]
|
||||
def uniform_vec4(variable, value, location = nil)
|
||||
def uniform_vector4(variable, value, location = nil)
|
||||
attr_loc = location || attribute_location(variable)
|
||||
|
||||
glUniform4f(attr_loc, *value.to_a)
|
||||
|
||||
Reference in New Issue
Block a user