(SOLVED) Scaling issue using render target

I want to downgrade resolution of my game using render target, so fragment shaders run for each in-game pixel (480x300) instead of screen pixel (2880x1800). I’ve set up simple test scene with nice little tree and camera:


Camera uses fixed_fit projection with zoom = 6. And it renders as it should:

Now I want to draw scene to render target with resolution 480x300, apply result texture to a quad and scale it up to fit whole screen. I’ve created a render target and added it as resource to custom render script:


Then I’ve created a quad game object, set material to my material with custom predicate and set property texture_sampler to point to my render target:

Then I’ve added this go to my scene, scaled it up and moved to match screen resolution and camera position:

Then in my render script:

    -- render the other components: sprites, tilemaps, particles etc
    --
    render.enable_state(render.STATE_BLEND)
    -- enable my render target
    render.set_render_target("test_rt")
    -- draw things to it
    render.draw(predicates.tile, camera_world.frustum)
    render.draw(predicates.particle, camera_world.frustum)
    -- reset render target
    render.set_render_target(render.RENDER_TARGET_DEFAULT)
    -- draw quad
    render.draw(predicates.test)
    render.disable_state(render.STATE_DEPTH_TEST)
    render.draw_debug3d()

What I expect to see is exactly the same image as without render target, but I’m getting this:

It somehow scaled I believe 6 times again, but I can not figure out where I messed up things. Thanks for help!

So seems like I’ve figured it out. I had to set viewport size to match render target size:

    -- setup camera view and projection
    --
    local camera_world = state.cameras.camera_world
    -- set viewport size
    render.set_viewport(0, 0, 480, 300)
    -- ... draw to render target here
    render.set_render_target(render.RENDER_TARGET_DEFAULT)
    -- reset viewport size
    render.set_viewport(0, 0, state.window_width, state.window_height)
    -- draw quad with rt texture 
2 Likes