Skip to content

Commit

Permalink
Post shader setting uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
iota97 committed May 15, 2020
1 parent 192198e commit 8aaa338
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 19 deletions.
20 changes: 20 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,26 @@ static ConfigSetting graphicsSettings[] = {
ReportedConfigSetting("HardwareTessellation", &g_Config.bHardwareTessellation, false, true, true),
ReportedConfigSetting("PostShader", &g_Config.sPostShaderName, "Off", true, true),

ReportedConfigSetting("PostShaderSettingName1", &g_Config.sPostShaderSettingName1, "", true, true),
ReportedConfigSetting("PostShaderSettingValue1", &g_Config.fPostShaderSettingValue1, 0.0f, true, true),
ConfigSetting("PostShaderSettingMaxValue1", &g_Config.fPostShaderMaxSettingValue1, 1.0f, true, true),
ConfigSetting("PostShaderSettingMinValue1", &g_Config.fPostShaderMinSettingValue1, -1.0f, true, true),

ReportedConfigSetting("PostShaderSettingName2", &g_Config.sPostShaderSettingName2, "", true, true),
ReportedConfigSetting("PostShaderSettingValue2", &g_Config.fPostShaderSettingValue2, 0.0f, true, true),
ConfigSetting("PostShaderSettingMaxValue2", &g_Config.fPostShaderMaxSettingValue2, 1.0f, true, true),
ConfigSetting("PostShaderSettingMinValue2", &g_Config.fPostShaderMinSettingValue2, -1.0f, true, true),

ReportedConfigSetting("PostShaderSettingName3", &g_Config.sPostShaderSettingName3, "", true, true),
ReportedConfigSetting("PostShaderSettingValue3", &g_Config.fPostShaderSettingValue3, 0.0f, true, true),
ConfigSetting("PostShaderSettingMaxValue3", &g_Config.fPostShaderMaxSettingValue3, 1.0f, true, true),
ConfigSetting("PostShaderSettingMinValue3", &g_Config.fPostShaderMinSettingValue3, -1.0f, true, true),

ReportedConfigSetting("PostShaderSettingName4", &g_Config.sPostShaderSettingName4, "", true, true),
ReportedConfigSetting("PostShaderSettingValue4", &g_Config.fPostShaderSettingValue4, 0.0f, true, true),
ConfigSetting("PostShaderSettingMaxValue4", &g_Config.fPostShaderMaxSettingValue4, 1.0f, true, true),
ConfigSetting("PostShaderSettingMinValue4", &g_Config.fPostShaderMinSettingValue4, -1.0f, true, true),

ReportedConfigSetting("MemBlockTransferGPU", &g_Config.bBlockTransferGPU, true, true, true),
ReportedConfigSetting("DisableSlowFramebufEffects", &g_Config.bDisableSlowFramebufEffects, false, true, true),
ReportedConfigSetting("FragmentTestCache", &g_Config.bFragmentTestCache, true, true, true),
Expand Down
16 changes: 16 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ struct Config {
int iSplineBezierQuality; // 0 = low , 1 = Intermediate , 2 = High
bool bHardwareTessellation;
std::string sPostShaderName; // Off for off.
std::string sPostShaderSettingName1;
float fPostShaderSettingValue1;
float fPostShaderMaxSettingValue1;
float fPostShaderMinSettingValue1;
std::string sPostShaderSettingName2;
float fPostShaderSettingValue2;
float fPostShaderMaxSettingValue2;
float fPostShaderMinSettingValue2;
std::string sPostShaderSettingName3;
float fPostShaderSettingValue3;
float fPostShaderMaxSettingValue3;
float fPostShaderMinSettingValue3;
std::string sPostShaderSettingName4;
float fPostShaderSettingValue4;
float fPostShaderMaxSettingValue4;
float fPostShaderMinSettingValue4;
bool bGfxDebugOutput;
bool bGfxDebugSplitSubmit;
int iInflightFrames;
Expand Down
33 changes: 32 additions & 1 deletion GPU/Common/PostShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ void LoadPostShaderInfo(std::vector<std::string> directories) {
off.isUpscalingFilter = false;
off.SSAAFilterLevel = 0;
off.requires60fps = false;
off.settingName1 = "";
off.settingValue1 = 0.0f;
off.minSettingValue1 = -1.0f;
off.maxSettingValue1 = 1.0f;
off.settingName2 = "";
off.settingValue2 = 0.0f;
off.minSettingValue2 = -1.0f;
off.maxSettingValue2 = 1.0f;
off.settingName3 = "";
off.settingValue3 = 0.0f;
off.minSettingValue3 = -1.0f;
off.maxSettingValue3 = 1.0f;
off.settingName4 = "";
off.settingValue4 = 0.0f;
off.minSettingValue4 = -1.0f;
off.maxSettingValue4 = 1.0f;
shaderInfo.push_back(off);

for (size_t d = 0; d < directories.size(); d++) {
Expand Down Expand Up @@ -90,7 +106,22 @@ void LoadPostShaderInfo(std::vector<std::string> directories) {
section.Get("Upscaling", &info.isUpscalingFilter, false);
section.Get("SSAA", &info.SSAAFilterLevel, 0);
section.Get("60fps", &info.requires60fps, false);

section.Get("SettingName1", &info.settingName1, "");
section.Get("SettingDefaultValue1", &info.settingValue1, 0.0f);
section.Get("SettingMinValue1", &info.minSettingValue1, -1.0f);
section.Get("SettingMaxValue1", &info.maxSettingValue1, 1.0f);
section.Get("SettingName2", &info.settingName2, "");
section.Get("SettingDefaultValue2", &info.settingValue2, 0.0f);
section.Get("SettingMinValue2", &info.minSettingValue2, -1.0f);
section.Get("SettingMaxValue2", &info.maxSettingValue2, 1.0f);
section.Get("SettingName3", &info.settingName3, "");
section.Get("SettingDefaultValue3", &info.settingValue3, 0.0f);
section.Get("SettingMinValue3", &info.minSettingValue3, -1.0f);
section.Get("SettingMaxValue3", &info.maxSettingValue3, 1.0f);
section.Get("SettingName4", &info.settingName4, "");
section.Get("SettingDefaultValue4", &info.settingValue4, 0.0f);
section.Get("SettingMinValue4", &info.minSettingValue4, -1.0f);
section.Get("SettingMaxValue4", &info.maxSettingValue4, 1.0f);
// Let's ignore shaders we can't support. TODO: Not a very good check
if (gl_extensions.IsGLES && !gl_extensions.GLES3) {
bool requiresIntegerSupport;
Expand Down
17 changes: 17 additions & 0 deletions GPU/Common/PostShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ struct ShaderInfo {
// Force constant/max refresh for animated filters
bool requires60fps;

std::string settingName1;
float settingValue1;
float maxSettingValue1;
float minSettingValue1;
std::string settingName2;
float settingValue2;
float maxSettingValue2;
float minSettingValue2;
std::string settingName3;
float settingValue3;
float maxSettingValue3;
float minSettingValue3;
std::string settingName4;
float settingValue4;
float maxSettingValue4;
float minSettingValue4;

// TODO: Add support for all kinds of fun options like mapping the depth buffer,
// SRGB texture reads, multiple shaders chained, etc.

Expand Down
9 changes: 9 additions & 0 deletions GPU/Common/PresentationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ void PresentationCommon::CalculatePostShaderUniforms(int bufferWidth, int buffer
// The shader translator tacks this onto our shaders, if we don't set it they render garbage.
uniforms->gl_HalfPixel[0] = u_pixel_delta * 0.5f;
uniforms->gl_HalfPixel[1] = v_pixel_delta * 0.5f;

uniforms->setting1 = g_Config.fPostShaderSettingValue1;
uniforms->setting2 = g_Config.fPostShaderSettingValue2;
uniforms->setting3 = g_Config.fPostShaderSettingValue3;
uniforms->setting4 = g_Config.fPostShaderSettingValue4;
}

static std::string ReadShaderSrc(const std::string &filename) {
Expand Down Expand Up @@ -214,6 +219,10 @@ bool PresentationCommon::UpdatePostShader() {
{ "u_pixelDelta", 2, 2, Draw::UniformType::FLOAT2, offsetof(PostShaderUniforms, pixelDelta) },
{ "u_time", 3, 3, Draw::UniformType::FLOAT4, offsetof(PostShaderUniforms, time) },
{ "u_video", 4, 4, Draw::UniformType::FLOAT1, offsetof(PostShaderUniforms, video) },
{ "u_setting1", 5, 5, Draw::UniformType::FLOAT1, offsetof(PostShaderUniforms, setting1) },
{ "u_setting2", 6, 6, Draw::UniformType::FLOAT1, offsetof(PostShaderUniforms, setting2) },
{ "u_setting3", 7, 7, Draw::UniformType::FLOAT1, offsetof(PostShaderUniforms, setting3) },
{ "u_setting4", 8, 8, Draw::UniformType::FLOAT1, offsetof(PostShaderUniforms, setting4) },
} };
Draw::Pipeline *pipeline = CreatePipeline({ vs, fs }, true, &postShaderDesc);
if (!pipeline)
Expand Down
7 changes: 6 additions & 1 deletion GPU/Common/PresentationCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ struct CardboardSettings {
struct PostShaderUniforms {
float texelDelta[2]; float pixelDelta[2];
float time[4];
float video; float pad[3];
float video;
float setting1;
float setting2;
float setting3;
float setting4;
float pad[3];
// Used on Direct3D9.
float gl_HalfPixel[4];
};
Expand Down
12 changes: 12 additions & 0 deletions GPU/Common/ShaderTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ cbuffer data : register(b0) {
float2 u_pixelDelta;
float4 u_time;
float u_video;
float u_setting1;
float u_setting2;
float u_setting3;
float u_setting4;
};
)";

Expand All @@ -102,6 +106,10 @@ layout (std140, set = 0, binding = 0) uniform Data {
vec2 u_pixelDelta;
vec4 u_time;
float u_video;
float u_setting1;
float u_setting2;
float u_setting3;
float u_setting4;
};
)";

Expand All @@ -111,6 +119,10 @@ float2 u_texelDelta : register(c1);
float2 u_pixelDelta : register(c2);
float4 u_time : register(c3);
float u_video : register(c4);
float u_setting1 : register(c5);
float u_setting2 : register(c6);
float u_setting3 : register(c7);
float u_setting4 : register(c8);
)";

// SPIRV-Cross' HLSL output has some deficiencies we need to work around.
Expand Down
14 changes: 12 additions & 2 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,15 @@ void GameSettingsScreen::CreateViews() {
return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
});

if (g_Config.sPostShaderSettingName1 != "")
graphicsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fPostShaderSettingValue1, g_Config.fPostShaderMinSettingValue1, g_Config.fPostShaderMaxSettingValue1, g_Config.sPostShaderSettingName1, 0.01f, screenManager()));
if (g_Config.sPostShaderSettingName2 != "")
graphicsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fPostShaderSettingValue2, g_Config.fPostShaderMinSettingValue2, g_Config.fPostShaderMaxSettingValue2, g_Config.sPostShaderSettingName2, 0.01f, screenManager()));
if (g_Config.sPostShaderSettingName3 != "")
graphicsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fPostShaderSettingValue3, g_Config.fPostShaderMinSettingValue3, g_Config.fPostShaderMaxSettingValue3, g_Config.sPostShaderSettingName3, 0.01f, screenManager()));
if (g_Config.sPostShaderSettingName4 != "")
graphicsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fPostShaderSettingValue4, g_Config.fPostShaderMinSettingValue4, g_Config.fPostShaderMaxSettingValue4, g_Config.sPostShaderSettingName4, 0.01f, screenManager()));

