mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-12-12 01:36:58 +00:00
implement adjustable gamma
This commit is contained in:
parent
548cf3e965
commit
181176b046
9 changed files with 40 additions and 3 deletions
|
|
@ -232,6 +232,11 @@ void RendererShaderGL::SetUniform1i(sint32 location, sint32 value)
|
|||
glProgramUniform1i(m_program, location, value);
|
||||
}
|
||||
|
||||
void RendererShaderGL::SetUniform1f(sint32 location, float value)
|
||||
{
|
||||
glProgramUniform1f(m_program, location, value);
|
||||
}
|
||||
|
||||
void RendererShaderGL::SetUniform2fv(sint32 location, void* data, sint32 count)
|
||||
{
|
||||
glProgramUniform2fv(m_program, location, count, (const GLfloat*)data);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
sint32 GetUniformLocation(const char* name) override;
|
||||
|
||||
void SetUniform1i(sint32 location, sint32 value) override;
|
||||
void SetUniform1f(sint32 location, float value) override;
|
||||
void SetUniform2fv(sint32 location, void* data, sint32 count) override;
|
||||
void SetUniform4iv(sint32 location, void* data, sint32 count) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -136,11 +136,13 @@ RendererOutputShader::RendererOutputShader(const std::string& vertex_source, con
|
|||
m_uniformLocations[0].m_loc_nativeResolution = m_vertex_shader->GetUniformLocation("nativeResolution");
|
||||
m_uniformLocations[0].m_loc_outputResolution = m_vertex_shader->GetUniformLocation("outputResolution");
|
||||
m_uniformLocations[0].m_loc_applySRGBEncoding = m_vertex_shader->GetUniformLocation("applySRGBEncoding");
|
||||
m_uniformLocations[0].m_loc_targetGamma = m_fragment_shader->GetUniformLocation("targetGamma");
|
||||
|
||||
m_uniformLocations[1].m_loc_textureSrcResolution = m_fragment_shader->GetUniformLocation("textureSrcResolution");
|
||||
m_uniformLocations[1].m_loc_nativeResolution = m_fragment_shader->GetUniformLocation("nativeResolution");
|
||||
m_uniformLocations[1].m_loc_outputResolution = m_fragment_shader->GetUniformLocation("outputResolution");
|
||||
m_uniformLocations[1].m_loc_applySRGBEncoding = m_fragment_shader->GetUniformLocation("applySRGBEncoding");
|
||||
m_uniformLocations[1].m_loc_targetGamma = m_fragment_shader->GetUniformLocation("targetGamma");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,6 +177,12 @@ void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_
|
|||
{
|
||||
shader->SetUniform1i(locations.m_loc_applySRGBEncoding, padView ? LatteGPUState.drcBufferUsesSRGB : LatteGPUState.tvBufferUsesSRGB);
|
||||
}
|
||||
|
||||
if (locations.m_loc_targetGamma != -1)
|
||||
{
|
||||
shader->SetUniform1f(locations.m_loc_targetGamma, GetTargetGamma(padView)); // TODO: hook up to user-pref override or GX calls
|
||||
}
|
||||
|
||||
};
|
||||
setUniforms(m_vertex_shader.get(), m_uniformLocations[0]);
|
||||
setUniforms(m_fragment_shader.get(), m_uniformLocations[1]);
|
||||
|
|
@ -298,12 +306,14 @@ layout(push_constant) uniform pc {
|
|||
vec2 nativeResolution;
|
||||
vec2 outputResolution;
|
||||
bool applySRGBEncoding; // true = app requested sRGB encoding
|
||||
float targetGamma;
|
||||
};
|
||||
#else
|
||||
uniform vec2 textureSrcResolution;
|
||||
uniform vec2 nativeResolution;
|
||||
uniform vec2 outputResolution;
|
||||
uniform bool applySRGBEncoding;
|
||||
uniform float targetGamma;
|
||||
#endif
|
||||
|
||||
layout(location = 0) smooth in vec2 passUV;
|
||||
|
|
@ -333,6 +343,8 @@ void main()
|
|||
{
|
||||
colorOut0 = vec4(sRGBEncode(colorOut0.xyz), 1.0f);
|
||||
}
|
||||
|
||||
colorOut0 = pow(colorOut0, vec4(targetGamma / 2.2f) );
|
||||
}
|
||||
|
||||
)" + shaderSrc;
|
||||
|
|
@ -372,3 +384,8 @@ void RendererOutputShader::ShutdownStatic()
|
|||
delete s_hermit_shader;
|
||||
delete s_hermit_shader_ud;
|
||||
}
|
||||
|
||||
float RendererOutputShader::GetTargetGamma(const bool padView)
|
||||
{
|
||||
return 2.4f;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ public:
|
|||
|
||||
static std::string PrependFragmentPreamble(const std::string& shaderSrc);
|
||||
|
||||
static float GetTargetGamma(const bool padView);
|
||||
|
||||
protected:
|
||||
std::unique_ptr<RendererShader> m_vertex_shader;
|
||||
std::unique_ptr<RendererShader> m_fragment_shader;
|
||||
|
|
@ -56,6 +58,7 @@ protected:
|
|||
sint32 m_loc_nativeResolution = -1;
|
||||
sint32 m_loc_outputResolution = -1;
|
||||
sint32 m_loc_applySRGBEncoding = -1;
|
||||
sint32 m_loc_targetGamma = -1;
|
||||
} m_uniformLocations[2]{};
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ public:
|
|||
virtual sint32 GetUniformLocation(const char* name) = 0;
|
||||
|
||||
virtual void SetUniform1i(sint32 location, sint32 value) = 0;
|
||||
virtual void SetUniform1f(sint32 location, float value) = 0;
|
||||
virtual void SetUniform2fv(sint32 location, void* data, sint32 count) = 0;
|
||||
virtual void SetUniform4iv(sint32 location, void* data, sint32 count) = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -237,6 +237,11 @@ void RendererShaderVk::SetUniform1i(sint32 location, sint32 value)
|
|||
cemu_assert_suspicious();
|
||||
}
|
||||
|
||||
void RendererShaderVk::SetUniform1f(sint32 location, float value)
|
||||
{
|
||||
cemu_assert_suspicious();
|
||||
}
|
||||
|
||||
void RendererShaderVk::SetUniform2fv(sint32 location, void* data, sint32 count)
|
||||
{
|
||||
cemu_assert_suspicious();
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ public:
|
|||
|
||||
sint32 GetUniformLocation(const char* name) override;
|
||||
void SetUniform1i(sint32 location, sint32 value) override;
|
||||
void SetUniform1f(sint32 location, float value) override;
|
||||
void SetUniform2fv(sint32 location, void* data, sint32 count) override;
|
||||
void SetUniform4iv(sint32 location, void* data, sint32 count) override;
|
||||
VkShaderModule& GetShaderModule() { return m_shader_module; }
|
||||
|
|
|
|||
|
|
@ -2659,7 +2659,9 @@ VkPipeline VulkanRenderer::backbufferBlit_createGraphicsPipeline(VkDescriptorSet
|
|||
VkPushConstantRange pushConstantRange{
|
||||
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
.offset = 0,
|
||||
.size = 3 * sizeof(float) * 2 + 1 // 3 vec2's + 1 bool
|
||||
.size = 3 * sizeof(float) * 2 // 3 vec2's
|
||||
+ 4 // + 1 VkBool32
|
||||
+ 4 // + 1 float
|
||||
};
|
||||
|
||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
|
||||
|
|
@ -3051,7 +3053,8 @@ void VulkanRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu
|
|||
struct
|
||||
{
|
||||
Vector2f vecs[3];
|
||||
bool applySRGBEncoding;
|
||||
VkBool32 applySRGBEncoding;
|
||||
float targetGamma;
|
||||
} pushData;
|
||||
|
||||
// textureSrcResolution
|
||||
|
|
@ -3068,8 +3071,8 @@ void VulkanRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu
|
|||
// outputResolution
|
||||
pushData.vecs[2] = {(float)imageWidth,(float)imageHeight};
|
||||
|
||||
// applySRGBEncoding
|
||||
pushData.applySRGBEncoding = padView ? LatteGPUState.drcBufferUsesSRGB : LatteGPUState.tvBufferUsesSRGB;
|
||||
pushData.targetGamma = RendererOutputShader::GetTargetGamma(padView);
|
||||
|
||||
vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(pushData), &pushData);
|
||||
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ GLFUNC(PFNGLPROGRAMUNIFORM1IPROC, glProgramUniform1i)
|
|||
GLFUNC(PFNGLPROGRAMUNIFORM2IPROC, glProgramUniform2i)
|
||||
GLFUNC(PFNGLPROGRAMUNIFORM1IVPROC, glProgramUniform1iv)
|
||||
GLFUNC(PFNGLPROGRAMUNIFORM4IVPROC, glProgramUniform4iv)
|
||||
GLFUNC(PFNGLPROGRAMUNIFORM1IPROC, glProgramUniform1f)
|
||||
GLFUNC(PFNGLPROGRAMUNIFORM1FVPROC, glProgramUniform1fv)
|
||||
GLFUNC(PFNGLPROGRAMUNIFORM2FVPROC, glProgramUniform2fv)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue