diff options
| author | 2017-08-20 17:49:42 -0700 | |
|---|---|---|
| committer | 2017-08-20 17:49:42 -0700 | |
| commit | 46d1ca768d9ee2856b663ee68c8d7fdd7b160a7e (patch) | |
| tree | ca2f06ff9cdc0e1debf2861b729a9b4418e5b9c2 /src | |
| parent | Merge branch 'update-soundtouch' (PR #2885) (diff) | |
| parent | SwRasterizer/Lighting: implement geometric factor (diff) | |
| download | yuzu-46d1ca768d9ee2856b663ee68c8d7fdd7b160a7e.tar.gz yuzu-46d1ca768d9ee2856b663ee68c8d7fdd7b160a7e.tar.xz yuzu-46d1ca768d9ee2856b663ee68c8d7fdd7b160a7e.zip | |
Merge pull request #2872 from wwylele/sw-geo-factor
SwRasterizer/Lighting: implement geometric factor
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/swrasterizer/lighting.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/video_core/swrasterizer/lighting.cpp b/src/video_core/swrasterizer/lighting.cpp index ffd35792a..39a3e396d 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: |
| @@ -240,6 +241,17 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors( | |||
| 240 | else | 241 | else |
| 241 | dot_product = std::max(dot_product, 0.0f); | 242 | dot_product = std::max(dot_product, 0.0f); |
| 242 | 243 | ||
| 244 | if (light_config.config.geometric_factor_0 || light_config.config.geometric_factor_1) { | ||
| 245 | float geo_factor = half_vector.Length2(); | ||
| 246 | geo_factor = geo_factor == 0.0f ? 0.0f : std::min(dot_product / geo_factor, 1.0f); | ||
| 247 | if (light_config.config.geometric_factor_0) { | ||
| 248 | specular_0 *= geo_factor; | ||
| 249 | } | ||
| 250 | if (light_config.config.geometric_factor_1) { | ||
| 251 | specular_1 *= geo_factor; | ||
| 252 | } | ||
| 253 | } | ||
| 254 | |||
| 243 | auto diffuse = | 255 | auto diffuse = |
| 244 | light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f(); | 256 | light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f(); |
| 245 | diffuse_sum += Math::MakeVec(diffuse * dist_atten * spot_atten, 0.0f); | 257 | diffuse_sum += Math::MakeVec(diffuse * dist_atten * spot_atten, 0.0f); |