diff options
| author | 2017-05-26 16:23:33 +0300 | |
|---|---|---|
| committer | 2017-05-30 10:54:58 +0300 | |
| commit | 10906dceec42b1975a7f10abd199678dce692838 (patch) | |
| tree | c455260c78a7e4f2aa695eb15d506cff02aa54d3 /src | |
| parent | gl_rasterizer: sync spot light status (diff) | |
| download | yuzu-10906dceec42b1975a7f10abd199678dce692838.tar.gz yuzu-10906dceec42b1975a7f10abd199678dce692838.tar.xz yuzu-10906dceec42b1975a7f10abd199678dce692838.zip | |
gl_rasterizer: implement spot light
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index fe23be340..3eeb47d33 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp | |||
| @@ -508,7 +508,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 508 | out += "vec4 diffuse_sum = vec4(0.0, 0.0, 0.0, 1.0);\n" | 508 | out += "vec4 diffuse_sum = vec4(0.0, 0.0, 0.0, 1.0);\n" |
| 509 | "vec4 specular_sum = vec4(0.0, 0.0, 0.0, 1.0);\n" | 509 | "vec4 specular_sum = vec4(0.0, 0.0, 0.0, 1.0);\n" |
| 510 | "vec3 light_vector = vec3(0.0);\n" | 510 | "vec3 light_vector = vec3(0.0);\n" |
| 511 | "vec3 refl_value = vec3(0.0);\n"; | 511 | "vec3 refl_value = vec3(0.0);\n" |
| 512 | "vec3 spot_dir = vec3(0.0);\n;"; | ||
| 512 | 513 | ||
| 513 | // Compute fragment normals | 514 | // Compute fragment normals |
| 514 | if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) { | 515 | if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) { |
| @@ -569,6 +570,10 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 569 | index = std::string("dot(light_vector, normal)"); | 570 | index = std::string("dot(light_vector, normal)"); |
| 570 | break; | 571 | break; |
| 571 | 572 | ||
| 573 | case LightingRegs::LightingLutInput::SP: | ||
| 574 | index = std::string("dot(light_vector, spot_dir)"); | ||
| 575 | break; | ||
| 576 | |||
| 572 | default: | 577 | default: |
| 573 | LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %d\n", (int)input); | 578 | LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %d\n", (int)input); |
| 574 | UNIMPLEMENTED(); | 579 | UNIMPLEMENTED(); |
| @@ -605,21 +610,34 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 605 | else | 610 | else |
| 606 | out += "light_vector = normalize(" + light_src + ".position + view);\n"; | 611 | out += "light_vector = normalize(" + light_src + ".position + view);\n"; |
| 607 | 612 | ||
| 613 | out += "spot_dir = " + light_src + ".spot_direction;\n"; | ||
| 614 | |||
| 608 | // Compute dot product of light_vector and normal, adjust if lighting is one-sided or | 615 | // Compute dot product of light_vector and normal, adjust if lighting is one-sided or |
| 609 | // two-sided | 616 | // two-sided |
| 610 | std::string dot_product = light_config.two_sided_diffuse | 617 | std::string dot_product = light_config.two_sided_diffuse |
| 611 | ? "abs(dot(light_vector, normal))" | 618 | ? "abs(dot(light_vector, normal))" |
| 612 | : "max(dot(light_vector, normal), 0.0)"; | 619 | : "max(dot(light_vector, normal), 0.0)"; |
| 613 | 620 | ||
| 621 | // If enabled, compute spot light attenuation value | ||
| 622 | std::string spot_atten = "1.0"; | ||
| 623 | if (light_config.spot_atten_enable && | ||
| 624 | LightingRegs::IsLightingSamplerSupported( | ||
| 625 | lighting.config, LightingRegs::LightingSampler::SpotlightAttenuation)) { | ||
| 626 | std::string index = | ||
| 627 | GetLutIndex(light_config.num, lighting.lut_sp.type, lighting.lut_sp.abs_input); | ||
| 628 | auto sampler = LightingRegs::SpotlightAttenuationSampler(light_config.num); | ||
| 629 | spot_atten = "(" + std::to_string(lighting.lut_sp.scale) + " * " + | ||
| 630 | GetLutValue(sampler, index) + ")"; | ||
| 631 | } | ||
| 632 | |||
| 614 | // If enabled, compute distance attenuation value | 633 | // If enabled, compute distance attenuation value |
| 615 | std::string dist_atten = "1.0"; | 634 | std::string dist_atten = "1.0"; |
| 616 | if (light_config.dist_atten_enable) { | 635 | if (light_config.dist_atten_enable) { |
| 617 | std::string index = "(" + light_src + ".dist_atten_scale * length(-view - " + | 636 | std::string index = "(" + light_src + ".dist_atten_scale * length(-view - " + |
| 618 | light_src + ".position) + " + light_src + ".dist_atten_bias)"; | 637 | light_src + ".position) + " + light_src + ".dist_atten_bias)"; |
| 619 | index = "(OFFSET_256 + SCALE_256 * clamp(" + index + ", 0.0, 1.0))"; | 638 | index = "(OFFSET_256 + SCALE_256 * clamp(" + index + ", 0.0, 1.0))"; |
| 620 | const unsigned lut_num = | 639 | auto sampler = LightingRegs::DistanceAttenuationSampler(light_config.num); |
| 621 | ((unsigned)LightingRegs::LightingSampler::DistanceAttenuation + light_config.num); | 640 | dist_atten = GetLutValue(sampler, index); |
| 622 | dist_atten = GetLutValue((LightingRegs::LightingSampler)lut_num, index); | ||
| 623 | } | 641 | } |
| 624 | 642 | ||
| 625 | // If enabled, clamp specular component if lighting result is negative | 643 | // If enabled, clamp specular component if lighting result is negative |
| @@ -720,11 +738,11 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 720 | 738 | ||
| 721 | // Compute primary fragment color (diffuse lighting) function | 739 | // Compute primary fragment color (diffuse lighting) function |
| 722 | out += "diffuse_sum.rgb += ((" + light_src + ".diffuse * " + dot_product + ") + " + | 740 | out += "diffuse_sum.rgb += ((" + light_src + ".diffuse * " + dot_product + ") + " + |
| 723 | light_src + ".ambient) * " + dist_atten + ";\n"; | 741 | light_src + ".ambient) * " + dist_atten + " * " + spot_atten + ";\n"; |
| 724 | 742 | ||
| 725 | // Compute secondary fragment color (specular lighting) function | 743 | // Compute secondary fragment color (specular lighting) function |
| 726 | out += "specular_sum.rgb += (" + specular_0 + " + " + specular_1 + ") * " + | 744 | out += "specular_sum.rgb += (" + specular_0 + " + " + specular_1 + ") * " + |
| 727 | clamp_highlights + " * " + dist_atten + ";\n"; | 745 | clamp_highlights + " * " + dist_atten + " * " + spot_atten + ";\n"; |
| 728 | } | 746 | } |
| 729 | 747 | ||
| 730 | // Sum final lighting result | 748 | // Sum final lighting result |