summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar wwylele2017-05-25 21:13:33 +0300
committerGravatar wwylele2017-06-11 21:30:53 +0300
commit40b7d0bf3f7bf4f29c1866231a79e0a751e30274 (patch)
tree7f5eb14962979041c168f3c00a88e27d3f98c2d6 /src
parentMerge pull request #2727 from wwylele/spot-light (diff)
downloadyuzu-40b7d0bf3f7bf4f29c1866231a79e0a751e30274.tar.gz
yuzu-40b7d0bf3f7bf4f29c1866231a79e0a751e30274.tar.xz
yuzu-40b7d0bf3f7bf4f29c1866231a79e0a751e30274.zip
gl_rasterizer/lighting: implement lut input 5 (CP)
Diffstat (limited to 'src')
-rw-r--r--src/video_core/regs_lighting.h2
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp27
2 files changed, 26 insertions, 3 deletions
diff --git a/src/video_core/regs_lighting.h b/src/video_core/regs_lighting.h
index fbfebc0a7..f383b8b4f 100644
--- a/src/video_core/regs_lighting.h
+++ b/src/video_core/regs_lighting.h
@@ -84,7 +84,7 @@ struct LightingRegs {
84 NV = 2, // Cosine of the angle between the normal and the view vector 84 NV = 2, // Cosine of the angle between the normal and the view vector
85 LN = 3, // Cosine of the angle between the light and the normal vectors 85 LN = 3, // Cosine of the angle between the light and the normal vectors
86 SP = 4, // Cosine of the angle between the light and the inverse spotlight vectors 86 SP = 4, // Cosine of the angle between the light and the inverse spotlight vectors
87 CP = 5, // TODO: document and implement 87 CP = 5, // Cosine of the angle between the tangent and projection of half-angle vectors
88 }; 88 };
89 89
90 enum class LightingBumpMode : u32 { 90 enum class LightingBumpMode : u32 {
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index db53710aa..89977a62b 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -534,18 +534,24 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
534 "(1.0 - (surface_normal.x*surface_normal.x + surface_normal.y*surface_normal.y))"; 534 "(1.0 - (surface_normal.x*surface_normal.x + surface_normal.y*surface_normal.y))";
535 out += "surface_normal.z = sqrt(max(" + val + ", 0.0));\n"; 535 out += "surface_normal.z = sqrt(max(" + val + ", 0.0));\n";
536 } 536 }
537
538 // The tangent vector is not perturbed by the normal map and is just a unit vector.
539 out += "vec3 surface_tangent = vec3(1.0, 0.0, 0.0);\n";
537 } else if (lighting.bump_mode == LightingRegs::LightingBumpMode::TangentMap) { 540 } else if (lighting.bump_mode == LightingRegs::LightingBumpMode::TangentMap) {
538 // Bump mapping is enabled using a tangent map 541 // Bump mapping is enabled using a tangent map
539 LOG_CRITICAL(HW_GPU, "unimplemented bump mapping mode (tangent mapping)"); 542 LOG_CRITICAL(HW_GPU, "unimplemented bump mapping mode (tangent mapping)");
540 UNIMPLEMENTED(); 543 UNIMPLEMENTED();
541 } else { 544 } else {
542 // No bump mapping - surface local normal is just a unit normal 545 // No bump mapping - surface local normal and tangent are just unit vectors
543 out += "vec3 surface_normal = vec3(0.0, 0.0, 1.0);\n"; 546 out += "vec3 surface_normal = vec3(0.0, 0.0, 1.0);\n";
547 out += "vec3 surface_tangent = vec3(1.0, 0.0, 0.0);\n";
544 } 548 }
545 549
546 // Rotate the surface-local normal by the interpolated normal quaternion to convert it to 550 // Rotate the surface-local normal by the interpolated normal quaternion to convert it to
547 // eyespace. 551 // eyespace.
548 out += "vec3 normal = quaternion_rotate(normalize(normquat), surface_normal);\n"; 552 out += "vec4 normalized_normquat = normalize(normquat);\n";
553 out += "vec3 normal = quaternion_rotate(normalized_normquat, surface_normal);\n";
554 out += "vec3 tangent = quaternion_rotate(normalized_normquat, surface_tangent);\n";
549 555
550 // Gets the index into the specified lookup table for specular lighting 556 // Gets the index into the specified lookup table for specular lighting
551 auto GetLutIndex = [&lighting](unsigned light_num, LightingRegs::LightingLutInput input, 557 auto GetLutIndex = [&lighting](unsigned light_num, LightingRegs::LightingLutInput input,
@@ -573,6 +579,23 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
573 index = std::string("dot(light_vector, spot_dir)"); 579 index = std::string("dot(light_vector, spot_dir)");
574 break; 580 break;
575 581
582 case LightingRegs::LightingLutInput::CP:
583 // CP input is only available with configuration 7
584 if (lighting.config == LightingRegs::LightingConfig::Config7) {
585 // Note: even if the normal vector is modified by normal map, which is not the
586 // normal of the tangent plane anymore, the half angle vector is still projected
587 // using the modified normal vector.
588 std::string half_angle_proj = half_angle +
589 " - normal / dot(normal, normal) * dot(normal, " +
590 half_angle + ")";
591 // Note: the half angle vector projection is confirmed not normalized before the dot
592 // product. The result is in fact not cos(phi) as the name suggested.
593 index = "dot(" + half_angle_proj + ", tangent)";
594 } else {
595 index = "0.0";
596 }
597 break;
598
576 default: 599 default:
577 LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %d\n", (int)input); 600 LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %d\n", (int)input);
578 UNIMPLEMENTED(); 601 UNIMPLEMENTED();