Troubles with frame buffers and textures

Still on the post processing topic from last week, i came back to try it once again. After lots of testing i found this:

The game first renders the whole game world into a rt (render target) game_world_fbo. Then enables it as a texture for tex0:

render.disable_render_target(self.game_world_fbo)
render.enable_texture(0, self.game_world_fbo, render.BUFFER_COLOR0_BIT)

then, the render script uses this texture in a draw call to the post process quad, that process quad has a material that only outputs the brightest pixels of it. This material uses the tex0 enabled before, that means the image is just the game world and it extracts the brightest pixels of it. Debugging it on render doc, this is the output after all this:

regular game world before and after the brightness filter:
image
image

all a ok until here.

Note that the brightness filter is done on a render target called just bright, which is then disabled and transformed in a texture for tex0:

  render.enable_render_target(self.bright)
  render.set_render_target(self.bright)
  -- changes the material to filterring brightest pixels
  render.enable_material('bright') 
  render.draw(self.post_processing_pred)

Acording to renderdoc, the texture is fine in the output:


(in the above image, the first call to glDrawElements is the defold model which has lighting applied to it, the second one is the quad, the quad itself is only 2 tris)

After this step in the render script, it is time to blur the image. It disables the bright rt, turns it into an image for use in tex0. Then I change the enabled material to the blurring one and just draw the same quad in a different target:

  render.disable_render_target(self.bright)
  render.enable_texture(0, self.bright, render.BUFFER_COLOR0_BIT)

    render.enable_render_target(self.blur_fbo[hor])
    render.set_render_target(self.blur_fbo[hor])
    local constants = render.constant_buffer()


    constants.BLUR_viewPort_Radius = vmath.vector4(add_blur, 0,0, not_hor)
    render.draw(self.post_processing_pred, {constants = constants})

it then gives me a pitch black screen, only the gui is rendered succesfully as seen by the frame counter:

The odd thing to note is that the renderdoc says that the last step, the blurring, dont have to get any image input, that means, nothing is on tex0:

the code is currently on this repo, i just pick the most important parts for the problem, but idk if the problem is actually only in those parts i talked about: https://github.com/Caue-Aron/Defold-Post-Processing-Test/tree/optmized-blur

Any help is greatly appreciated!

Looking at https://github.com/Caue-Aron/Defold-Post-Processing-Test/blob/optmized-blur/rendercam/rendercam.render_script

Looks like you enable the blur render target then immediately set_render_target you then disable the render target and enable a non existent texture. Problem is nothing is drawn to the render target. I am assuming but seems like the “bright” render target isn’t doing much either, except you draw the postprocess predicate to it. A refactor is needed e.g. the steps from enabling > drawing > disabling > setting textures etc.

1 Like

im sorry, i still couldnt find a solution to it…

You mention that you want a step where you blur the image , assuming you want to draw the framebuffer then blur it in the shader and display the rendertarget to the screen quad. The problem is in your render script when enabling render.enable_render_target(self.blur_fbo[hor]) you should then draw the appropriate buffer that you want to blur then disable the render target and apply it . In the current render script nothing is drawn so you get a blank output.

3 Likes