// 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) } }
// toDraw sets all the data references and uniform data needed // by the rendering layer. func (m *model) toDraw(d render.Draw, eid uint64, depth bool, overlay int, distToCam float64) { d.SetTag(eid) d.SetAlpha(float64(m.alpha)) // 1 : no transparency as the default. // Set the drawing hints. Overlay trumps transparency since 2D overlay // objects can't be sorted by distance anyways. bucket := OPAQUE // used to sort the draw data. Lowest first. switch { case overlay > 0: bucket = overlay // OVERLAY draw last. case m.alpha < 1: bucket = TRANSPARENT // sort and draw after opaque. } depth = depth && m.depth // both must be true for depth rendering. tocam := 0.0 if depth { tocam = distToCam } d.SetHints(bucket, tocam, depth) // Set the drawing references. d.SetRefs(m.shd.program, m.msh.vao, m.drawMode) if total := len(m.texs); total > 0 { for cnt, t := range m.texs { d.SetTex(total, cnt, t.tid, t.f0, t.fn) } } else { d.SetTex(0, 0, 0, 0, 0) // clear any previous data. } // Set uniform values. These can be sent as a reference because they // are fixed on shader creation. d.SetUniforms(m.shd.uniforms) // shader integer uniform references. if m.anm != nil && len(m.pose) > 0 { d.SetPose(m.pose) } else { d.SetPose(nil) // clear data. } d.SetTime(time.Since(m.time).Seconds()) // For shaders that need elapsed time. // Set colour uniforms. d.SetFloats("kd", m.kd.R, m.kd.G, m.kd.B) d.SetFloats("ks", m.ks.R, m.ks.G, m.ks.B) d.SetFloats("ka", m.ka.R, m.ka.G, m.ka.B) // Set user specificed uniforms. for uniform, uvalues := range m.uniforms { d.SetFloats(uniform, uvalues...) } }