refactor debug info, measure render times

This commit is contained in:
2022-02-21 12:24:05 +08:00
parent 057e8907a9
commit 4a9afb4246
6 changed files with 135 additions and 46 deletions

View File

@ -2,7 +2,6 @@ package render
import (
"errors"
"math"
"math/rand"
"time"
"unsafe"
@ -305,6 +304,9 @@ var (
)
func (r *WorldRenderer) Render(world *world.World, view *View) {
allclock := util.NewClock()
lastclock := util.NewClock()
io.RenderPos = io.ViewPos
io.RenderDir = io.ViewDir
@ -337,6 +339,8 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
gl.Enable(gl.DEPTH_TEST)
gl.DepthFunc(gl.LESS)
lastclock.Restart()
// 1. Render to depth map
gl.Viewport(0, 0, int32(ShadowmapSize[0]), int32(ShadowmapSize[1]))
gl.BindFramebuffer(gl.FRAMEBUFFER, r.depthmap.fbo)
@ -356,6 +360,8 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
world.Render()
world.RenderWater()
io.Diagnostics.Times.RenderPasses.Depthmap = lastclock.Restart()
// 2. Geometry pass, render to G-buffer
io.RenderPos = io.ViewPos
io.RenderDir = io.ViewDir
@ -376,6 +382,8 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
world.Render()
io.Diagnostics.Times.RenderPasses.Geometry = lastclock.Restart()
// 3/1. SSAO pass
gl.BindFramebuffer(gl.FRAMEBUFFER, r.ssao.fbo)
gl.ClearColor(1, 1, 1, 1)
@ -386,7 +394,6 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
r.ssao.shader.SetUniformMat4("view", view.View())
r.ssao.shader.SetUniformMat4("projection", view.Perspective())
r.ssao.shader.SetUniformVec3f("viewPos", view.EyePos)
r.ssao.shader.SetUniformFloat("time", float32(time.Since(r.startTime).Seconds()))
DrawScreenQuad()
@ -398,6 +405,8 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
DrawScreenQuad()
io.Diagnostics.Times.RenderPasses.SSAO = lastclock.Restart()
// 4. Render the actual output with deferred lighting
gl.BindFramebuffer(gl.FRAMEBUFFER, r.output.fbo)
gl.ClearColor(0, 0, 0, 0)
@ -412,6 +421,8 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
DrawScreenQuad()
io.Diagnostics.Times.RenderPasses.Lighting = lastclock.Restart()
// 5. Render water
gl.Enable(gl.DEPTH_TEST)
gl.DepthFunc(gl.LESS)
@ -445,46 +456,11 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
DrawScreenQuad()
// Show G-buffers?
io.Diagnostics.Times.RenderPasses.Postfx = lastclock.Restart()
io.Diagnostics.Times.Render = allclock.Elapsed()
// Show Information?
if io.ShowDebugInfo {
imgui.SetNextWindowPosV(imgui.Vec2{X: float32(r.lastDisplaySize[0]), Y: 0}, imgui.ConditionAlways, imgui.Vec2{X: 1, Y: 0})
if igwrap.Begin("Renderer Textures/Outputs", nil, igwrap.WindowFlagsOverlay) {
imgui.PushStyleVarVec2(imgui.StyleVarItemSpacing, imgui.Vec2{})
imageSize := r.lastDisplaySize.ToFloat32().Multiply(0.25)
imageSize[1] -= imgui.CurrentStyle().WindowPadding().Y / 2
imageSize[0] = imageSize[1] / float32(r.lastDisplaySize[1]) * float32(r.lastDisplaySize[0])
igwrap.Image(r.gbuffer.pos, imageSize, itype.Rectf{0, 0, 1, 1})
igwrap.Image(r.gbuffer.norm, imageSize, itype.Rectf{0, 0, 1, 1})
igwrap.Image(r.gbuffer.color, imageSize, itype.Rectf{0, 0, 1, 1})
igwrap.Image(r.ssao.ambient, imageSize, itype.Rectf{0, 0, 1, 1})
imgui.PopStyleVar()
imgui.End()
}
if igwrap.Begin("F3", nil, 0) {
imgui.PushStyleColor(imgui.StyleColorButton, imgui.Vec4{0, 0, 0, 0.5})
imgui.PushStyleColor(imgui.StyleColorButtonHovered, imgui.Vec4{0, 0, 0, 0.6})
imgui.PushStyleColor(imgui.StyleColorButtonActive, imgui.Vec4{0, 0, 0, 0.8})
igwrap.TextBlank()
isize := asset.WorldTextureAtlas.ImageSize
igwrap.TextBackground("Texture Atlas Size: (%dx%d)", isize[0], isize[1])
imgui.SameLine()
igwrap.TextBackground("[Hover]")
if imgui.IsItemHoveredV(imgui.HoveredFlagsAllowWhenDisabled) {
_, wheely := imgui.CurrentIO().MouseWheel()
if math.Abs(float64(wheely)) > 1e-3 {
atlasScale = util.Maxf(1, atlasScale+wheely)
}
imgui.BeginTooltip()
igwrap.Image(r.texture.Handle(), isize.ToFloat32().Multiply(atlasScale), itype.Rectf{0, 0, 1, 1})
imgui.EndTooltip()
}
imgui.PopStyleColorV(3)
imgui.End()
}
r.renderDebugInfo()
}
}

View File

@ -0,0 +1,56 @@
package render
import (
"math"
"time"
"edgaru089.ml/go/gl01/internal/asset"
"edgaru089.ml/go/gl01/internal/igwrap"
"edgaru089.ml/go/gl01/internal/io"
"edgaru089.ml/go/gl01/internal/util"
"edgaru089.ml/go/gl01/internal/util/itype"
"github.com/inkyblackness/imgui-go/v4"
)
func (r *WorldRenderer) renderDebugInfo() {
// Render information
if igwrap.Begin("F3", nil, 0) {
igwrap.TextBlank()
igwrap.TextBackground("WorldRender: lastframe %.3fms", float64(io.Diagnostics.Times.Render.Nanoseconds())/float64(time.Millisecond))
isize := asset.WorldTextureAtlas.ImageSize
igwrap.TextBackground("Texture Atlas Size: (%dx%d)", isize[0], isize[1])
imgui.SameLine()
igwrap.TextBackground("[Hover]")
if imgui.IsItemHoveredV(imgui.HoveredFlagsAllowWhenDisabled) {
_, wheely := imgui.CurrentIO().MouseWheel()
if math.Abs(float64(wheely)) > 1e-3 {
atlasScale = util.Maxf(1, atlasScale+wheely)
}
imgui.BeginTooltip()
igwrap.Image(r.texture.Handle(), isize.ToFloat32().Multiply(atlasScale), itype.Rectf{0, 0, 1, 1})
imgui.EndTooltip()
}
imgui.End()
}
imgui.SetNextWindowPosV(imgui.Vec2{X: float32(r.lastDisplaySize[0]), Y: 0}, imgui.ConditionAlways, imgui.Vec2{X: 1, Y: 0})
if igwrap.Begin("Renderer Textures/Outputs", nil, igwrap.WindowFlagsOverlay) {
imgui.PushStyleVarVec2(imgui.StyleVarItemSpacing, imgui.Vec2{})
imageSize := r.lastDisplaySize.ToFloat32().Multiply(0.25)
imageSize[1] -= imgui.CurrentStyle().WindowPadding().Y / 2
imageSize[0] = imageSize[1] / float32(r.lastDisplaySize[1]) * float32(r.lastDisplaySize[0])
igwrap.Image(r.gbuffer.pos, imageSize, itype.Rectf{0, 0, 1, 1})
igwrap.Image(r.gbuffer.norm, imageSize, itype.Rectf{0, 0, 1, 1})
igwrap.Image(r.gbuffer.color, imageSize, itype.Rectf{0, 0, 1, 1})
igwrap.Image(r.ssao.ambient, imageSize, itype.Rectf{0, 0, 1, 1})
imgui.PopStyleVar()
imgui.End()
}
}