gamnit :: NormalsMaterial :: defaultinit
# Simple material using the normals of the surface as color
#
# Each axis composing the normals are translated to color values.
# This material is useful for debugging normals or display models in a colorful way.
class NormalsMaterial
super Material
redef fun draw(actor, model, camera)
do
var program = app.normals_program
program.use
program.mvp.uniform camera.mvp_matrix
var mesh = model.mesh
# TODO apply normal map
program.translation.uniform(actor.center.x, actor.center.y, actor.center.z, 0.0)
program.scale.uniform actor.scale
program.tex_coord.array_enabled = true
program.tex_coord.array(mesh.texture_coords, 2)
program.coord.array_enabled = true
program.coord.array(mesh.vertices, 3)
program.rotation = new Matrix.gamnit_euler_rotation(actor.pitch, actor.yaw, actor.roll)
program.normal.array_enabled = true
program.normal.array(mesh.normals, 3)
if mesh.indices.is_empty then
glDrawArrays(mesh.draw_mode, 0, mesh.vertices.length/3)
else
glDrawElements(mesh.draw_mode, mesh.indices.length, gl_UNSIGNED_SHORT, mesh.indices_c.native_array)
end
end
end
lib/gamnit/depth/more_materials.nit:275,1--312,3