Ok i make a sprite with custom material.
but when i draw on it, render target texture, have only part of screen that i draw on it.(red/white sprite, red - is stone wall) What am i doing wrong? projection - is same for all draw.
local function init_occlusion_map_target(self)
self.occlusion_map_color_params = {
format = render.FORMAT_RGBA,
width = render.get_width(),
height = render.get_height(),
min_filter = render.FILTER_LINEAR,
mag_filter = render.FILTER_LINEAR,
u_wrap = render.WRAP_CLAMP_TO_EDGE,
v_wrap = render.WRAP_CLAMP_TO_EDGE }
self.occlusion_map_depth_params = {
format = render.FORMAT_DEPTH,
width = render.get_width(),
height = render.get_height(),
u_wrap = render.WRAP_CLAMP_TO_EDGE,
v_wrap = render.WRAP_CLAMP_TO_EDGE }
self.occlusion_map_target = render.render_target("occlusion_map", {
[render.BUFFER_COLOR_BIT] = self.occlusion_map_color_params,
[render.BUFFER_DEPTH_BIT] = self.occlusion_map_depth_params })
end
function init(self)
self.tile_pred = render.predicate({"tile"})
self.gui_pred = render.predicate({"gui"})
self.text_pred = render.predicate({"text"})
self.particle_pred = render.predicate({"particle"})
self.block_light_pred = render.predicate({"block_light"})
self.screen_pred = render.predicate({"screen"})
self.clear_color = vmath.vector4(0, 0, 0, 0)
self.clear_color.x = sys.get_config("render.clear_color_red", 0)
self.clear_color.y = sys.get_config("render.clear_color_green", 0)
self.clear_color.z = sys.get_config("render.clear_color_blue", 0)
self.clear_color.w = sys.get_config("render.clear_color_alpha", 0)
self.white_color=vmath.vector4(1, 1, 1, 1)
self.view = vmath.matrix4()
init_occlusion_map_target(self)
end
local function render_occlusion_map(self)
render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1))
render.enable_render_target(self.occlusion_map_target)
render.clear({[render.BUFFER_COLOR_BIT] = self.white_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})
render.enable_material("block_light")
render.draw(self.block_light_pred)
render.disable_material("block_light")
render.disable_render_target(self.occlusion_map_target)
render.enable_texture(0, self.occlusion_map_target, render.BUFFER_COLOR_BIT)
render.draw(self.screen_pred)
render.disable_texture(0, self.occlusion_map_target, render.BUFFER_COLOR_BIT)
end
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})
render.set_viewport(0, 0, render.get_window_width(), render.get_window_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)
render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1))
render_occlusion_map(self)
render.draw(self.tile_pred)
--[[render.draw(self.tile_pred)
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