Hi, guys!
I made a render script that renders 3 textures to a simple shader with a mix method.
It runs smoothly on my PC and Android device, but the multilayer thing makes the HTML build have a poor performance.
I have a simple test scene with moving objects, and not only it’s heavy, but also slow, although i’m using go.animate. So it’s not frame rate independent.
Is there a way for the render script not to interfere with the game’s execution time?
Also, is there something I can do to improve my render script’s performance?
Here’s the update section:
function update(self)
render.set_depth_mask(true)
render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})
local original_width = 720
local original_height = 1280
local current_width = render.get_window_width()
local current_height = render.get_window_height()
render.set_viewport(0, 0, current_width, current_height)
render.set_view(self.view)
render.set_depth_mask(false)
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_STENCIL_TEST)
render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
render.disable_state(render.STATE_CULL_FACE)
local ratio = math.min(math.min(current_width / original_width, current_height / original_height), 1)
local projected_width = current_width / ratio
local projected_height = current_height / ratio
render.set_projection(vmath.matrix4_orthographic(-(projected_width/2), projected_width/2, -(projected_height/2), projected_height/2, -1, 1))
--Render layers and draw to texture
render.enable_render_target(self.proj_black)
render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})
render.draw(self.proj_black_pred)
render.disable_render_target(self.proj_black)
render.enable_render_target(self.proj_blank)
render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})
render.draw(self.proj_blank_pred)
render.disable_render_target(self.proj_blank)
render.enable_render_target(self.fill)
render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})
render.draw(self.fill_pred)
render.disable_render_target(self.fill)
--Pass textures to shader and draw to render buffer
render.enable_material("mat")
render.enable_texture(0, self.proj_black, render.BUFFER_COLOR_BIT)
render.enable_texture(1, self.proj_blank, render.BUFFER_COLOR_BIT)
render.enable_texture(2, self.fill, render.BUFFER_COLOR_BIT)
render.draw(self.quad_pred)
render.disable_texture(0, self.proj_black)
render.disable_texture(1, self.proj_blank)
render.disable_texture(2, self.fill)
render.disable_material("mat")
render.draw(self.particle_pred)
render.draw_debug3d()
render.set_view(vmath.matrix4())
render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1))
render.enable_state(render.STATE_STENCIL_TEST)
render.draw(self.gui_pred)
render.draw(self.text_pred)
render.disable_state(render.STATE_STENCIL_TEST)
render.set_depth_mask(false)
render.draw_debug2d()
end
Update: I added some redundanct methods to the script and it happens to slow down time on the PC build as well