summaryrefslogtreecommitdiff
path: root/src/video_core/swrasterizer/lighting.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2017-08-30 21:07:30 -0400
committerGravatar GitHub2017-08-30 21:07:30 -0400
commitf0e461bf6f9d38c35c581e75731ac80fca3f3172 (patch)
tree0a54a98595c313afd9002ed9964c94255a88abc4 /src/video_core/swrasterizer/lighting.cpp
parentMerge pull request #2899 from wwylele/touch-refactor (diff)
parentgl_rasterizer/lighting: more accurate CP formula (diff)
downloadyuzu-f0e461bf6f9d38c35c581e75731ac80fca3f3172.tar.gz
yuzu-f0e461bf6f9d38c35c581e75731ac80fca3f3172.tar.xz
yuzu-f0e461bf6f9d38c35c581e75731ac80fca3f3172.zip
Merge pull request #2891 from wwylele/sw-bump
SwRasterizer/Lighting: implement bump mapping
Diffstat (limited to 'src/video_core/swrasterizer/lighting.cpp')
-rw-r--r--src/video_core/swrasterizer/lighting.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/video_core/swrasterizer/lighting.cpp b/src/video_core/swrasterizer/lighting.cpp
index 39a3e396d..b38964530 100644
--- a/src/video_core/swrasterizer/lighting.cpp
+++ b/src/video_core/swrasterizer/lighting.cpp
@@ -22,18 +22,37 @@ 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
36 auto normal = Math::QuaternionRotate(normquat, surface_normal); 54 auto normal = Math::QuaternionRotate(normquat, surface_normal);
55 auto tangent = Math::QuaternionRotate(normquat, surface_tangent);
37 56
38 Math::Vec4<float> diffuse_sum = {0.0f, 0.0f, 0.0f, 1.0f}; 57 Math::Vec4<float> diffuse_sum = {0.0f, 0.0f, 0.0f, 1.0f};
39 Math::Vec4<float> specular_sum = {0.0f, 0.0f, 0.0f, 1.0f}; 58 Math::Vec4<float> specular_sum = {0.0f, 0.0f, 0.0f, 1.0f};
@@ -102,6 +121,16 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
102 result = Math::Dot(light_vector, spot_dir.Cast<float>() / 2047.0f); 121 result = Math::Dot(light_vector, spot_dir.Cast<float>() / 2047.0f);
103 break; 122 break;
104 } 123 }
124 case LightingRegs::LightingLutInput::CP:
125 if (lighting.config0.config == LightingRegs::LightingConfig::Config7) {
126 const Math::Vec3<float> norm_half_vector = half_vector.Normalized();
127 const Math::Vec3<float> half_vector_proj =
128 norm_half_vector - normal * Math::Dot(normal, norm_half_vector);
129 result = Math::Dot(half_vector_proj, tangent);
130 } else {
131 result = 0.0f;
132 }
133 break;
105 default: 134 default:
106 LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %u\n", static_cast<u32>(input)); 135 LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %u\n", static_cast<u32>(input));
107 UNIMPLEMENTED(); 136 UNIMPLEMENTED();