// toDraw sets the render data needed for a single draw call. // The data is copied into a render.Draw instance. One of the key jobs // of this method is to put each draw request into a particular // render bucket so that they are drawn in order once sorted. func (sm *scene) toDraw(d render.Draw, p *pov, cam *camera, m *model, rt uint32) { d.SetMv(sm.mv.Mult(p.mm, cam.vm)) // model-view d.SetMvp(sm.mvp.Mult(sm.mv, cam.pm)) // model-view-projection d.SetPm(cam.pm) // projection only. d.SetScale(p.Scale()) d.SetTag(p.eid) // Set the drawing order hints. Overlay trumps transparency since 2D overlay // objects can't be sorted by distance anyways. bucket := render.OPAQUE // used to sort the draw data. Lowest first. switch { case m.castShadow && rt > 0: bucket = render.DEPTH_PASS // pre-passes first. case cam.overlay > 0: bucket = cam.overlay // OVERLAY draw last. case m.alpha < 1: bucket = render.TRANSPARENT // sort and draw after opaque. } depth := cam.depth && m.depth // both must be true for depth rendering. tocam := 0.0 if depth { tocam = p.toc } d.SetHints(bucket, tocam, depth, rt) // use the shadow map texture for models that show shadows. if m.hasShadows { m.UseLayer(sm.shadowMap) } }