Thanks for the response,
I have been sitting with this today some more and I have no clue what I am doing! Really hard to find information about this kinda stuff too, so hard to read up on it.
Oh and I can’t really do it as a render material because in the end I don’t want the gui to be affected.
What is wrong with this approach?
- Enable the first render target
- Draw what I want to be blurred
- Disable the first render target
- Enable the second render target
- Set first render target as texture to quad
- Disable the second render target
- Set second render target as texture to quad
It doesn’t feel like when I self.draw(self.effects_pred)
the first time it doesn’t get put into the second render target. Is it because I disable the texture?
It is probably easier if you guys can just see the whole render script.
[details=main.render_script]
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.effects_pred = render.predicate({"post_effects"})
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.view = vmath.matrix4()
local color_params = { format = render.FORMAT_RGBA,
width = render.get_window_width(),
height = render.get_window_height() }
local target_params = {[render.BUFFER_COLOR_BIT] = color_params }
self.target = render.render_target("effects", target_params)
self.target_second = render.render_target("effects2", target_params)
self.render_effects = false
self.render_passes = 5
end
local function effect(self, target, predicate)
render.disable_render_target(target)
render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color})
render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
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_texture(0, target, render.BUFFER_COLOR_BIT)
render.draw(predicate)
render.disable_texture(0, target)
end
local function do_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_width(), render.get_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.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
function update(self)
if self.render_effects then
render.enable_render_target(self.target)
end
do_update(self)
if self.render_effects then
render.enable_render_target(self.target_second)
effect(self, self.target, self.effects_pred)
effect(self, self.target_second, self.effects_pred)
end
end
function on_message(self, message_id, message)
if message_id == hash("clear_color") then
self.clear_color = message.color
elseif message_id == hash("set_view_projection") then
self.view = message.view
elseif message_id == hash("render_effects") then
self.render_effects = message.render
end
end
```[/details]