Visual "bug" with render targets [SOLVED]

I have this render script update:

render.set_stencil_mask(0xff)
  render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})

  render.set_viewport(vp.x, vp.y, vp.width, vp.height)

  render.set_render_target(self.pp_game_world)

  default_renderer()
  render.set_depth_mask(true)
  render.set_view(rendercam.calculate_view())
  render.set_projection(rendercam.calculate_proj())

  -- Sprite and particle rendering
  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.draw(self.particle_pred)

  render.set_projection(rendercam.calculate_proj())
  -- Model rendering
  render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
  render.disable_state(render.STATE_CULL_FACE)
  render.enable_state(render.STATE_DEPTH_TEST)
  render.set_depth_mask(true)
  render.draw(self.model_pred)

  -- Debug rendering - physics debug, draw_line
  render.disable_state(render.STATE_DEPTH_TEST)
  render.disable_state(render.STATE_CULL_FACE)
  render.draw_debug3d()

  -- GUI Rendering
  render.set_viewport(0, 0, rendercam.window.x, rendercam.window.y)
  render.set_view(IDENTITY_MATRIX)
  render.set_projection(self.gui_proj) -- gui_proj only calculated on update_window

  render.enable_state(render.STATE_STENCIL_TEST)
  render.draw(self.gui_pred)
  render.draw(self.text_pred) -- Includes debug text from "draw_text" messages.
  render.disable_state(render.STATE_STENCIL_TEST)

  -- changes to post process
  render.set_render_target(render.RENDER_TARGET_DEFAULT)
  render.set_projection(vmath.matrix4())
  render.set_view(vmath.matrix4())

  render.enable_texture(0, self.pp_game_world, render.BUFFER_COLOR_BIT)
  render.draw(self.post_processing_pred)
  render.disable_texture(0)

and the quad fragment shader that uses the frame buffer:

varying mediump vec2 var_texcoord0;
uniform lowp sampler2D tex0;
//---------------------------------------------------------------------------
void main()
{
    gl_FragColor=texture2D(tex0, var_texcoord0);
}

But instead of a defold logo, this is what im getting:

If anyone knows what might be happening, please tell me

Can you create a small repro and upload it here? :slight_smile:
Is the correct logo an original picture you are drawing before processing? Is proper material assigned to the model?

I think this was resolved by @Jerakin on Discord.

2 Likes

For knowledge sharing purposes: The output is wrong because the render target does not have a depth buffer. This can be fixed by including that into constructor of the render target, something like this

    local rgba_params = {
        format = render.FORMAT_RGBA,
        width = render.get_window_width(),
        height = render.get_window_height(),
        u_wrap = render.WRAP_CLAMP_TO_EDGE,
        v_wrap = render.WRAP_CLAMP_TO_EDGE
    }
    
    -- This is needed for effects that include 3d object
    local depth_params = {
        format = render.FORMAT_DEPTH,
        width = render.get_window_width(),
        height = render.get_window_height(),
        u_wrap = render.WRAP_CLAMP_TO_EDGE,
        v_wrap = render.WRAP_CLAMP_TO_EDGE
    }
    
    local target_params = {
        [render.BUFFER_COLOR_BIT] = rgba_params,
        [render.BUFFER_DEPTH_BIT] = depth_params
    }
    self.target = render.render_target("post_process", target_params)
4 Likes

thank u guys for helping me, i really appreciated it!

1 Like