Linear/point sampling runtime.

Discussion and feedback on Construct 2

Post » Fri Nov 11, 2016 3:58 am

Any chance of getting linear/point sampling control per layout or as system action?
Image
B
82
S
30
G
12
Posts: 517
Reputation: 12,763

Post » Sun Nov 13, 2016 2:36 pm

I also agree it would be nice, be it for only an option menu for some pixel based games if people do not enjoy pixels that much
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Sun Nov 13, 2016 4:10 pm

I'd love to see it, but it doesn't seem feasible as a runtime toggle. To enable or disable linear sampling you need to reload the textures in question. So first off we'd need to have control over the loading of assets, which iirc can't be done while Canvas2D is still in the mix at least.
B
40
S
16
G
6
Posts: 543
Reputation: 7,649

Post » Sun Nov 13, 2016 4:35 pm

I figured it must be something that happens during the first loading/caching screen, on the other hand I would mind if this runtime action will preform a full browser reload to take effect, I just need something to check for it on the startup of C2, maybe save it to local storage and read it before loading the game, the other alternative is having 2 JS files, which is less ideal.
Image
B
82
S
30
G
12
Posts: 517
Reputation: 12,763

Post » Sun Nov 13, 2016 6:13 pm

You can get a runtime point sampling/linear sampling toggle going if you don't mind editing layout.js a bit.

How C2's rendering pipeline works is basically draw all scene objects onto a big texture and then display that texture on screen. Fullscreen scaling 'high quality' scales all objects up first, then renders them to the final output texture. 'Low quality' on the other hand renders all objects to the final texture at 1x1 scale and then scales that texture up to fill the screen afterwards. What this means is that if you disable linear sampling on the final texture then nothing gets filtered in 'low quality' mode because all the objects got rendered to it at 1x1, and texture filters only come into effect at non-1x1 scales.

Simplest way to get it working (for webgl) is:

Open layout.js and go down to the
Code: Select all
Layout.prototype.drawGL = function (glw)
line.

Below that you'll see the 'if (render_to_texture)' if-statement where the final output texture gets created.

Change both lines within, from:
Code: Select all
this.runtime.layout_tex = glw.createEmptyTexture(this.runtime.draw_width, this.runtime.draw_height, this.runtime.linearSampling);

.. to:
Code: Select all
this.runtime.layout_tex = glw.createEmptyTexture(this.runtime.draw_width, this.runtime.draw_height, this.runtime.pointSampling);

And now you can turn linear sampling on and off by switching between 'high quality' and 'low quality' fullscreen scaling.
If you want it to work with shader effects as well it gets a bit more involved tho. PM me if you're interested and I'll explain more in detail.
B
40
S
16
G
6
Posts: 543
Reputation: 7,649


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests