func (glRenderer *OpenglRenderer) enableDepthMask(depthMask bool) { if depthMask == glRenderer.depthMast { return } gl.DepthMask(depthMask) glRenderer.depthMast = depthMask }
func (p *LightPass) DrawPass(scene *Scene) { /* use light pass shader */ p.Material.Use() shader := p.Material.Shader /* compute camera view projection inverse */ vp := scene.Camera.Projection.Mul4(scene.Camera.View) vp_inv := vp.Inv() shader.Matrix4f("cameraInverse", &vp_inv[0]) /* clear */ gl.ClearColor(0.9, 0.9, 0.9, 1.0) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) /* set blending mode to additive */ gl.DepthMask(false) /* draw lights */ lights := scene.FindLights() last := len(lights) - 1 for i, light := range lights { if i == 1 { /* first light pass we want the shader to restore the depth buffer * then, disable depth masking so that multiple lights can be drawn */ gl.BlendFunc(gl.ONE, gl.ONE) } if i == last { gl.DepthMask(true) } /* draw shadow pass for this light into shadow map */ p.Shadows.DrawPass(scene, &light) /* use light pass shader */ p.Material.Use() /* compute world to lightspace (light view projection) matrix */ lp := light.Projection lv := mgl.LookAtV(light.Position, mgl.Vec3{}, mgl.Vec3{0, 1, 0}) // only for directional light lvp := lp.Mul4(lv) shader.Matrix4f("light_vp", &lvp[0]) /* set light uniform attributes */ shader.Vec3("light.Position", &light.Position) shader.Vec3("light.Color", &light.Color) shader.Int32("light.Type", int32(light.Type)) shader.Float("light.Range", light.Range) shader.Float("light.attenuation.Constant", light.Attenuation.Constant) shader.Float("light.attenuation.Linear", light.Attenuation.Linear) shader.Float("light.attenuation.Quadratic", light.Attenuation.Quadratic) /* render light */ gl.Viewport(0, 0, int32(scene.Camera.Width), int32(scene.Camera.Height)) p.quad.Draw() } /* reset GL state */ gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) }