Post shader setting uniform

This commit is contained in:
iota97 2020-05-15 11:15:38 +02:00
parent 192198ef3b
commit a666635fa2
15 changed files with 258 additions and 19 deletions

View File

@ -768,6 +768,30 @@ 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),
ConfigSetting("PostShaderSettingStep1", &g_Config.fPostShaderSettingStep1, 0.01f, 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),
ConfigSetting("PostShaderSettingStep2", &g_Config.fPostShaderSettingStep2, 0.01f, 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),
ConfigSetting("PostShaderSettingStep3", &g_Config.fPostShaderSettingStep3, 0.01f, 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),
ConfigSetting("PostShaderSettingStep4", &g_Config.fPostShaderSettingStep4, 0.01f, 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),

View File

@ -205,6 +205,26 @@ public:
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;
float fPostShaderSettingStep1;
std::string sPostShaderSettingName2;
float fPostShaderSettingValue2;
float fPostShaderMaxSettingValue2;
float fPostShaderMinSettingValue2;
float fPostShaderSettingStep2;
std::string sPostShaderSettingName3;
float fPostShaderSettingValue3;
float fPostShaderMaxSettingValue3;
float fPostShaderMinSettingValue3;
float fPostShaderSettingStep3;
std::string sPostShaderSettingName4;
float fPostShaderSettingValue4;
float fPostShaderMaxSettingValue4;
float fPostShaderMinSettingValue4;
float fPostShaderSettingStep4;
bool bGfxDebugOutput;
bool bGfxDebugSplitSubmit;
int iInflightFrames;

View File

@ -44,6 +44,26 @@ 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.settingStep1 = 0.01f;
off.settingName2 = "";
off.settingValue2 = 0.0f;
off.minSettingValue2 = -1.0f;
off.maxSettingValue2 = 1.0f;
off.settingStep2 = 0.01f;
off.settingName3 = "";
off.settingValue3 = 0.0f;
off.minSettingValue3 = -1.0f;
off.maxSettingValue3 = 1.0f;
off.settingStep3 = 0.01f;
off.settingName4 = "";
off.settingValue4 = 0.0f;
off.minSettingValue4 = -1.0f;
off.maxSettingValue4 = 1.0f;
off.settingStep4 = 0.01f;
shaderInfo.push_back(off);
for (size_t d = 0; d < directories.size(); d++) {
@ -90,7 +110,26 @@ 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("SettingStep1", &info.settingStep1, 0.01f);
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("SettingStep2", &info.settingStep2, 0.01f);
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("SettingStep3", &info.settingStep3, 0.01f);
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);
section.Get("SettingStep4", &info.settingStep4, 0.01f);
// Let's ignore shaders we can't support. TODO: Not a very good check
if (gl_extensions.IsGLES && !gl_extensions.GLES3) {
bool requiresIntegerSupport;

View File

@ -41,6 +41,27 @@ struct ShaderInfo {
// Force constant/max refresh for animated filters
bool requires60fps;
std::string settingName1;
float settingValue1;
float maxSettingValue1;
float minSettingValue1;
float settingStep1;
std::string settingName2;
float settingValue2;
float maxSettingValue2;
float minSettingValue2;
float settingStep2;
std::string settingName3;
float settingValue3;
float maxSettingValue3;
float minSettingValue3;
float settingStep3;
std::string settingName4;
float settingValue4;
float maxSettingValue4;
float minSettingValue4;
float settingStep4;
// TODO: Add support for all kinds of fun options like mapping the depth buffer,
// SRGB texture reads, multiple shaders chained, etc.

View File

@ -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) {
@ -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)

View File

@ -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];
};

View File

@ -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;
};
)";
@ -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;
};
)";
@ -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.

View File

