summaryrefslogtreecommitdiff
path: root/src/video_core/swrasterizer
diff options
context:
space:
mode:
authorGravatar wwylele2017-07-11 21:36:19 +0300
committerGravatar wwylele2017-07-11 22:15:35 +0300
commitc6d1472513394cc55b5d5a852d5f76b5e9a51f2b (patch)
treefe79c4c8c40d968f1e6833c1b0ca3bf0d8fcddf5 /src/video_core/swrasterizer
parentSwRasterizer: only interpolate quat and view when lighting is enabled (diff)
downloadyuzu-c6d1472513394cc55b5d5a852d5f76b5e9a51f2b.tar.gz
yuzu-c6d1472513394cc55b5d5a852d5f76b5e9a51f2b.tar.xz
yuzu-c6d1472513394cc55b5d5a852d5f76b5e9a51f2b.zip
SwRasterizer/Lighting: refactor GetLutValue into a function.
merging similar pattern. Also makes the code more similar to the gl one
Diffstat (limited to 'src/video_core/swrasterizer')
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp110
1 files changed, 27 insertions, 83 deletions
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index 5844c401c..53c3bb585 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -179,9 +179,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
179 dist_atten = LookupLightingLut(lighting_state, lut, lutindex, delta); 179 dist_atten = LookupLightingLut(lighting_state, lut, lutindex, delta);
180 } 180 }
181 181
182 auto GetLutIndex = [&](unsigned num, LightingRegs::LightingLutInput input, 182 auto GetLutValue = [&](LightingRegs::LightingLutInput input, bool abs,
183 bool abs) -> std::tuple<u8, float> { 183 LightingRegs::LightingScale scale_enum,
184 184 LightingRegs::LightingSampler sampler) {
185 Math::Vec3<float> norm_view = view.Normalized(); 185 Math::Vec3<float> norm_view = view.Normalized();
186 Math::Vec3<float> half_angle = (norm_view + light_vector).Normalized(); 186 Math::Vec3<float> half_angle = (norm_view + light_vector).Normalized();
187 float result = 0.0f; 187 float result = 0.0f;
@@ -209,6 +209,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
209 result = 0.f; 209 result = 0.f;
210 } 210 }
211 211
212 u8 index;
213 float delta;
214
212 if (abs) { 215 if (abs) {
213 if (light_config.config.two_sided_diffuse) 216 if (light_config.config.two_sided_diffuse)
214 result = std::abs(result); 217 result = std::abs(result);
@@ -216,15 +219,18 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
216 result = std::max(result, 0.0f); 219 result = std::max(result, 0.0f);
217 220
218 float flr = std::floor(result * 256.f); 221 float flr = std::floor(result * 256.f);
219 u8 lutindex = static_cast<u8>(MathUtil::Clamp(flr, 0.0f, 255.0f)); 222 index = static_cast<u8>(MathUtil::Clamp(flr, 0.0f, 255.0f));
220 float delta = result * 256 - lutindex; 223 delta = result * 256 - index;
221 return {lutindex, delta};
222 } else { 224 } else {
223 float flr = std::floor(result * 128.f); 225 float flr = std::floor(result * 128.f);
224 s8 lutindex = static_cast<s8>(MathUtil::Clamp(flr, -128.0f, 127.0f)); 226 s8 signed_index = static_cast<s8>(MathUtil::Clamp(flr, -128.0f, 127.0f));
225 float delta = result * 128.f - lutindex; 227 delta = result * 128.f - signed_index;
226 return {static_cast<u8>(lutindex), delta}; 228 index = static_cast<u8>(signed_index);
227 } 229 }
230
231 float scale = lighting.lut_scale.GetScale(scale_enum);
232 return scale *
233 LookupLightingLut(lighting_state, static_cast<size_t>(sampler), index, delta);
228 }; 234 };
229 235
230 // Specular 0 component 236 // Specular 0 component
@@ -232,20 +238,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
232 if (lighting.config1.disable_lut_d0 == 0 && 238 if (lighting.config1.disable_lut_d0 == 0 &&
233 LightingRegs::IsLightingSamplerSupported( 239 LightingRegs::IsLightingSamplerSupported(
234 lighting.config0.config, LightingRegs::LightingSampler::Distribution0)) { 240 lighting.config0.config, LightingRegs::LightingSampler::Distribution0)) {
235
236 // Lookup specular "distribution 0" LUT value
237 u8 index;
238 float delta;
239 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d0.Value(),
240 lighting.abs_lut_input.disable_d0 == 0);
241
242 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d0);
243
244 d0_lut_value = 241 d0_lut_value =
245 scale * 242 GetLutValue(lighting.lut_input.d0, lighting.abs_lut_input.disable_d0 == 0,
246 LookupLightingLut(lighting_state, 243 lighting.lut_scale.d0, LightingRegs::LightingSampler::Distribution0);
247 static_cast<size_t>(LightingRegs::LightingSampler::Distribution0),
248 index, delta);
249 } 244 }
250 245
251 Math::Vec3<float> specular_0 = d0_lut_value * light_config.specular_0.ToVec3f(); 246 Math::Vec3<float> specular_0 = d0_lut_value * light_config.specular_0.ToVec3f();
@@ -254,19 +249,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
254 if (lighting.config1.disable_lut_rr == 0 && 249 if (lighting.config1.disable_lut_rr == 0 &&
255 LightingRegs::IsLightingSamplerSupported(lighting.config0.config, 250 LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
256 LightingRegs::LightingSampler::ReflectRed)) { 251 LightingRegs::LightingSampler::ReflectRed)) {
257
258 u8 index;
259 float delta;
260 std::tie(index, delta) =
261 GetLutIndex(num, lighting.lut_input.rr, lighting.abs_lut_input.disable_rr == 0);
262
263 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rr);
264
265 refl_value.x = 252 refl_value.x =
266 scale * 253 GetLutValue(lighting.lut_input.rr, lighting.abs_lut_input.disable_rr == 0,
267 LookupLightingLut(lighting_state, 254 lighting.lut_scale.rr, LightingRegs::LightingSampler::ReflectRed);
268 static_cast<size_t>(LightingRegs::LightingSampler::ReflectRed),
269 index, delta);
270 } else { 255 } else {
271 refl_value.x = 1.0f; 256 refl_value.x = 1.0f;
272 } 257 }
@@ -275,19 +260,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
275 if (lighting.config1.disable_lut_rg == 0 && 260 if (lighting.config1.disable_lut_rg == 0 &&
276 LightingRegs::IsLightingSamplerSupported(lighting.config0.config, 261 LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
277 LightingRegs::LightingSampler::ReflectGreen)) { 262 LightingRegs::LightingSampler::ReflectGreen)) {
278
279 u8 index;
280 float delta;
281 std::tie(index, delta) =
282 GetLutIndex(num, lighting.lut_input.rg, lighting.abs_lut_input.disable_rg == 0);
283
284 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rg);
285
286 refl_value.y = 263 refl_value.y =
287 scale * 264 GetLutValue(lighting.lut_input.rg, lighting.abs_lut_input.disable_rg == 0,
288 LookupLightingLut(lighting_state, 265 lighting.lut_scale.rg, LightingRegs::LightingSampler::ReflectGreen);
289 static_cast<size_t>(LightingRegs::LightingSampler::ReflectGreen),
290 index, delta);
291 } else { 266 } else {
292 refl_value.y = refl_value.x; 267 refl_value.y = refl_value.x;
293 } 268 }
@@ -296,19 +271,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
296 if (lighting.config1.disable_lut_rb == 0 && 271 if (lighting.config1.disable_lut_rb == 0 &&
297 LightingRegs::IsLightingSamplerSupported(lighting.config0.config, 272 LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
298 LightingRegs::LightingSampler::ReflectBlue)) { 273 LightingRegs::LightingSampler::ReflectBlue)) {
299
300 u8 index;
301 float delta;
302 std::tie(index, delta) =
303 GetLutIndex(num, lighting.lut_input.rb, lighting.abs_lut_input.disable_rb == 0);
304
305 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rb);
306
307 refl_value.z = 274 refl_value.z =
308 scale * 275 GetLutValue(lighting.lut_input.rb, lighting.abs_lut_input.disable_rb == 0,
309 LookupLightingLut(lighting_state, 276 lighting.lut_scale.rb, LightingRegs::LightingSampler::ReflectBlue);
310 static_cast<size_t>(LightingRegs::LightingSampler::ReflectBlue),
311 index, delta);
312 } else { 277 } else {
313 refl_value.z = refl_value.x; 278 refl_value.z = refl_value.x;
314 } 279 }
@@ -317,20 +282,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
317 if (lighting.config1.disable_lut_d1 == 0 && 282 if (lighting.config1.disable_lut_d1 == 0 &&
318 LightingRegs::IsLightingSamplerSupported( 283 LightingRegs::IsLightingSamplerSupported(
319 lighting.config0.config, LightingRegs::LightingSampler::Distribution1)) { 284 lighting.config0.config, LightingRegs::LightingSampler::Distribution1)) {
320
321 // Lookup specular "distribution 1" LUT value
322 u8 index;
323 float delta;
324 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d1.Value(),
325 lighting.abs_lut_input.disable_d1 == 0);
326
327 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d1);
328
329 d1_lut_value = 285 d1_lut_value =
330 scale * 286 GetLutValue(lighting.lut_input.d1, lighting.abs_lut_input.disable_d1 == 0,
331 LookupLightingLut(lighting_state, 287 lighting.lut_scale.d1, LightingRegs::LightingSampler::Distribution1);
332 static_cast<size_t>(LightingRegs::LightingSampler::Distribution1),
333 index, delta);
334 } 288 }
335 289
336 Math::Vec3<float> specular_1 = 290 Math::Vec3<float> specular_1 =
@@ -340,19 +294,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
340 LightingRegs::IsLightingSamplerSupported(lighting.config0.config, 294 LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
341 LightingRegs::LightingSampler::Fresnel)) { 295 LightingRegs::LightingSampler::Fresnel)) {
342 296
343 // Lookup fresnel LUT value
344 u8 index;
345 float delta;
346 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.fr.Value(),
347 lighting.abs_lut_input.disable_fr == 0);
348
349 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.fr);
350
351 float lut_value = 297 float lut_value =
352 scale * 298 GetLutValue(lighting.lut_input.fr, lighting.abs_lut_input.disable_fr == 0,
353 LookupLightingLut(lighting_state, 299 lighting.lut_scale.fr, LightingRegs::LightingSampler::Fresnel);
354 static_cast<size_t>(LightingRegs::LightingSampler::Fresnel),
355 index, delta);
356 300
357 // Enabled for diffuse lighting alpha component 301 // Enabled for diffuse lighting alpha component
358 if (lighting.config0.fresnel_selector == 302 if (lighting.config0.fresnel_selector ==