summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Rowe <jroweboy@gmail.com>2017-08-20 04:10:24 +0200
committerGitHub <noreply@github.com>2017-08-20 04:10:24 +0200
commit8afa81ac1bbb0ffb67faf87e9ee696145a40bb99 (patch)
tree6df910795bd79debdd06943e5d6bd4a4a9e3fd78 /src
parentAdded missing parts in libnetwork (#2838) (diff)
parentSwRasterizer/Lighting: implement spot light (diff)
downloadyuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.tar
yuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.tar.gz
yuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.tar.bz2
yuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.tar.lz
yuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.tar.xz
yuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.tar.zst
yuzu-8afa81ac1bbb0ffb67faf87e9ee696145a40bb99.zip
Diffstat (limited to 'src')
-rw-r--r--src/video_core/swrasterizer/lighting.cpp22
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(
result = Math::Dot(light_vector, normal);
break;
+ case LightingRegs::LightingLutInput::SP: {
+ Math::Vec3<s32> spot_dir{light_config.spot_x.Value(), light_config.spot_y.Value(),
+ light_config.spot_z.Value()};
+ result = Math::Dot(light_vector, spot_dir.Cast<float>() / 2047.0f);
+ break;
+ }
default:
LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %u\n", static_cast<u32>(input));
UNIMPLEMENTED();
@@ -125,6 +131,16 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
LookupLightingLut(lighting_state, static_cast<size_t>(sampler), index, delta);
};
+ // If enabled, compute spot light attenuation value
+ float spot_atten = 1.0f;
+ if (!lighting.IsSpotAttenDisabled(num) &&
+ LightingRegs::IsLightingSamplerSupported(
+ lighting.config0.config, LightingRegs::LightingSampler::SpotlightAttenuation)) {
+ auto lut = LightingRegs::SpotlightAttenuationSampler(num);
+ spot_atten = GetLutValue(lighting.lut_input.sp, lighting.abs_lut_input.disable_sp == 0,
+ lighting.lut_scale.sp, lut);
+ }
+
// Specular 0 component
float d0_lut_value = 1.0f;
if (lighting.config1.disable_lut_d0 == 0 &&
@@ -226,10 +242,10 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
auto diffuse =
light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f();
- diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f);
+ diffuse_sum += Math::MakeVec(diffuse * dist_atten * spot_atten, 0.0f);
- specular_sum +=
- Math::MakeVec((specular_0 + specular_1) * clamp_highlights * dist_atten, 0.0f);
+ specular_sum += Math::MakeVec(
+ (specular_0 + specular_1) * clamp_highlights * dist_atten * spot_atten, 0.0f);
}
diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f);