summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2017-06-28 12:34:16 -0500
committerGravatar wwylele2017-07-11 19:39:15 +0300
commit7bc467e8725c6751eb44ea45ff2203af8692cda1 (patch)
treebcc21b0d48574dad3c8036905b3fe179f6e39640 /src
parentSwRasterizer/Lighting: Fixed a bug where the distance attenuation bias was be... (diff)
downloadyuzu-7bc467e8725c6751eb44ea45ff2203af8692cda1.tar.gz
yuzu-7bc467e8725c6751eb44ea45ff2203af8692cda1.tar.xz
yuzu-7bc467e8725c6751eb44ea45ff2203af8692cda1.zip
SwRasterizer/Lighting: Do not use global state in LookupLightingLut.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/pica_state.h2
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp33
2 files changed, 22 insertions, 13 deletions
diff --git a/src/video_core/pica_state.h b/src/video_core/pica_state.h
index 2d23d34e6..864a2c9e6 100644
--- a/src/video_core/pica_state.h
+++ b/src/video_core/pica_state.h
@@ -79,7 +79,7 @@ struct State {
79 std::array<ColorDifferenceEntry, 256> color_diff_table; 79 std::array<ColorDifferenceEntry, 256> color_diff_table;
80 } proctex; 80 } proctex;
81 81
82 struct { 82 struct Lighting {
83 union LutEntry { 83 union LutEntry {
84 // Used for raw access 84 // Used for raw access
85 u32 raw; 85 u32 raw;
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index 48ed8ccbf..b69f7b692 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -115,12 +115,15 @@ static std::tuple<float24, float24, PAddr> ConvertCubeCoord(float24 u, float24 v
115 return std::make_tuple(x / z * half + half, y / z * half + half, addr); 115 return std::make_tuple(x / z * half + half, y / z * half + half, addr);
116} 116}
117 117
118float LookupLightingLut(size_t lut_index, u8 index, float delta) { 118static float LookupLightingLut(const Pica::State::Lighting& lighting, size_t lut_index, u8 index,
119 ASSERT_MSG(lut_index < g_state.lighting.luts.size(), "Out of range lut"); 119 float delta) {
120 ASSERT_MSG(index < g_state.lighting.luts[0].size(), "Out of range index"); 120 ASSERT_MSG(lut_index < lighting.luts.size(), "Out of range lut");
121 ASSERT_MSG(index < lighting.luts[0].size(), "Out of range index");
121 122
122 float lut_value = g_state.lighting.luts[lut_index][index].ToFloat(); 123 const auto& lut = lighting.luts[lut_index][index];
123 float lut_diff = g_state.lighting.luts[lut_index][index].DiffToFloat(); 124
125 float lut_value = lut.ToFloat();
126 float lut_diff = lut.DiffToFloat();
124 127
125 return lut_value + lut_diff * delta; 128 return lut_value + lut_diff * delta;
126} 129}
@@ -184,7 +187,7 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
184 u8 lutindex = 187 u8 lutindex =
185 static_cast<u8>(MathUtil::Clamp(std::floor(sample_loc * 256.f), 0.0f, 255.0f)); 188 static_cast<u8>(MathUtil::Clamp(std::floor(sample_loc * 256.f), 0.0f, 255.0f));
186 float delta = sample_loc * 256 - lutindex; 189 float delta = sample_loc * 256 - lutindex;
187 dist_atten = LookupLightingLut(lut, lutindex, delta); 190 dist_atten = LookupLightingLut(g_state.lighting, lut, lutindex, delta);
188 } 191 }
189 192
190 float clamp_highlights = 1.0f; 193 float clamp_highlights = 1.0f;
@@ -260,7 +263,8 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
260 263
261 d0_lut_value = 264 d0_lut_value =
262 scale * 265 scale *
263 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution0), 266 LookupLightingLut(g_state.lighting,
267 static_cast<size_t>(LightingRegs::LightingSampler::Distribution0),
264 index, delta); 268 index, delta);
265 } 269 }
266 270
@@ -280,7 +284,8 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
280 284
281 refl_value.x = 285 refl_value.x =
282 scale * 286 scale *
283 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectRed), 287 LookupLightingLut(g_state.lighting,
288 static_cast<size_t>(LightingRegs::LightingSampler::ReflectRed),
284 index, delta); 289 index, delta);
285 } else { 290 } else {
286 refl_value.x = 1.0f; 291 refl_value.x = 1.0f;
@@ -300,7 +305,8 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
300 305
301 refl_value.y = 306 refl_value.y =
302 scale * 307 scale *
303 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectGreen), 308 LookupLightingLut(g_state.lighting,
309 static_cast<size_t>(LightingRegs::LightingSampler::ReflectGreen),
304 index, delta); 310 index, delta);
305 } else { 311 } else {
306 refl_value.y = refl_value.x; 312 refl_value.y = refl_value.x;
@@ -320,7 +326,8 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
320 326
321 refl_value.z = 327 refl_value.z =
322 scale * 328 scale *
323 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectBlue), 329 LookupLightingLut(g_state.lighting,
330 static_cast<size_t>(LightingRegs::LightingSampler::ReflectBlue),
324 index, delta); 331 index, delta);
325 } else { 332 } else {
326 refl_value.z = refl_value.x; 333 refl_value.z = refl_value.x;
@@ -341,7 +348,8 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
341 348
342 d1_lut_value = 349 d1_lut_value =
343 scale * 350 scale *
344 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution1), 351 LookupLightingLut(g_state.lighting,
352 static_cast<size_t>(LightingRegs::LightingSampler::Distribution1),
345 index, delta); 353 index, delta);
346 } 354 }
347 355
@@ -362,7 +370,8 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
362 370
363 float lut_value = 371 float lut_value =
364 scale * 372 scale *
365 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Fresnel), 373 LookupLightingLut(g_state.lighting,
374 static_cast<size_t>(LightingRegs::LightingSampler::Fresnel),
366 index, delta); 375 index, delta);
367 376
368 // Enabled for diffuse lighting alpha component 377 // Enabled for diffuse lighting alpha component