@ -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, g_Config.fPostShaderSettingStep1, screenManager()));
if (g_Config.sPostShaderSettingName2 != "")
graphicsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fPostShaderSettingValue2, g_Config.fPostShaderMinSettingValue2, g_Config.fPostShaderMaxSettingValue2, g_Config.sPostShaderSettingName2, g_Config.fPostShaderSettingStep2, screenManager()));
if (g_Config.sPostShaderSettingName3 != "")
graphicsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fPostShaderSettingValue3, g_Config.fPostShaderMinSettingValue3, g_Config.fPostShaderMaxSettingValue3, g_Config.sPostShaderSettingName3, g_Config.fPostShaderSettingStep3, screenManager()));
if (g_Config.sPostShaderSettingName4 != "")
graphicsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fPostShaderSettingValue4, g_Config.fPostShaderMinSettingValue4, g_Config.fPostShaderMaxSettingValue4, g_Config.sPostShaderSettingName4, g_Config.fPostShaderSettingStep4, 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) {
@ -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) {

View File

@ -317,6 +317,30 @@ 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.fPostShaderSettingStep1 = shaders_[listView_->GetSelected()].settingStep1;
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.fPostShaderSettingStep2 = shaders_[listView_->GetSelected()].settingStep2;
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.fPostShaderSettingStep3 = shaders_[listView_->GetSelected()].settingStep3;
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;
g_Config.fPostShaderSettingStep4 = shaders_[listView_->GetSelected()].settingStep4;
}
NewLanguageScreen::NewLanguageScreen(const std::string &title) : ListPopupScreen(title) {

View File

@ -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()
{
@ -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)
@ -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;
}

View File

@ -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;
@ -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;

View File

@ -0,0 +1,23 @@
// Color correction
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D sampler0;
varying vec2 v_texcoord0;
uniform float u_setting1; // brightness - default: 1.0, range = 0.1 - 2.0
uniform float u_setting2; // saturation - default: 1.0, range = 0.0 - 2.0
uniform float u_setting3; // contrast - default: 1.0, range = 0.1 - 3.0
uniform float u_setting4; // gamma - default: 1.0, range = 0.1 - 2.0
void main()
{
vec3 rgb = texture2D( sampler0, v_texcoord0 ).xyz;
rgb = vec3(mix(vec3(dot(rgb, vec3(0.299, 0.587, 0.114))), rgb, u_setting2));
rgb = (rgb-0.5)*u_setting3+0.5+u_setting1-1.0;
gl_FragColor.rgb = pow(rgb, vec3(1.0/u_setting4));
gl_FragColor.a = 1.0;
}

View File

@ -32,10 +32,23 @@ 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
SettingStep1=0.1
[InverseColors]
Name=Inverse Colors
Author=Henrik
@ -46,10 +59,24 @@ Name=Scanlines (CRT)
Fragment=scanlines.fsh
Vertex=fxaa.vsh
OutputResolution=True
SettingName1=Amount
SettingDefaultValue1=1.0
SettingMaxValue1=1.0
SettingMinValue1=0.0
SettingStep1=0.1
SettingName2=Intensity
SettingDefaultValue2=0.5
SettingMaxValue2=1.0
SettingMinValue2=0.0
SettingStep2=0.05
[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
@ -93,3 +120,28 @@ Fragment=GaussianDownscale.fsh
Vertex=fxaa.vsh
OutputResolution=True
SSAA=2
[ColorCorrection]
Name=Color correction
Fragment=colorcorrection.fsh
Vertex=fxaa.vsh
SettingName1=Brightness
SettingDefaultValue1=1.0
SettingMaxValue1=2.0
SettingMinValue1=0.1
SettingStep1=0.05
SettingName2=Saturation
SettingDefaultValue2=1.0
SettingMaxValue2=2.0
SettingMinValue2=0.0
SettingStep2=0.1
SettingName3=Constrast
SettingDefaultValue3=1.0
SettingMaxValue3=3.0
SettingMinValue3=0.1
SettingStep3=0.1
SettingName4=Gamma
SettingDefaultValue4=1.0
SettingMaxValue4=2.0
SettingMinValue4=0.1
SettingStep4=0.05

View File

@ -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

View File

@ -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;
}