summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar wwylele2017-08-11 01:13:55 +0300
committerGravatar wwylele2017-08-11 01:18:43 +0300
commit14ee32c46a6dc97c1c6a0597e72e5284bf4e86e6 (patch)
treeca4559ee6f99350b062581aa299a52722f397efb
parentMerge pull request #2863 from wwylele/pad-state-zero (diff)
downloadyuzu-14ee32c46a6dc97c1c6a0597e72e5284bf4e86e6.tar.gz
yuzu-14ee32c46a6dc97c1c6a0597e72e5284bf4e86e6.tar.xz
yuzu-14ee32c46a6dc97c1c6a0597e72e5284bf4e86e6.zip
SwRasterizer/Lighting: implement geometric factor
Diffstat (limited to '')
-rw-r--r--src/video_core/swrasterizer/lighting.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/video_core/swrasterizer/lighting.cpp b/src/video_core/swrasterizer/lighting.cpp
index d61e6d572..91683afa4 100644
--- a/src/video_core/swrasterizer/lighting.cpp
+++ b/src/video_core/swrasterizer/lighting.cpp
@@ -55,6 +55,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
55 55
56 light_vector.Normalize(); 56 light_vector.Normalize();
57 57
58 Math::Vec3<float> norm_view = view.Normalized();
59 Math::Vec3<float> half_vector = norm_view + light_vector;
60
58 float dist_atten = 1.0f; 61 float dist_atten = 1.0f;
59 if (!lighting.IsDistAttenDisabled(num)) { 62 if (!lighting.IsDistAttenDisabled(num)) {
60 auto distance = (-view - position).Length(); 63 auto distance = (-view - position).Length();
@@ -74,17 +77,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
74 auto GetLutValue = [&](LightingRegs::LightingLutInput input, bool abs, 77 auto GetLutValue = [&](LightingRegs::LightingLutInput input, bool abs,
75 LightingRegs::LightingScale scale_enum, 78 LightingRegs::LightingScale scale_enum,
76 LightingRegs::LightingSampler sampler) { 79 LightingRegs::LightingSampler sampler) {
77 Math::Vec3<float> norm_view = view.Normalized();
78 Math::Vec3<float> half_angle = (norm_view + light_vector).Normalized();
79 float result = 0.0f; 80 float result = 0.0f;
80 81
81 switch (input) { 82 switch (input) {
82 case LightingRegs::LightingLutInput::NH: 83 case LightingRegs::LightingLutInput::NH:
83 result = Math::Dot(normal, half_angle); 84 result = Math::Dot(normal, half_vector.Normalized());
84 break; 85 break;
85 86
86 case LightingRegs::LightingLutInput::VH: 87 case LightingRegs::LightingLutInput::VH:
87 result = Math::Dot(norm_view, half_angle); 88 result = Math::Dot(norm_view, half_vector.Normalized());
88 break; 89 break;
89 90
90 case LightingRegs::LightingLutInput::NV: 91 case LightingRegs::LightingLutInput::NV:
@@ -224,6 +225,17 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
224 else 225 else
225 dot_product = std::max(dot_product, 0.0f); 226 dot_product = std::max(dot_product, 0.0f);
226 227
228 if (light_config.config.geometric_factor_0 || light_config.config.geometric_factor_1) {
229 float geo_factor = half_vector.Length2();
230 geo_factor = geo_factor == 0.0f ? 0.0f : std::min(dot_product / geo_factor, 1.0f);
231 if (light_config.config.geometric_factor_0) {
232 specular_0 *= geo_factor;
233 }
234 if (light_config.config.geometric_factor_1) {
235 specular_1 *= geo_factor;
236 }
237 }
238
227 auto diffuse = 239 auto diffuse =
228 light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f(); 240 light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f();
229 diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f); 241 diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f);