From 88f409aec9a490138012cde35789d1f21f20818f Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sun, 25 Dec 2016 20:55:24 +0100 Subject: Offset lighting LUT samples correctly --- src/video_core/renderer_opengl/gl_shader_gen.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/video_core/renderer_opengl') diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 8f278722d..d485ddacf 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -423,15 +423,12 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { // LUT index is in the range of (0.0, 1.0) index = lighting.light[light_num].two_sided_diffuse ? "abs(" + index + ")" : "max(" + index + ", 0.f)"; - return "(FLOAT_255 * clamp(" + index + ", 0.0, 1.0))"; } else { // LUT index is in the range of (-1.0, 1.0) - index = "clamp(" + index + ", -1.0, 1.0)"; - return "(FLOAT_255 * ((" + index + " < 0) ? " + index + " + 2.0 : " + index + - ") / 2.0)"; + index = "((" + index + " < 0) ? " + index + " + 2.0 : " + index + ") / 2.0"; } - return std::string(); + return "(OFFSET_256 + SCALE_256 * clamp(" + index + ", 0.0, 1.0))"; }; // Gets the lighting lookup table value given the specified sampler and index @@ -462,7 +459,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { if (light_config.dist_atten_enable) { std::string index = "(" + light_src + ".dist_atten_scale * length(-view - " + light_src + ".position) + " + light_src + ".dist_atten_bias)"; - index = "((clamp(" + index + ", 0.0, FLOAT_255)))"; + index = "(OFFSET_256 + SCALE_256 * clamp(" + index + ", 0.0, 1.0))"; const unsigned lut_num = ((unsigned)Regs::LightingSampler::DistanceAttenuation + light_config.num); dist_atten = GetLutValue((Regs::LightingSampler)lut_num, index); @@ -581,7 +578,10 @@ std::string GenerateFragmentShader(const PicaShaderConfig& config) { #define NUM_TEV_STAGES 6 #define NUM_LIGHTS 8 #define LIGHTING_LUT_SIZE 256 -#define FLOAT_255 (255.0 / 256.0) + +// Texture coordinate offsets and scales +#define OFFSET_256 (0.5 / 256.0) +#define SCALE_256 (255.0 / 256.0) in vec4 primary_color; in vec2 texcoord[3]; -- cgit v1.2.3 From 6ed4206f878da69bbd71e018eb6c82872a1f328b Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sun, 25 Dec 2016 20:56:42 +0100 Subject: Minor cleanup in GLSL code --- src/video_core/renderer_opengl/gl_shader_gen.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/video_core/renderer_opengl') diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index d485ddacf..4c4f98ac9 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -293,7 +293,7 @@ static void AppendAlphaTestCondition(std::string& out, Regs::CompareFunc func) { case CompareFunc::GreaterThanOrEqual: { static const char* op[] = {"!=", "==", ">=", ">", "<=", "<"}; unsigned index = (unsigned)func - (unsigned)CompareFunc::Equal; - out += "int(last_tex_env_out.a * 255.0f) " + std::string(op[index]) + " alphatest_ref"; + out += "int(last_tex_env_out.a * 255.0) " + std::string(op[index]) + " alphatest_ref"; break; } @@ -422,7 +422,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { if (abs) { // LUT index is in the range of (0.0, 1.0) index = lighting.light[light_num].two_sided_diffuse ? "abs(" + index + ")" - : "max(" + index + ", 0.f)"; + : "max(" + index + ", 0.0)"; } else { // LUT index is in the range of (-1.0, 1.0) index = "((" + index + " < 0) ? " + index + " + 2.0 : " + index + ") / 2.0"; @@ -577,7 +577,6 @@ std::string GenerateFragmentShader(const PicaShaderConfig& config) { #version 330 core #define NUM_TEV_STAGES 6 #define NUM_LIGHTS 8 -#define LIGHTING_LUT_SIZE 256 // Texture coordinate offsets and scales #define OFFSET_256 (0.5 / 256.0) -- cgit v1.2.3