Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nearest Neighbour filtering #1486

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/source/about/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,21 @@ dwmflush

dwmflush = enabled

point_filtering
^^^^^^^^^^^^^^^

**Description**
Enable nearest point filtering for scaling from captured screen to streamed video.
May be useful for retro games or pixel-perfect streaming to low-resolution devices (PlayStation Vita, for example).

**Default**
``disabled``

**Example**
.. code-block:: text

point_filtering = enabled

Audio
-----

Expand Down
4 changes: 3 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ namespace config {
{}, // encoder
{}, // adapter_name
{}, // output_name
true // dwmflush
true, // dwmflush
false //point_filtering
};

audio_t audio {
Expand Down Expand Up @@ -969,6 +970,7 @@ namespace config {
string_f(vars, "adapter_name", video.adapter_name);
string_f(vars, "output_name", video.output_name);
bool_f(vars, "dwmflush", video.dwmflush);
bool_f(vars, "point_filtering", video.point_filtering);

path_f(vars, "pkey", nvhttp.pkey);
path_f(vars, "cert", nvhttp.cert);
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace config {
std::string adapter_name;
std::string output_name;
bool dwmflush;
bool point_filtering;
};

struct audio_t {
Expand Down
11 changes: 9 additions & 2 deletions src/platform/linux/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
#include "graphics.h"
#include "src/video.h"
#include "src/config.h"

#include <fcntl.h>

Expand Down Expand Up @@ -48,13 +49,19 @@ namespace gl {
ctx.GenTextures(textures.size(), textures.begin());

float color[] = { 0.0f, 0.0f, 0.0f, 1.0f };

GLint filtering = GL_LINEAR;
if (config::video.point_filtering)
{
filtering = GL_POINT;
}

for (auto tex : textures) {
gl::ctx.BindTexture(GL_TEXTURE_2D, tex);
gl::ctx.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // x
gl::ctx.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // y
gl::ctx.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl::ctx.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl::ctx.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
gl::ctx.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
gl::ctx.TexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
}

Expand Down
17 changes: 15 additions & 2 deletions src/platform/windows/display_vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern "C" {
#include "misc.h"
#include "src/main.h"
#include "src/video.h"
#include "src/config.h"

#define SUNSHINE_SHADERS_DIR SUNSHINE_ASSETS_DIR "/shaders/directx"
namespace platf {
Expand Down Expand Up @@ -695,8 +696,14 @@ namespace platf::dxgi {
return -1;
}

D3D11_FILTER filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
if (config::video.point_filtering)
{
filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
}

D3D11_SAMPLER_DESC sampler_desc {};
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampler_desc.Filter = filter;
sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
Expand Down Expand Up @@ -1263,8 +1270,14 @@ namespace platf::dxgi {
return -1;
}

D3D11_FILTER filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
if (config::video.point_filtering)
{
filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
}

D3D11_SAMPLER_DESC sampler_desc {};
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampler_desc.Filter = filter;
sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
Expand Down
12 changes: 12 additions & 0 deletions src_assets/common/assets/web/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,17 @@ <h1 class="my-4">Configuration</h1>
Disable if you encounter any VSync-related issues.
</div>
</div>
<div class="mb-3" v-if="platform === 'windows' || platform === 'linux'">
<label for="point_filtering" class="form-label">Nearest Point filtering</label>
<select id="point_filtering" class="form-select" v-model="config.point_filtering">
<option value="disabled">Disabled</option>
<option value="enabled">Enabled</option>
</select>
<div class="form-text">
Enable this to not interpolate captured screen to video size.<br />
May be useful for pixel-perfect streaming.
</div>
</div>
<div class="mb-3 config-page" v-if="platform === 'linux'">
<label for="output_name" class="form-label">Monitor number</label>
<input
Expand Down Expand Up @@ -1028,6 +1039,7 @@ <h1 class="my-4">Configuration</h1>
"controller": "enabled",
"install_steam_audio_drivers": "enabled",
"dwmflush": "enabled",
"point_filtering": "enabled",
"encoder": "",
"fps": "[10,30,60,90,120]",
"gamepad": "auto",
Expand Down