summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar wwylele2017-08-18 15:04:56 +0300
committerGravatar wwylele2017-08-22 09:34:44 +0300
commit3e478ca13110639a67ad95880aae5d7d13e096b7 (patch)
tree6d6c4bbada2738e20ff7ba3d895443214fecffca /src
parentMerge pull request #2872 from wwylele/sw-geo-factor (diff)
downloadyuzu-3e478ca13110639a67ad95880aae5d7d13e096b7.tar.gz
yuzu-3e478ca13110639a67ad95880aae5d7d13e096b7.tar.xz
yuzu-3e478ca13110639a67ad95880aae5d7d13e096b7.zip
SwRasterizer/Lighting: implement bump mapping
Diffstat (limited to 'src')
-rw-r--r--src/video_core/swrasterizer/lighting.cpp28
-rw-r--r--src/video_core/swrasterizer/lighting.h3
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp4
3 files changed, 27 insertions, 8 deletions
diff --git a/src/video_core/swrasterizer/lighting.cpp b/src/video_core/swrasterizer/lighting.cpp
index 39a3e396d..4f16bac07 100644
--- a/src/video_core/swrasterizer/lighting.cpp
+++ b/src/video_core/swrasterizer/lighting.cpp
@@ -22,14 +22,32 @@ static float LookupLightingLut(const Pica::State::Lighting& lighting, size_t lut
22 22
23std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors( 23std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
24 const Pica::LightingRegs& lighting, const Pica::State::Lighting& lighting_state, 24 const Pica::LightingRegs& lighting, const Pica::State::Lighting& lighting_state,
25 const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view) { 25 const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view,
26 const Math::Vec4<u8> (&texture_color)[4]) {
26 27
27 // TODO(Subv): Bump mapping 28 Math::Vec3<float> surface_normal;
28 Math::Vec3<float> surface_normal = {0.0f, 0.0f, 1.0f}; 29 Math::Vec3<float> surface_tangent;
29 30
30 if (lighting.config0.bump_mode != LightingRegs::LightingBumpMode::None) { 31 if (lighting.config0.bump_mode != LightingRegs::LightingBumpMode::None) {
31 LOG_CRITICAL(HW_GPU, "unimplemented bump mapping"); 32 Math::Vec3<float> perturbation =
32 UNIMPLEMENTED(); 33 texture_color[lighting.config0.bump_selector].xyz().Cast<float>() / 127.5f -
34 Math::MakeVec(1.0f, 1.0f, 1.0f);
35 if (lighting.config0.bump_mode == LightingRegs::LightingBumpMode::NormalMap) {
36 if (!lighting.config0.disable_bump_renorm) {
37 const float z_square = 1 - perturbation.xy().Length2();
38 perturbation.z = std::sqrt(std::max(z_square, 0.0f));
39 }
40 surface_normal = perturbation;
41 surface_tangent = Math::MakeVec(1.0f, 0.0f, 0.0f);
42 } else if (lighting.config0.bump_mode == LightingRegs::LightingBumpMode::TangentMap) {
43 surface_normal = Math::MakeVec(0.0f, 0.0f, 1.0f);
44 surface_tangent = perturbation;
45 } else {
46 LOG_ERROR(HW_GPU, "Unknown bump mode %u", lighting.config0.bump_mode.Value());
47 }
48 } else {
49 surface_normal = Math::MakeVec(0.0f, 0.0f, 1.0f);
50 surface_tangent = Math::MakeVec(1.0f, 0.0f, 0.0f);
33 } 51 }
34 52
35 // Use the normalized the quaternion when performing the rotation 53 // Use the normalized the quaternion when performing the rotation
diff --git a/src/video_core/swrasterizer/lighting.h b/src/video_core/swrasterizer/lighting.h
index 438dca926..d807a3d94 100644
--- a/src/video_core/swrasterizer/lighting.h
+++ b/src/video_core/swrasterizer/lighting.h
@@ -13,6 +13,7 @@ namespace Pica {
13 13
14std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors( 14std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
15 const Pica::LightingRegs& lighting, const Pica::State::Lighting& lighting_state, 15 const Pica::LightingRegs& lighting, const Pica::State::Lighting& lighting_state,
16 const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view); 16 const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view,
17 const Math::Vec4<u8> (&texture_color)[4]);
17 18
18} // namespace Pica 19} // namespace Pica
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index fdc1df199..862135614 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -437,8 +437,8 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
437 GetInterpolatedAttribute(v0.view.y, v1.view.y, v2.view.y).ToFloat32(), 437 GetInterpolatedAttribute(v0.view.y, v1.view.y, v2.view.y).ToFloat32(),
438 GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32(), 438 GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32(),
439 }; 439 };
440 std::tie(primary_fragment_color, secondary_fragment_color) = 440 std::tie(primary_fragment_color, secondary_fragment_color) = ComputeFragmentsColors(
441 ComputeFragmentsColors(g_state.regs.lighting, g_state.lighting, normquat, view); 441 g_state.regs.lighting, g_state.lighting, normquat, view, texture_color);
442 } 442 }
443 443
444 for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size(); 444 for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size();