diff options
| author | 2017-08-19 20:10:24 -0600 | |
|---|---|---|
| committer | 2017-08-19 20:10:24 -0600 | |
| commit | 8afa81ac1bbb0ffb67faf87e9ee696145a40bb99 (patch) | |
| tree | 6df910795bd79debdd06943e5d6bd4a4a9e3fd78 | |
| parent | Added missing parts in libnetwork (#2838) (diff) | |
| parent | SwRasterizer/Lighting: implement spot light (diff) | |
| download | yuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.tar.gz yuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.tar.xz yuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.zip | |
Merge pull request #2871 from wwylele/sw-spotlight
SwRasterizer/Lighting: implement spot light
Diffstat (limited to '')
| -rw-r--r-- | src/video_core/swrasterizer/lighting.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/video_core/swrasterizer/lighting.cpp b/src/video_core/swrasterizer/lighting.cpp index d61e6d572..ffd35792a 100644 --- a/src/video_core/swrasterizer/lighting.cpp +++ b/src/video_core/swrasterizer/lighting.cpp | |||
| @@ -95,6 +95,12 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors( | |||
| 95 | result = Math::Dot(light_vector, normal); | 95 | result = Math::Dot(light_vector, normal); |
| 96 | break; | 96 | break; |
| 97 | 97 | ||
| 98 | case LightingRegs::LightingLutInput::SP: { | ||
| 99 | Math::Vec3<s32> spot_dir{light_config.spot_x.Value(), light_config.spot_y.Value(), | ||
| 100 | light_config.spot_z.Value()}; | ||
| 101 | result = Math::Dot(light_vector, spot_dir.Cast<float>() / 2047.0f); | ||
| 102 | break; | ||
| 103 | } | ||
| 98 | default: | 104 | default: |
| 99 | LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %u\n", static_cast<u32>(input)); | 105 | LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %u\n", static_cast<u32>(input)); |
| 100 | UNIMPLEMENTED(); | 106 | UNIMPLEMENTED(); |
| @@ -125,6 +131,16 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors( | |||
| 125 | LookupLightingLut(lighting_state, static_cast<size_t>(sampler), index, delta); | 131 | LookupLightingLut(lighting_state, static_cast<size_t>(sampler), index, delta); |
| 126 | }; | 132 | }; |
| 127 | 133 | ||
| 134 | // If enabled, compute spot light attenuation value | ||
| 135 | float spot_atten = 1.0f; | ||
| 136 | if (!lighting.IsSpotAttenDisabled(num) && | ||
| 137 | LightingRegs::IsLightingSamplerSupported( | ||
| 138 | lighting.config0.config, LightingRegs::LightingSampler::SpotlightAttenuation)) { | ||
| 139 | auto lut = LightingRegs::SpotlightAttenuationSampler(num); | ||
| 140 | spot_atten = GetLutValue(lighting.lut_input.sp, lighting.abs_lut_input.disable_sp == 0, | ||
| 141 | lighting.lut_scale.sp, lut); | ||
| 142 | } | ||
| 143 | |||
| 128 | // Specular 0 component | 144 | // Specular 0 component |
| 129 | float d0_lut_value = 1.0f; | 145 | float d0_lut_value = 1.0f; |
| 130 | if (lighting.config1.disable_lut_d0 == 0 && | 146 | if (lighting.config1.disable_lut_d0 == 0 && |
| @@ -226,10 +242,10 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors( | |||
| 226 | 242 | ||
| 227 | auto diffuse = | 243 | auto diffuse = |
| 228 | light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f(); | 244 | light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f(); |
| 229 | diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f); | 245 | diffuse_sum += Math::MakeVec(diffuse * dist_atten * spot_atten, 0.0f); |
| 230 | 246 | ||
| 231 | specular_sum += | 247 | specular_sum += Math::MakeVec( |
| 232 | Math::MakeVec((specular_0 + specular_1) * clamp_highlights * dist_atten, 0.0f); | 248 | (specular_0 + specular_1) * clamp_highlights * dist_atten * spot_atten, 0.0f); |
| 233 | } | 249 | } |
| 234 | 250 | ||
| 235 | diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f); | 251 | diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f); |