#if !defined(MOBILE_DEVICE)
graphicsSettings->Add(new CheckBox(&g_Config.bFullScreen, gr->T("FullScreen", "Full Screen")))->OnClick.Handle(this, &GameSettingsScreen::OnFullscreenChange);
if (System_GetPropertyInt(SYSPROP_DISPLAY_COUNT) > 1) {
Expand Down Expand Up @@ -1413,12 +1422,13 @@ UI::EventReturn GameSettingsScreen::OnPostProcShader(UI::EventParams &e) {

UI::EventReturn GameSettingsScreen::OnPostProcShaderChange(UI::EventParams &e) {
NativeMessageReceived("gpu_resized", "");
RecreateViews(); // Update setting name
return UI::EVENT_DONE;
}

UI::EventReturn GameSettingsScreen::OnDeveloperTools(UI::EventParams &e) {
screenManager()->push(new DeveloperToolsScreen());
return UI::EVENT_DONE;
screenManager()->push(new DeveloperToolsScreen());
return UI::EVENT_DONE;
}

UI::EventReturn GameSettingsScreen::OnRemoteISO(UI::EventParams &e) {
Expand Down
20 changes: 20 additions & 0 deletions UI/MiscScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,26 @@ void PostProcScreen::OnCompleted(DialogResult result) {
if (result != DR_OK)
return;
g_Config.sPostShaderName = shaders_[listView_->GetSelected()].section;

g_Config.sPostShaderSettingName1 = shaders_[listView_->GetSelected()].settingName1;
g_Config.fPostShaderSettingValue1 = shaders_[listView_->GetSelected()].settingValue1;
g_Config.fPostShaderMaxSettingValue1 = shaders_[listView_->GetSelected()].maxSettingValue1;
g_Config.fPostShaderMinSettingValue1 = shaders_[listView_->GetSelected()].minSettingValue1;

g_Config.sPostShaderSettingName2 = shaders_[listView_->GetSelected()].settingName2;
g_Config.fPostShaderSettingValue2 = shaders_[listView_->GetSelected()].settingValue2;
g_Config.fPostShaderMaxSettingValue2 = shaders_[listView_->GetSelected()].maxSettingValue2;
g_Config.fPostShaderMinSettingValue2 = shaders_[listView_->GetSelected()].minSettingValue2;

g_Config.sPostShaderSettingName3 = shaders_[listView_->GetSelected()].settingName3;
g_Config.fPostShaderSettingValue3 = shaders_[listView_->GetSelected()].settingValue3;
g_Config.fPostShaderMaxSettingValue3 = shaders_[listView_->GetSelected()].maxSettingValue3;
g_Config.fPostShaderMinSettingValue3 = shaders_[listView_->GetSelected()].minSettingValue3;

g_Config.sPostShaderSettingName4 = shaders_[listView_->GetSelected()].settingName4;
g_Config.fPostShaderSettingValue4 = shaders_[listView_->GetSelected()].settingValue4;
g_Config.fPostShaderMaxSettingValue4 = shaders_[listView_->GetSelected()].maxSettingValue4;
g_Config.fPostShaderMinSettingValue4 = shaders_[listView_->GetSelected()].minSettingValue4;
}

NewLanguageScreen::NewLanguageScreen(const std::string &title) : ListPopupScreen(title) {
Expand Down
12 changes: 6 additions & 6 deletions assets/shaders/bloom.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ precision mediump int;
uniform sampler2D sampler0;
varying vec2 v_texcoord0;

float amount = 0.60; // suitable range = 0.00 - 1.00
float power = 0.5; // suitable range = 0.0 - 1.0
uniform float u_setting1; // float amount = 0.60; // suitable range = 0.00 - 1.00
uniform float u_setting2; // float power = 0.5; // suitable range = 0.0 - 1.0

void main()
{
Expand All @@ -21,9 +21,9 @@ void main()

for(int i= -3 ;i < 3; i++)
{
sum += texture2D(sampler0, v_texcoord0 + vec2(-1, i)*0.004) * amount;
sum += texture2D(sampler0, v_texcoord0 + vec2(0, i)*0.004) * amount;
sum += texture2D(sampler0, v_texcoord0 + vec2(1, i)*0.004) * amount;
sum += texture2D(sampler0, v_texcoord0 + vec2(-1, i)*0.004) * u_setting1;
sum += texture2D(sampler0, v_texcoord0 + vec2(0, i)*0.004) * u_setting1;
sum += texture2D(sampler0, v_texcoord0 + vec2(1, i)*0.004) * u_setting1;
}

if (color.r < 0.3 && color.g < 0.3 && color.b < 0.3)
Expand All @@ -42,7 +42,7 @@ void main()
}
}

bloom = mix(color, bloom, power);
bloom = mix(color, bloom, u_setting2);
gl_FragColor.rgb = bloom;
gl_FragColor.a = 1.0;
}
4 changes: 2 additions & 2 deletions assets/shaders/cartoon.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ precision mediump float;
precision mediump int;
#endif

const float bb = 0.5; // effects black border sensitivity; from 0.0 to 1.0
uniform float u_setting1; // const float bb = 0.5; // effects black border sensitivity; from 0.0 to 1.0

uniform sampler2D sampler0;

Expand Down Expand Up @@ -39,7 +39,7 @@ void main()
float d2=dot(abs(c20-c02),dt);
float hl=dot(abs(c01-c21),dt);
float vl=dot(abs(c10-c12),dt);
float d = bb*(d1+d2+hl+vl)/(dot(c11,dt)+0.15);
float d = u_setting1*(d1+d2+hl+vl)/(dot(c11,dt)+0.15);

float lc = 4.0*length(c11);
float f = fract(lc); f*=f;
Expand Down
24 changes: 24 additions & 0 deletions assets/shaders/defaultshaders.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,22 @@ Vertex=fxaa.vsh
Name=Bloom
Fragment=bloom.fsh
Vertex=fxaa.vsh
SettingName1=Amount
SettingDefaultValue1=0.6
SettingMaxValue1=1.0
SettingMinValue1=0.0
SettingName2=Power
SettingDefaultValue2=0.5
SettingMaxValue2=1.0
SettingMinValue2=0.0
[Sharpen]
Name=Sharpen
Fragment=sharpen.fsh
Vertex=fxaa.vsh
SettingName1=Amount
SettingDefaultValue1=1.5
SettingMaxValue1=3.0
SettingMinValue1=1.0
[InverseColors]
Name=Inverse Colors
Author=Henrik
Expand All @@ -46,10 +58,22 @@ Name=Scanlines (CRT)
Fragment=scanlines.fsh
Vertex=fxaa.vsh
OutputResolution=True
SettingName1=Amount
SettingDefaultValue1=1.0
SettingMaxValue1=1.0
SettingMinValue1=0.0
SettingName2=Intensity
SettingDefaultValue2=0.5
SettingMaxValue2=1.0
SettingMinValue2=0.0
[Cartoon]
Name=Cartoon
Fragment=cartoon.fsh
Vertex=cartoon.vsh
SettingName1=Black border
SettingDefaultValue1=0.5
SettingMaxValue1=1.0
SettingMinValue1=0.0
[4xHqGLSL]
Name=4xHqGLSL Upscaler
Fragment=4xhqglsl.fsh
Expand Down
8 changes: 4 additions & 4 deletions assets/shaders/scanlines.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ precision mediump int;
uniform sampler2D sampler0;
varying vec2 v_texcoord0;

float amount = 1.0; // suitable range = 0.0 - 1.0
float intensity = 0.5; // suitable range = 0.0 - 1.0
uniform float u_setting1; // float amount = 1.0; // suitable range = 0.0 - 1.0
uniform float u_setting2; // float intensity = 0.5; // suitable range = 0.0 - 1.0

void main()
{
float pos0 = ((v_texcoord0.y + 1.0) * 170.0*amount);
float pos1 = cos((fract( pos0 ) - 0.5)*3.1415926*intensity)*1.5;
float pos0 = ((v_texcoord0.y + 1.0) * 170.0*u_setting1);
float pos1 = cos((fract( pos0 ) - 0.5)*3.1415926*u_setting2)*1.5;
vec4 rgb = texture2D( sampler0, v_texcoord0 );

// slight contrast curve
Expand Down
6 changes: 3 additions & 3 deletions assets/shaders/sharpen.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ precision mediump int;
uniform sampler2D sampler0;
varying vec2 v_texcoord0;

float amount = 1.5;
uniform float u_setting1; float amount = 1.5;

void main()
{
vec3 color = texture2D(sampler0, v_texcoord0.xy).xyz;
color -= texture2D(sampler0, v_texcoord0.xy+0.0001).xyz*7.0*amount;
color += texture2D(sampler0, v_texcoord0.xy-0.0001).xyz*7.0*amount;
color -= texture2D(sampler0, v_texcoord0.xy+0.0001).xyz*7.0*u_setting1;
color += texture2D(sampler0, v_texcoord0.xy-0.0001).xyz*7.0*u_setting1;
gl_FragColor.rgb = color;
}

0 comments on commit 8aaa338

Please sign in to comment.