Skip to content

Commit

Permalink
Implement frustum culling (#54)
Browse files Browse the repository at this point in the history
Not sure this fits your style @britzl but I figured I'd at least get the ball rolling. I assume passing frustum to a project <1.3.1 just has no effect?
  • Loading branch information
8bitskull authored Apr 5, 2022
1 parent fb01580 commit 0750bb7
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions orthographic/render/orthographic.render_script
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,23 @@ function update(self)

-- draw world per camera
local cameras = camera.get_cameras()
local frustum = nil
local view = nil
local proj = nil
if #cameras > 0 then
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_CULL_FACE)
render.disable_state(render.STATE_STENCIL_TEST)
for _,camera_id in ipairs(cameras) do
local viewport = camera.get_viewport(camera_id)
render.set_viewport(viewport.x, viewport.y, viewport.z, viewport.w)
render.set_view(camera.get_view(camera_id))
render.set_projection(camera.get_projection(camera_id))
render.draw(self.tile_pred)
render.draw(self.particle_pred)
view = camera.get_view(camera_id)
render.set_view(view)
proj = camera.get_projection(camera_id)
render.set_projection(proj)
frustum = proj * view
render.draw(self.tile_pred, {frustum = frustum})
render.draw(self.particle_pred, {frustum = frustum})
render.draw_debug3d()
end
end
Expand All @@ -51,10 +57,13 @@ function update(self)
render.disable_state(render.STATE_CULL_FACE)
render.enable_state(render.STATE_STENCIL_TEST)
render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
render.set_view(IDENTITY)
render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1))
render.draw(self.gui_pred)
render.draw(self.text_pred)
view = IDENTITY
render.set_view(view)
proj = vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1)
render.set_projection(proj)
frustum = proj * view
render.draw(self.gui_pred, {frustum = frustum})
render.draw(self.text_pred, {frustum = frustum})
render.disable_state(render.STATE_STENCIL_TEST)
end

Expand Down

0 comments on commit 0750bb7

Please sign in to comment.