init atmo do init(null, false, [0.0, 0.8*atmo_a, 1.0*atmo_a, atmo_a])
private var atmo_a = 0.05
- redef fun draw(actor, model)
+ redef fun draw(actor, model, camera)
do
var gl_error = glGetError
assert gl_error == gl_NO_ERROR else print gl_error
var program = app.globe_program
program.use
- # Set constant program values
- program.use
-
# Bind textures
glActiveTexture gl_TEXTURE0
glBindTexture(gl_TEXTURE_2D, app.texture_earth.gl_texture)
# Update camera view and light
var p = app.world_camera.position
program.camera.uniform(p.x, p.y, p.z)
- program.mvp.uniform app.world_camera.mvp_matrix
+ program.mvp.uniform camera.mvp_matrix
program.light_center.uniform(app.light.position.x, app.light.position.y, app.light.position.z)
# Set attributes
glViewport(0, 0, display.width, display.height)
frame_core_dynamic_resolution_before display
- # Update cameras on both our programs
- versatile_program.use
- versatile_program.mvp.uniform world_camera.mvp_matrix
-
- normals_program.use
- normals_program.mvp.uniform app.world_camera.mvp_matrix
-
frame_core_depth_clock.lapse
for actor in actors do
for leaf in actor.model.leaves do
- leaf.material.draw(actor, leaf)
+ leaf.material.draw(actor, leaf, app.world_camera)
end
end
perfs["gamnit depth actors"].add frame_core_depth_clock.lapse
# This method is called on many materials for many `actor` and `model` at each frame.
# It is expected to use a `GLProgram` and call an equivalent to `glDrawArrays`.
# However, it should not call `glClear` nor `GamnitDisplay::flip`.
- fun draw(actor: Actor, model: LeafModel) do end
+ fun draw(actor: Actor, model: LeafModel, camera: Camera) do end
end
# Mesh with all geometry data
# The RGB values should be premultiplied by the alpha value.
var specular_color: Array[Float] is writable
- redef fun draw(actor, model)
+ redef fun draw(actor, model, camera)
do
var program = app.versatile_program
program.use
+ program.mvp.uniform camera.mvp_matrix
var mesh = model.mesh
program.light_center.uniform(app.light.position.x, app.light.position.y, app.light.position.z)
# Camera
- program.camera.uniform(app.world_camera.position.x, app.world_camera.position.y, app.world_camera.position.z)
+ program.camera.uniform(camera.position.x, camera.position.y, camera.position.z)
# Colors from the material
var a = actor.alpha
# Bump map TODO
private var normals_texture: nullable Texture = null is writable
- redef fun draw(actor, model)
+ redef fun draw(actor, model, camera)
do
var mesh = model.mesh
program.use_map_bump.uniform false
end
+ program.mvp.uniform camera.mvp_matrix
program.translation.uniform(actor.center.x, actor.center.y, actor.center.z, 0.0)
program.scale.uniform actor.scale
program.normal.array(mesh.normals, 3)
program.light_center.uniform(app.light.position.x, app.light.position.y, app.light.position.z)
- program.camera.uniform(app.world_camera.position.x, app.world_camera.position.y, app.world_camera.position.z)
+
+ # Camera
+ program.camera.uniform(camera.position.x, camera.position.y, camera.position.z)
if mesh.indices.is_empty then
glDrawArrays(mesh.draw_mode, 0, mesh.vertices.length/3)
class NormalsMaterial
super Material
- redef fun draw(actor, model)
+ redef fun draw(actor, model, camera)
do
var program = app.normals_program
program.use
- program.mvp.uniform app.world_camera.mvp_matrix
+ program.mvp.uniform camera.mvp_matrix
var mesh = model.mesh