Hey guys!
I’m trying to combine the rendy with the simple light and shadows repo, but I’m quite lost when working with the render pipeline in any game engine
I combined both repos in my codebase, and made the following changes to the rendy render_script:
- added the predicate to the predicates list in rendy
local predicates =
{
-- ...
-- Declare custom predicates.
occluder = {
tags = { hash("light_occluder") },
object = nil
},
}
- initialized lights.lua in the init method:
function init (self)
-- ...
lights.init()
lights.set_clear_color(clear_color)
end
- included the lights.draw in the update method using the camera’s view and projection
function update(self, dt)
-- Enable writing to the depth and stencil buffers, and set the default blend function.
-- Writing to the color buffer is always enabled.
render.set_depth_mask(true)
render.set_stencil_mask(0xff)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
-- Write default values to the color, depth, and stencil buffers.
render.clear(clear_buffers)
-- Render each camera according to its render order.
local ordered_camera_ids = get_ordered_camera_ids()
for i = 1, #ordered_camera_ids do
local camera_id = ordered_camera_ids[i]
local camera = rendy.cameras[camera_id]
-- Only render this camera if it is active.
if camera.active then
activate_camera(camera)
-- First, render 3D objects.
-- Enable depth testing and facing culling to discard non-visible fragments.
-- Blending is not supported for 3D objects because Defold does not sort them from back to front, which is a requirement for proper blending.
render.enable_state(render.STATE_DEPTH_TEST)
render.enable_state(render.STATE_CULL_FACE)
render.draw(predicates.model.object, { frustum = camera.frustum })
render.disable_state(render.STATE_CULL_FACE)
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_STENCIL_TEST)
render.set_depth_mask(false)
-- Second, render 2D objects.
-- Disable depth testing because Defold sorts 2D objects by their z positions from back to front.
-- Enable blending to support partially transparent objects.
render.enable_state(render.STATE_BLEND)
lights.draw(camera.view_transform, camera.projection_transform, predicates.occluder.object)
render.draw(predicates.tile.object, { frustum = camera.frustum })
render.draw(predicates.particle.object, { frustum = camera.frustum })
render.draw_debug3d()
render.disable_state(render.STATE_BLEND)
end
end
-- Render the GUI camera on top of all other cameras.
--...
I also made some tests using the follow view and projection, but couldn’t make it work:
local view = vmath.matrix4()
local proj = vmath.matrix4_orthographic(0, window_width, 0, window_height, -1, 1)
And yes, the rendy.renderer has the required materials, and the light_quad is in the scene with the light_quad.material.
Could anyone help me? I don’t know what else to do -.-U
Thanks in advance