Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Most efficient way to render at a scaled down resolution?  (Read 3041 times)

0 Members and 1 Guest are viewing this topic.

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Most efficient way to render at a scaled down resolution?
« on: July 18, 2017, 09:29:24 pm »
Hi, what's the most efficient way for me to render at a lower / scaled down / pixelated resolution? The goal is a retro pixelated appearance - but of course rendering at a lower resolution has its performance benefits so I don't want to take the shader route.

I've thought of these two -
- Creating the window at the desired downscaled resolution then scaling the window up
- Draw to a rendertexture of the desired size then render it as a scaled up sprite that fills the screen

I wanted to see what people thought before I committed to implementing it to avoid having to go through and benchmark both methods if it can be avoided.

Thanks!

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Most efficient way to render at a scaled down resolution?
« Reply #1 on: July 18, 2017, 11:10:20 pm »
Using a shader is actually likely to be the most effecient route but feel free to test all methods; it could depend on what you're actually drawing. Of course, you may also want to consider that a render texture would be needed anyway if you wanted to apply the shader to the entire window at once as opposed to on an object by object basis.

The other option you mentioned (using a smaller render texture) is a viable option. In fact, I think, the first thing I added to GitHub was a class that can do it automatically for you! :D
https://github.com/Hapaxia/PXL8

I'm not sure what you mean by "scaling the window up"...

Another option that you seem to have overlooked (this only really works if you're only using images - won't work with vector graphics) is to simply just scale up everything. Remember to turn off smoothing for textures and consider reducing/zooming the view to match so you can simply pretend it's the smaller size but it will draw everything larger.



It's possible that by "scaling the window up", you might mean that you have noticed that things can stretch when a window is resized. This is because the view is not changed. However, you can simply set the view manually.
For this, just set the view to the window size divided by the scale size. Something like this, maybe:
const unsigned int pixelSize{ 2u };
const sf::Vector2u windowSize{ 800u, 600u };
const sf::View view(sf::Vector2f(windowSize / pixelSize), sf::Vector2f(windowSize / pixelSize / 2u));
sf::RenderWindow window(sf::VideoMode(windowSize.x, windowSize.y), "");
window.setView(view);
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Most efficient way to render at a scaled down resolution?
« Reply #2 on: July 20, 2017, 09:35:38 pm »
Awesome, thanks Hapax. Your PXL8 project looks like it does exactly what I'm after - I think I will go for the rendertexture approach.

The thing with scaling everything up is it looks clearly pseudo-retro. Pixelated objects will transition smoothly across the screen which is not the case if you actually render at a lower resolution. The pixels of the background and the foreground should never overlap, they should line up exactly.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Most efficient way to render at a scaled down resolution?
« Reply #3 on: July 23, 2017, 11:31:40 pm »
You're welcome. Any of the methods mentioned seem valid, to be fair, though. For example, the "issue" you mentioned with "scaling up" can be simply avoided by rounding off positions to the correct "low-res pixel".

That is, if you have a view set to the "low res" size, you can simply round (to the nearest whole number) the position's elements. This will round it to the view co-ordinates - not the pixels - and effectively lock to the size of your pixels...
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*