summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar wwylele2017-06-08 18:48:12 +0300
committerGravatar wwylele2017-06-11 21:30:53 +0300
commit972548e3eec73b16cb804ecf67a21b48bc09d299 (patch)
treec669c516b23744f3efaf68b20c539ebe5f7d980a /src
parentgl_rasterizer/lighting: implement lut input 5 (CP) (diff)
downloadyuzu-972548e3eec73b16cb804ecf67a21b48bc09d299.tar.gz
yuzu-972548e3eec73b16cb804ecf67a21b48bc09d299.tar.xz
yuzu-972548e3eec73b16cb804ecf67a21b48bc09d299.zip
gl_rasterizer/lighting: Implement tangent mapping
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 89977a62b..14be1201f 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -520,12 +520,12 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
520 "vec3 refl_value = vec3(0.0);\n" 520 "vec3 refl_value = vec3(0.0);\n"
521 "vec3 spot_dir = vec3(0.0);\n;"; 521 "vec3 spot_dir = vec3(0.0);\n;";
522 522
523 // Compute fragment normals 523 // Compute fragment normals and tangents
524 const std::string pertubation =
525 "2.0 * (" + SampleTexture(config, lighting.bump_selector) + ").rgb - 1.0";
524 if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) { 526 if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) {
525 // Bump mapping is enabled using a normal map, read perturbation vector from the selected 527 // Bump mapping is enabled using a normal map
526 // texture 528 out += "vec3 surface_normal = " + pertubation + ";\n";
527 out += "vec3 surface_normal = 2.0 * (" + SampleTexture(config, lighting.bump_selector) +
528 ").rgb - 1.0;\n";
529 529
530 // Recompute Z-component of perturbation if 'renorm' is enabled, this provides a higher 530 // Recompute Z-component of perturbation if 'renorm' is enabled, this provides a higher
531 // precision result 531 // precision result
@@ -539,8 +539,13 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
539 out += "vec3 surface_tangent = vec3(1.0, 0.0, 0.0);\n"; 539 out += "vec3 surface_tangent = vec3(1.0, 0.0, 0.0);\n";
540 } else if (lighting.bump_mode == LightingRegs::LightingBumpMode::TangentMap) { 540 } else if (lighting.bump_mode == LightingRegs::LightingBumpMode::TangentMap) {
541 // Bump mapping is enabled using a tangent map 541 // Bump mapping is enabled using a tangent map
542 LOG_CRITICAL(HW_GPU, "unimplemented bump mapping mode (tangent mapping)"); 542 out += "vec3 surface_tangent = " + pertubation + ";\n";
543 UNIMPLEMENTED(); 543 // Mathematically, recomputing Z-component of the tangent vector won't affect the relevant
544 // computation below, which is also confirmed on 3DS. So we don't bother recomputing here
545 // even if 'renorm' is enabled.
546
547 // The normal vector is not perturbed by the tangent map and is just a unit vector.
548 out += "vec3 surface_normal = vec3(0.0, 0.0, 1.0);\n";
544 } else { 549 } else {
545 // No bump mapping - surface local normal and tangent are just unit vectors 550 // No bump mapping - surface local normal and tangent are just unit vectors
546 out += "vec3 surface_normal = vec3(0.0, 0.0, 1.0);\n"; 551 out += "vec3 surface_normal = vec3(0.0, 0.0, 1.0);\n";