Adding supersampling/subsampling support

Hi there,

I want to add supersampling/subsampling support to jME becaus of two reasons:

  1. Mac osx user with retina displays cannot play my game at 60fps due to their high resolution.
  2. Anti Aliasing

The problem is that I don’t know where to start.
I tried to reshape the frambuffers e.g. to a 2x higher resolution as a test.

float scale = settings.getFloat("RenderScale");

width *= scale;
height *= scale;

settings.setResolution(width, height);
listener.reshape(width, height);

After that I added an post filter (via FilterPostProcessor) to scale the rendered image down to the window size (the framebuffer is still bigger than the window). But this only affects the main viewport. Another problem is that subsampling (0.5x) doesn’t work this way because the framebuffers are also sized down to the half. Which means there is only a small rendered image in the lower left of my window.

Is there a better way or can someone give me a general idea to achieve supersampling/subsampling?

Is possible to render the whole game (main viewport + gui + other viewports) to an offscreen buffer with a higher/lower resolution than the window and than scale it down/up?

Or is it best to create a new SceneProcessor?

best regards
Alrik

I think you can do this easily as a post processing filter: you make a big framebuffer, you render on it and then you render it back on a smaller framebuffer.

Maybe you could check out the bloom filter that does the opposite of what you want, downsampling instead of supersampling, but the idea is the same jmonkeyengine/BloomFilter.java at master · jMonkeyEngine/jmonkeyengine · GitHub

There are also some informations in the wiki on the offscreen rendering page.

I can’t be more helful regarding the exact code you need in jme because, even thought I do post processing, i don’t use jme filter system.

+1 for a built-in super/subsampling support.

As for the Mac Users: You should be able to use the app settings (dialog) to render Fullscreen in FullHD (many (old) game do that on windows as well, you notice how they change your resolution).
Given the size of the Displays on Mac you wouldn’t even really tell quality differences.

My Game use LWJGL 3 and GLFW. Some Mac users has strange behavior when using fullscreen. This is why I try to achieve subsampling

1 Like

Hey,
I saw that @nehon and @Momoko_Fan are the authors of Renderer and FilterPostProcessor. Maybe you guys can help me with this problem? :slight_smile:
It’s important to me to fix the problem because we already have some customers that trying to play the game on Mac OSX.
Is there any way to render the whole game (main viewport, gui viewport and custom viewports) to a lower resolution/framebuffer and then scale the rendered texture up to the window resolution? The game is unplayable at 4K but its running smoothly at FullHD. We use GLFW and LWJGL3.

Any ideas?

You could do this with a FilterPostProcessor by scaling in a fragment shader.

extends the FilterPostProcessor and override the reshape method.
If res is > a given threshold render the filters at this threshold then add an additional pass that upscales the render.

thank you. I already tried it in the reshape method. But what is with the other viewports? Is it possible to apply this modified FilterPostProcessor to all viewports? Because e.g. the BloomFilter doesn’t work when applied to main viewport and gui viewport at the same time (as far as I know).

I doubt you can make it work without touching to the engine’s core.
Why not just cap the resolution?

mhh what you could try though… is to make a smaller viewport, attach the filterPost processor to it, then set a custom frame buffer to it. (viewport.setOutputFramebuffer()). This framebuffer must have the viewport resolution.
Then you create another viewport at full resolution and you just render a full screen quad with the texture from the frameBuffer of the first viewport.

1 Like

Ok thank you. I will try the second idea with the smaller viewport. On mac it seams there is a general problem with jMonkeyEngine. It is not possible to select a lower resolution in fullscreen on the test machine. The test cases are also crashing/black screen when running in fullscreen.

@javasabr @Empire_Phoenix Any idea?

hm, I will try to check it on macbooks of my friends…

2 Likes

No idea, sorry

as far as I can see we can’t use custom screen sizes in fullscreen mode in GLFW :frowning: , we can use only options of available video modes:

final GLFWVidMode.Buffer buffer = glfwGetVideoModes(glfwGetPrimaryMonitor());

        for(int i = 0; i < buffer.capacity(); i++) {
            final GLFWVidMode mode = buffer.get(i);
            System.out.println(mode.width() + "x" + mode.height());
        }
1 Like

also on my linux machine, I can’t use any other resolution than fullhd in fullscreen mode :frowning:

A friend of me that use mac could not start the jme test cases in fullscreen mode with a lower resolution. He selected the screen sizes in the drop down box of the settings dialog. The native osx resolution was retina 2x 1400x900 which means 2800x1800 in jme.

That’s (Due of the fullscreen mode problems) why I want to implement subsampling for window mode. But the supersampling feature is also useful for screenshots :smiley:

Or people with better pc’s than mine :slight_smile: