diff options
| author | 2015-11-18 23:40:18 -0500 | |
|---|---|---|
| committer | 2016-02-05 17:17:35 -0500 | |
| commit | 3d89dacd56064c3c49cd1ae9482a0221f1912f56 (patch) | |
| tree | 2584a9e691636fb3c2c88c0f579bbcc022e8dec2 /src | |
| parent | pica: Cleanup and add some comments to lighting registers. (diff) | |
| download | yuzu-3d89dacd56064c3c49cd1ae9482a0221f1912f56.tar.gz yuzu-3d89dacd56064c3c49cd1ae9482a0221f1912f56.tar.xz yuzu-3d89dacd56064c3c49cd1ae9482a0221f1912f56.zip | |
gl_shader_gen: Refactor lighting config to match Pica register naming.
- Also implement D0 LUT enable.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/pica.h | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 60 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 30 |
3 files changed, 50 insertions, 42 deletions
diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 48854dda2..b1cf072f1 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h | |||
| @@ -718,6 +718,8 @@ struct Regs { | |||
| 718 | }; | 718 | }; |
| 719 | 719 | ||
| 720 | union { | 720 | union { |
| 721 | BitField<16, 1, u32> lut_enable_d0; // 0: GL_TRUE, 1: GL_FALSE | ||
| 722 | |||
| 721 | // Each bit specifies whether distance attenuation should be applied for the | 723 | // Each bit specifies whether distance attenuation should be applied for the |
| 722 | // corresponding light | 724 | // corresponding light |
| 723 | 725 | ||
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 6be161efd..2042be786 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -73,23 +73,24 @@ struct PicaShaderConfig { | |||
| 73 | 73 | ||
| 74 | // Fragment lighting | 74 | // Fragment lighting |
| 75 | 75 | ||
| 76 | res.lighting_enabled = !regs.lighting.disable; | 76 | res.lighting.enable = !regs.lighting.disable; |
| 77 | res.num_lights = regs.lighting.src_num + 1; | 77 | res.lighting.src_num = regs.lighting.src_num + 1; |
| 78 | 78 | ||
| 79 | for (unsigned light_index = 0; light_index < res.num_lights; ++light_index) { | 79 | for (unsigned light_index = 0; light_index < res.lighting.src_num; ++light_index) { |
| 80 | unsigned num = regs.lighting.light_enable.GetNum(light_index); | 80 | unsigned num = regs.lighting.light_enable.GetNum(light_index); |
| 81 | const auto& light = regs.lighting.light[num]; | 81 | const auto& light = regs.lighting.light[num]; |
| 82 | res.light_src[light_index].num = num; | 82 | res.lighting.light[light_index].num = num; |
| 83 | res.light_src[light_index].directional = light.directional != 0; | 83 | res.lighting.light[light_index].directional = light.directional != 0; |
| 84 | res.light_src[light_index].two_sided_diffuse = light.two_sided_diffuse != 0; | 84 | res.lighting.light[light_index].two_sided_diffuse = light.two_sided_diffuse != 0; |
| 85 | res.light_src[light_index].dist_atten_enabled = regs.lighting.IsDistAttenEnabled(num); | 85 | res.lighting.light[light_index].dist_atten_enable = regs.lighting.IsDistAttenEnabled(num); |
| 86 | res.light_src[light_index].dist_atten_bias = Pica::float20::FromRawFloat20(light.dist_atten_bias).ToFloat32(); | 86 | res.lighting.light[light_index].dist_atten_bias = Pica::float20::FromRawFloat20(light.dist_atten_bias).ToFloat32(); |
| 87 | res.light_src[light_index].dist_atten_scale = Pica::float20::FromRawFloat20(light.dist_atten_scale).ToFloat32(); | 87 | res.lighting.light[light_index].dist_atten_scale = Pica::float20::FromRawFloat20(light.dist_atten_scale).ToFloat32(); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | res.lighting_lut.d0_abs = regs.lighting.abs_lut_input.d0 == 0; | 90 | res.lighting.lut_d0.enable = regs.lighting.lut_enable_d0 == 0; |
| 91 | res.lighting_lut.d0_type = (Pica::Regs::LightingLutInput)regs.lighting.lut_input.d0.Value(); | 91 | res.lighting.lut_d0.abs_input = regs.lighting.abs_lut_input.d0 == 0; |
| 92 | res.clamp_highlights = regs.lighting.clamp_highlights != 0; | 92 | res.lighting.lut_d0.type = (Pica::Regs::LightingLutInput)regs.lighting.lut_input.d0.Value(); |
| 93 | res.lighting.clamp_highlights = regs.lighting.clamp_highlights != 0; | ||
| 93 | 94 | ||
| 94 | return res; | 95 | return res; |
| 95 | } | 96 | } |
| @@ -112,22 +113,25 @@ struct PicaShaderConfig { | |||
| 112 | u8 combiner_buffer_input = 0; | 113 | u8 combiner_buffer_input = 0; |
| 113 | 114 | ||
| 114 | struct { | 115 | struct { |
| 115 | unsigned num = 0; | 116 | struct { |
| 116 | bool directional = false; | 117 | unsigned num = 0; |
| 117 | bool two_sided_diffuse = false; | 118 | bool directional = false; |
| 118 | bool dist_atten_enabled = false; | 119 | bool two_sided_diffuse = false; |
| 119 | GLfloat dist_atten_scale = 0.0f; | 120 | bool dist_atten_enable = false; |
| 120 | GLfloat dist_atten_bias = 0.0f; | 121 | GLfloat dist_atten_scale = 0.0f; |
| 121 | } light_src[8]; | 122 | GLfloat dist_atten_bias = 0.0f; |
| 122 | 123 | } light[8]; | |
| 123 | bool lighting_enabled = false; | 124 | |
| 124 | unsigned num_lights = 0; | 125 | bool enable = false; |
| 125 | bool clamp_highlights = false; | 126 | unsigned src_num = 0; |
| 126 | 127 | bool clamp_highlights = false; | |
| 127 | struct { | 128 | |
| 128 | bool d0_abs = false; | 129 | struct { |
| 129 | Pica::Regs::LightingLutInput d0_type = Pica::Regs::LightingLutInput::NH; | 130 | bool enable = false; |
| 130 | } lighting_lut; | 131 | bool abs_input = false; |
| 132 | Pica::Regs::LightingLutInput type = Pica::Regs::LightingLutInput::NH; | ||
| 133 | } lut_d0; | ||
| 134 | } lighting; | ||
| 131 | }; | 135 | }; |
| 132 | }; | 136 | }; |
| 133 | 137 | ||
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 10cb2d065..a2770cc6e 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp | |||
| @@ -360,7 +360,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 360 | 360 | ||
| 361 | if (abs) { | 361 | if (abs) { |
| 362 | // LUT index is in the range of (0.0, 1.0) | 362 | // LUT index is in the range of (0.0, 1.0) |
| 363 | index = config.light_src[light_num].two_sided_diffuse ? "abs(" + index + ")" : "max(" + index + ", 0.f)"; | 363 | index = config.lighting.light[light_num].two_sided_diffuse ? "abs(" + index + ")" : "max(" + index + ", 0.f)"; |
| 364 | return "clamp(" + index + ", 0.0, FLOAT_255)"; | 364 | return "clamp(" + index + ", 0.0, FLOAT_255)"; |
| 365 | } else { | 365 | } else { |
| 366 | // LUT index is in the range of (-1.0, 1.0) | 366 | // LUT index is in the range of (-1.0, 1.0) |
| @@ -378,10 +378,9 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 378 | }; | 378 | }; |
| 379 | 379 | ||
| 380 | // Write the code to emulate each enabled light | 380 | // Write the code to emulate each enabled light |
| 381 | for (unsigned light_index = 0; light_index < config.num_lights; ++light_index) { | 381 | for (unsigned light_index = 0; light_index < config.lighting.src_num; ++light_index) { |
| 382 | unsigned num = config.light_src[light_index].num; | 382 | const auto& light_config = config.lighting.light[light_index]; |
| 383 | const auto& light_config = config.light_src[light_index]; | 383 | std::string light_src = "light_src[" + std::to_string(light_config.num) + "]"; |
| 384 | std::string light_src = "light_src[" + std::to_string(num) + "]"; | ||
| 385 | 384 | ||
| 386 | // Compute light vector (directional or positional) | 385 | // Compute light vector (directional or positional) |
| 387 | if (light_config.directional) | 386 | if (light_config.directional) |
| @@ -394,12 +393,12 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 394 | 393 | ||
| 395 | // If enabled, compute distance attenuation value | 394 | // If enabled, compute distance attenuation value |
| 396 | std::string dist_atten = "1.0"; | 395 | std::string dist_atten = "1.0"; |
| 397 | if (light_config.dist_atten_enabled) { | 396 | if (light_config.dist_atten_enable) { |
| 398 | std::string scale = std::to_string(light_config.dist_atten_scale); | 397 | std::string scale = std::to_string(light_config.dist_atten_scale); |
| 399 | std::string bias = std::to_string(light_config.dist_atten_bias); | 398 | std::string bias = std::to_string(light_config.dist_atten_bias); |
| 400 | std::string lut_index = "(" + scale + " * length(-view - " + light_src + ".position) + " + bias + ")"; | 399 | std::string lut_index = "(" + scale + " * length(-view - " + light_src + ".position) + " + bias + ")"; |
| 401 | lut_index = "((clamp(" + lut_index + ", 0.0, FLOAT_255)))"; | 400 | lut_index = "((clamp(" + lut_index + ", 0.0, FLOAT_255)))"; |
| 402 | const unsigned lut_num = ((unsigned)Regs::LightingSampler::DistanceAttenuation + num); | 401 | const unsigned lut_num = ((unsigned)Regs::LightingSampler::DistanceAttenuation + light_config.num); |
| 403 | dist_atten = GetLutValue((Regs::LightingSampler)lut_num, lut_index); | 402 | dist_atten = GetLutValue((Regs::LightingSampler)lut_num, lut_index); |
| 404 | } | 403 | } |
| 405 | 404 | ||
| @@ -407,11 +406,14 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 407 | out += "diffuse_sum += ((" + light_src + ".diffuse * " + dot_product + ") + " + light_src + ".ambient) * " + dist_atten + ";\n"; | 406 | out += "diffuse_sum += ((" + light_src + ".diffuse * " + dot_product + ") + " + light_src + ".ambient) * " + dist_atten + ";\n"; |
| 408 | 407 | ||
| 409 | // If enabled, clamp specular component if lighting result is negative | 408 | // If enabled, clamp specular component if lighting result is negative |
| 410 | std::string clamp_highlights = config.clamp_highlights ? "(dot(light_vector, normal) <= 0.0 ? 0.0 : 1.0)" : "1.0"; | 409 | std::string clamp_highlights = config.lighting.clamp_highlights ? "(dot(light_vector, normal) <= 0.0 ? 0.0 : 1.0)" : "1.0"; |
| 411 | 410 | ||
| 412 | // Lookup specular distribution 0 LUT value | 411 | // Lookup specular "distribution 0" LUT value |
| 413 | std::string d0_lut_index = GetLutIndex(num, config.lighting_lut.d0_type, config.lighting_lut.d0_abs); | 412 | std::string d0_lut_value = "1.0"; |
| 414 | std::string d0_lut_value = GetLutValue(Regs::LightingSampler::Distribution0, d0_lut_index); | 413 | if (config.lighting.lut_d0.enable) { |
| 414 | std::string d0_lut_index = GetLutIndex(light_config.num, config.lighting.lut_d0.type, config.lighting.lut_d0.abs_input); | ||
| 415 | d0_lut_value = GetLutValue(Regs::LightingSampler::Distribution0, d0_lut_index); | ||
| 416 | } | ||
| 415 | 417 | ||
| 416 | // Compute secondary fragment color (specular lighting) function | 418 | // Compute secondary fragment color (specular lighting) function |
| 417 | out += "specular_sum += " + clamp_highlights + " * " + d0_lut_value + " * " + light_src + ".specular_0 * " + dist_atten + ";\n"; | 419 | out += "specular_sum += " + clamp_highlights + " * " + d0_lut_value + " * " + light_src + ".specular_0 * " + dist_atten + ";\n"; |
| @@ -463,15 +465,15 @@ vec4 primary_fragment_color = vec4(0.0); | |||
| 463 | vec4 secondary_fragment_color = vec4(0.0); | 465 | vec4 secondary_fragment_color = vec4(0.0); |
| 464 | )"; | 466 | )"; |
| 465 | 467 | ||
| 466 | if (config.lighting_enabled) | ||
| 467 | WriteLighting(out, config); | ||
| 468 | |||
| 469 | // Do not do any sort of processing if it's obvious we're not going to pass the alpha test | 468 | // Do not do any sort of processing if it's obvious we're not going to pass the alpha test |
| 470 | if (config.alpha_test_func == Regs::CompareFunc::Never) { | 469 | if (config.alpha_test_func == Regs::CompareFunc::Never) { |
| 471 | out += "discard; }"; | 470 | out += "discard; }"; |
| 472 | return out; | 471 | return out; |
| 473 | } | 472 | } |
| 474 | 473 | ||
| 474 | if (config.lighting.enable) | ||
| 475 | WriteLighting(out, config); | ||
| 476 | |||
| 475 | out += "vec4 combiner_buffer = vec4(0.0);\n"; | 477 | out += "vec4 combiner_buffer = vec4(0.0);\n"; |
| 476 | out += "vec4 next_combiner_buffer = tev_combiner_buffer_color;\n"; | 478 | out += "vec4 next_combiner_buffer = tev_combiner_buffer_color;\n"; |
| 477 | out += "vec4 last_tex_env_out = vec4(0.0);\n"; | 479 | out += "vec4 last_tex_env_out = vec4(0.0);\n"; |