mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Initital shader lighting support
This commit is contained in:
@@ -1,35 +1,19 @@
|
||||
class IMICFPS
|
||||
class Light
|
||||
attr_reader :ambient, :diffuse, :specular, :position, :light_id
|
||||
attr_accessor :x, :y, :z, :intensity
|
||||
def initialize(id:, x:,y:,z:,
|
||||
attr_reader :light_id
|
||||
attr_accessor :ambient, :diffuse, :specular, :position, :intensity
|
||||
def initialize(id:,
|
||||
ambient: Vector.new(0.5, 0.5, 0.5, 1),
|
||||
diffuse: Vector.new(1, 0.5, 0, 1), specular: Vector.new(0.2, 0.2, 0.2, 1),
|
||||
position: Vector.new(x, y, z, 0), intensity: 1)
|
||||
position: Vector.new(0, 0, 0, 0), intensity: 1
|
||||
)
|
||||
@light_id = id
|
||||
@x,@y,@z = x,y,z
|
||||
@intensity = intensity
|
||||
|
||||
self.ambient = ambient
|
||||
self.diffuse = diffuse
|
||||
self.specular = specular
|
||||
self.position = position
|
||||
end
|
||||
|
||||
def ambient=(color)
|
||||
@ambient = convert(color).pack("f*")
|
||||
end
|
||||
|
||||
def diffuse=(color)
|
||||
@diffuse = convert(color, true).pack("f*")
|
||||
end
|
||||
|
||||
def specular=(color)
|
||||
@specular = convert(color, true).pack("f*")
|
||||
end
|
||||
|
||||
def position=(vertex)
|
||||
@position = convert(vertex).pack("f*")
|
||||
@ambient = ambient
|
||||
@diffuse = diffuse
|
||||
@specular = specular
|
||||
@position = position
|
||||
end
|
||||
|
||||
def draw
|
||||
|
||||
@@ -29,8 +29,8 @@ class IMICFPS
|
||||
add_entity(Player.new(spawnpoint: @map_loader.spawnpoints.sample, manifest: Manifest.new(package: "base", name: "character")))
|
||||
|
||||
# TODO: Load lights from MapLoader
|
||||
add_light(Light.new(id: available_light, x: 3, y: -6, z: 6))
|
||||
add_light(Light.new(id: available_light, x: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1)))
|
||||
add_light(Light.new(id: available_light, position: Vector.new(30, 10.0, 30)))
|
||||
# add_light(Light.new(id: available_light, x: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1)))
|
||||
end
|
||||
|
||||
def data
|
||||
|
||||
@@ -15,6 +15,7 @@ class IMICFPS
|
||||
shader.set_uniform("hasTexture", object.model.has_texture?)
|
||||
|
||||
# TODO: Upload and use lights
|
||||
shader.set_uniform("lightPos", lights.first.position)
|
||||
|
||||
handleGlError
|
||||
draw_model(object.model)
|
||||
|
||||
Reference in New Issue
Block a user