summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 04e7cb0c4..540cbb9d0 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -521,6 +521,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
521 "vec3 light_vector = vec3(0.0);\n" 521 "vec3 light_vector = vec3(0.0);\n"
522 "vec3 refl_value = vec3(0.0);\n" 522 "vec3 refl_value = vec3(0.0);\n"
523 "vec3 spot_dir = vec3(0.0);\n" 523 "vec3 spot_dir = vec3(0.0);\n"
524 "vec3 half_vector = vec3(0.0);\n"
524 "float geo_factor = 1.0;\n"; 525 "float geo_factor = 1.0;\n";
525 526
526 // Compute fragment normals and tangents 527 // Compute fragment normals and tangents
@@ -564,15 +565,14 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
564 // Gets the index into the specified lookup table for specular lighting 565 // Gets the index into the specified lookup table for specular lighting
565 auto GetLutIndex = [&lighting](unsigned light_num, LightingRegs::LightingLutInput input, 566 auto GetLutIndex = [&lighting](unsigned light_num, LightingRegs::LightingLutInput input,
566 bool abs) { 567 bool abs) {
567 const std::string half_angle = "normalize(normalize(view) + light_vector)";
568 std::string index; 568 std::string index;
569 switch (input) { 569 switch (input) {
570 case LightingRegs::LightingLutInput::NH: 570 case LightingRegs::LightingLutInput::NH:
571 index = "dot(normal, " + half_angle + ")"; 571 index = "dot(normal, normalize(half_vector))";
572 break; 572 break;
573 573
574 case LightingRegs::LightingLutInput::VH: 574 case LightingRegs::LightingLutInput::VH:
575 index = std::string("dot(normalize(view), " + half_angle + ")"); 575 index = std::string("dot(normalize(view), normalize(half_vector))");
576 break; 576 break;
577 577
578 case LightingRegs::LightingLutInput::NV: 578 case LightingRegs::LightingLutInput::NV:
@@ -593,9 +593,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
593 // Note: even if the normal vector is modified by normal map, which is not the 593 // Note: even if the normal vector is modified by normal map, which is not the
594 // normal of the tangent plane anymore, the half angle vector is still projected 594 // normal of the tangent plane anymore, the half angle vector is still projected
595 // using the modified normal vector. 595 // using the modified normal vector.
596 std::string half_angle_proj = half_angle + 596 std::string half_angle_proj = "normalize(half_vector) - normal / dot(normal, "
597 " - normal / dot(normal, normal) * dot(normal, " + 597 "normal) * dot(normal, normalize(half_vector))";
598 half_angle + ")";
599 // Note: the half angle vector projection is confirmed not normalized before the dot 598 // Note: the half angle vector projection is confirmed not normalized before the dot
600 // product. The result is in fact not cos(phi) as the name suggested. 599 // product. The result is in fact not cos(phi) as the name suggested.
601 index = "dot(" + half_angle_proj + ", tangent)"; 600 index = "dot(" + half_angle_proj + ", tangent)";
@@ -641,6 +640,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
641 out += "light_vector = normalize(" + light_src + ".position + view);\n"; 640 out += "light_vector = normalize(" + light_src + ".position + view);\n";
642 641
643 out += "spot_dir = " + light_src + ".spot_direction;\n"; 642 out += "spot_dir = " + light_src + ".spot_direction;\n";
643 out += "half_vector = normalize(view) + light_vector;\n";
644 644
645 // Compute dot product of light_vector and normal, adjust if lighting is one-sided or 645 // Compute dot product of light_vector and normal, adjust if lighting is one-sided or
646 // two-sided 646 // two-sided
@@ -675,8 +675,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
675 lighting.clamp_highlights ? "(dot(light_vector, normal) <= 0.0 ? 0.0 : 1.0)" : "1.0"; 675 lighting.clamp_highlights ? "(dot(light_vector, normal) <= 0.0 ? 0.0 : 1.0)" : "1.0";
676 676
677 if (light_config.geometric_factor_0 || light_config.geometric_factor_1) { 677 if (light_config.geometric_factor_0 || light_config.geometric_factor_1) {
678 out += "geo_factor = 1 + dot(light_vector, normalize(view));\n" 678 out += "geo_factor = dot(half_vector, half_vector);\n"
679 "geo_factor = geo_factor == 0.0 ? 0.0 : min(0.5 * " + 679 "geo_factor = geo_factor == 0.0 ? 0.0 : min(" +
680 dot_product + " / geo_factor, 1.0);\n"; 680 dot_product + " / geo_factor, 1.0);\n";
681 } 681 }
682 682