read depth buffer [solved]
Posted: Wed Jun 07, 2023 4:53 am
tldr: how do i save/access the depth buffer contents from a render?
if i modify groverburger's simplest 3d example to render the spinning cube to a special canvas:
and then draw temp_canvas to the default screen canvas:
that works fine. however, when trying to draw the resultant depth_canvas to the screen canvas (or access it as a uniform in a shader), all of its values appear to be {1.0,1.0,1.0,1.0}.
source of demo: https://github.com/groverburger/simplest_3d
edit: solved, see below
if i modify groverburger's simplest 3d example to render the spinning cube to a special canvas:
Code: Select all
local lg = love.graphics
canvas_settings = {
["type"] = "2d",
["format"] = "depth32f",
["readable"] = true,
["msaa"] = 0,
["dpiscale"] = lg.getDPIScale(),
["mipmaps"] = "none",
}
temp_canvas = lg.newCanvas(
lg.getPixelWidth(),
lg.getPixelHeight()
)
depth_canvas = lg.newCanvas(
lg.getPixelWidth(),
lg.getPixelHeight(),
canvas_settings
)
Code: Select all
function love.draw()
love.graphics.clear()
-- draw the mesh using the shader to the canvas pair
lg.setCanvas({temp_canvas, nil, ["depthstencil"]=depth_canvas, ["depth"]=true}}) -- <<<
lg.clear()
lg.setDepthMode("lequal", true)
Shader:send("modelMatrix", GetTransformationMatrix({0,0,4}, {Timer,Timer,Timer}, {1,1,1}))
lg.setShader(Shader)
lg.draw(Mesh)
-- set canvas back to the default
lg.setCanvas()
lg.setShader()
lg.setDepthMode()
if love.keyboard.isDown("space") then
--shader2:send("depthmap",depth_canvas)
--lg.setShader(shader2)
lg.draw(depth_canvas)
--lg.setShader()
else
lg.draw(temp_canvas)
end
end
source of demo: https://github.com/groverburger/simplest_3d
edit: solved, see below