summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2016-12-29 13:41:51 -0500
committerGravatar GitHub2016-12-29 13:41:51 -0500
commit2f746e9946f78a2e283dfdcbeda9cf332e44d099 (patch)
tree58c8833bbfe8673381d4839492bc2b5d311d7477 /src
parentMerge pull request #2376 from wwylele/remove-unused (diff)
parentMinor cleanup in GLSL code (diff)
downloadyuzu-2f746e9946f78a2e283dfdcbeda9cf332e44d099.tar.gz
yuzu-2f746e9946f78a2e283dfdcbeda9cf332e44d099.tar.xz
yuzu-2f746e9946f78a2e283dfdcbeda9cf332e44d099.zip
Merge pull request #2367 from JayFoxRox/lighting-lut-quickfix
Lighting LUT Quickfix
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 8f278722d..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) {
293 case CompareFunc::GreaterThanOrEqual: { 293 case CompareFunc::GreaterThanOrEqual: {
294 static const char* op[] = {"!=", "==", ">=", ">", "<=", "<"}; 294 static const char* op[] = {"!=", "==", ">=", ">", "<=", "<"};
295 unsigned index = (unsigned)func - (unsigned)CompareFunc::Equal; 295 unsigned index = (unsigned)func - (unsigned)CompareFunc::Equal;
296 out += "int(last_tex_env_out.a * 255.0f) " + std::string(op[index]) + " alphatest_ref"; 296 out += "int(last_tex_env_out.a * 255.0) " + std::string(op[index]) + " alphatest_ref";
297 break; 297 break;
298 } 298 }
299 299
@@ -422,16 +422,13 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
422 if (abs) { 422 if (abs) {
423 // LUT index is in the range of (0.0, 1.0) 423 // LUT index is in the range of (0.0, 1.0)
424 index = lighting.light[light_num].two_sided_diffuse ? "abs(" + index + ")" 424 index = lighting.light[light_num].two_sided_diffuse ? "abs(" + index + ")"
425 : "max(" + index + ", 0.f)"; 425 : "max(" + index + ", 0.0)";
426 return "(FLOAT_255 * clamp(" + index + ", 0.0, 1.0))";
427 } else { 426 } else {
428 // LUT index is in the range of (-1.0, 1.0) 427 // LUT index is in the range of (-1.0, 1.0)
429 index = "clamp(" + index + ", -1.0, 1.0)"; 428 index = "((" + index + " < 0) ? " + index + " + 2.0 : " + index + ") / 2.0";
430 return "(FLOAT_255 * ((" + index + " < 0) ? " + index + " + 2.0 : " + index +
431 ") / 2.0)";
432 } 429 }
433 430
434 return std::string(); 431 return "(OFFSET_256 + SCALE_256 * clamp(" + index + ", 0.0, 1.0))";
435 }; 432 };
436 433
437 // Gets the lighting lookup table value given the specified sampler and index 434 // 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) {
462 if (light_config.dist_atten_enable) { 459 if (light_config.dist_atten_enable) {
463 std::string index = "(" + light_src + ".dist_atten_scale * length(-view - " + 460 std::string index = "(" + light_src + ".dist_atten_scale * length(-view - " +
464 light_src + ".position) + " + light_src + ".dist_atten_bias)"; 461 light_src + ".position) + " + light_src + ".dist_atten_bias)";
465 index = "((clamp(" + index + ", 0.0, FLOAT_255)))"; 462 index = "(OFFSET_256 + SCALE_256 * clamp(" + index + ", 0.0, 1.0))";
466 const unsigned lut_num = 463 const unsigned lut_num =
467 ((unsigned)Regs::LightingSampler::DistanceAttenuation + light_config.num); 464 ((unsigned)Regs::LightingSampler::DistanceAttenuation + light_config.num);
468 dist_atten = GetLutValue((Regs::LightingSampler)lut_num, index); 465 dist_atten = GetLutValue((Regs::LightingSampler)lut_num, index);
@@ -580,8 +577,10 @@ std::string GenerateFragmentShader(const PicaShaderConfig& config) {
580#version 330 core 577#version 330 core
581#define NUM_TEV_STAGES 6 578#define NUM_TEV_STAGES 6
582#define NUM_LIGHTS 8 579#define NUM_LIGHTS 8
583#define LIGHTING_LUT_SIZE 256 580
584#define FLOAT_255 (255.0 / 256.0) 581// Texture coordinate offsets and scales
582#define OFFSET_256 (0.5 / 256.0)
583#define SCALE_256 (255.0 / 256.0)
585 584
586in vec4 primary_color; 585in vec4 primary_color;
587in vec2 texcoord[3]; 586in vec2 texcoord[3];