summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2017-06-13 12:31:28 -0500
committerGravatar wwylele2017-07-11 19:39:15 +0300
commit2d69a9b8bf232fdd9e3bbb2a9c624ee9dd6ec637 (patch)
treeacdf6d26265cdcaf95c171489fb8af124f6bc780 /src
parentSwRasterizer: Flip the vertex quaternions before clipping (if necessary). (diff)
downloadyuzu-2d69a9b8bf232fdd9e3bbb2a9c624ee9dd6ec637.tar.gz
yuzu-2d69a9b8bf232fdd9e3bbb2a9c624ee9dd6ec637.tar.xz
yuzu-2d69a9b8bf232fdd9e3bbb2a9c624ee9dd6ec637.zip
SwRasterizer: Run clang-format
Diffstat (limited to 'src')
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp128
1 files changed, 83 insertions, 45 deletions
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index 76f793c86..382b5927b 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -125,11 +125,12 @@ float LookupLightingLut(size_t lut_index, u8 index, float delta) {
125 return lut_value + lut_diff * delta; 125 return lut_value + lut_diff * delta;
126} 126}
127 127
128std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view) { 128std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
129 const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view) {
129 const auto& lighting = g_state.regs.lighting; 130 const auto& lighting = g_state.regs.lighting;
130 131
131 if (lighting.disable) 132 if (lighting.disable)
132 return {{}, {}}; 133 return {Math::MakeVec<u8>(0, 0, 0, 0), Math::MakeVec<u8>(0, 0, 0, 0)};
133 134
134 // TODO(Subv): Bump mapping 135 // TODO(Subv): Bump mapping
135 Math::Vec3<float> surface_normal = {0.0f, 0.0f, 1.0f}; 136 Math::Vec3<float> surface_normal = {0.0f, 0.0f, 1.0f};
@@ -151,7 +152,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
151 unsigned num = lighting.light_enable.GetNum(light_index); 152 unsigned num = lighting.light_enable.GetNum(light_index);
152 const auto& light_config = g_state.regs.lighting.light[num]; 153 const auto& light_config = g_state.regs.lighting.light[num];
153 154
154 Math::Vec3<float> position = {float16::FromRaw(light_config.x).ToFloat32(), float16::FromRaw(light_config.y).ToFloat32(), float16::FromRaw(light_config.z).ToFloat32()}; 155 Math::Vec3<float> position = {float16::FromRaw(light_config.x).ToFloat32(),
156 float16::FromRaw(light_config.y).ToFloat32(),
157 float16::FromRaw(light_config.z).ToFloat32()};
155 158
156 if (light_config.config.directional) 159 if (light_config.config.directional)
157 light_vector = position; 160 light_vector = position;
@@ -173,11 +176,13 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
173 auto distance = (-view - position).Length(); 176 auto distance = (-view - position).Length();
174 float scale = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32(); 177 float scale = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32();
175 float bias = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32(); 178 float bias = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32();
176 size_t lut = static_cast<size_t>(LightingRegs::LightingSampler::DistanceAttenuation) + num; 179 size_t lut =
180 static_cast<size_t>(LightingRegs::LightingSampler::DistanceAttenuation) + num;
177 181
178 float sample_loc = scale * distance + bias; 182 float sample_loc = scale * distance + bias;
179 183
180 u8 lutindex = MathUtil::Clamp(std::floor(sample_loc * 256.f), 0.0f, 255.0f); 184 u8 lutindex =
185 static_cast<u8>(MathUtil::Clamp(std::floor(sample_loc * 256.f), 0.0f, 255.0f));
181 float delta = sample_loc * 256 - lutindex; 186 float delta = sample_loc * 256 - lutindex;
182 dist_atten = LookupLightingLut(lut, lutindex, delta); 187 dist_atten = LookupLightingLut(lut, lutindex, delta);
183 } 188 }
@@ -192,7 +197,7 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
192 } 197 }
193 198
194 auto GetLutIndex = [&](unsigned num, LightingRegs::LightingLutInput input, 199 auto GetLutIndex = [&](unsigned num, LightingRegs::LightingLutInput input,
195 bool abs) -> std::tuple<u8, float> { 200 bool abs) -> std::tuple<u8, float> {
196 201
197 Math::Vec3<float> norm_view = view.Normalized(); 202 Math::Vec3<float> norm_view = view.Normalized();
198 Math::Vec3<float> half_angle = (norm_view + light_vector).Normalized(); 203 Math::Vec3<float> half_angle = (norm_view + light_vector).Normalized();
@@ -216,7 +221,7 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
216 break; 221 break;
217 222
218 default: 223 default:
219 LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %d\n", (int)input); 224 LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %u\n", static_cast<u32>(input));
220 UNIMPLEMENTED(); 225 UNIMPLEMENTED();
221 result = 0.f; 226 result = 0.f;
222 } 227 }
@@ -227,14 +232,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
227 else 232 else
228 result = std::max(result, 0.0f); 233 result = std::max(result, 0.0f);
229 234
230 u8 lutindex = MathUtil::Clamp(std::floor(result * 256.f), 0.0f, 255.0f); 235 float flr = std::floor(result * 256.f);
236 u8 lutindex = static_cast<u8>(MathUtil::Clamp(flr, 0.0f, 255.0f));
231 float delta = result * 256 - lutindex; 237 float delta = result * 256 - lutindex;
232 return { lutindex, delta }; 238 return {lutindex, delta};
233 } else { 239 } else {
234 float flr = std::floor(result * 128.f); 240 float flr = std::floor(result * 128.f);
235 s8 tmpi = MathUtil::Clamp(flr, -128.0f, 127.0f); 241 s8 lutindex = static_cast<u8>(MathUtil::Clamp(flr, -128.0f, 127.0f));
236 float delta = result * 128.f - tmpi; 242 float delta = result * 128.f - lutindex;
237 return { tmpi & 0xFF, delta }; 243 return {static_cast<u8>(lutindex), delta};
238 } 244 }
239 }; 245 };
240 246
@@ -247,11 +253,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
247 // Lookup specular "distribution 0" LUT value 253 // Lookup specular "distribution 0" LUT value
248 u8 index; 254 u8 index;
249 float delta; 255 float delta;
250 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d0.Value(), lighting.abs_lut_input.disable_d0 == 0); 256 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d0.Value(),
257 lighting.abs_lut_input.disable_d0 == 0);
251 258
252 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d0); 259 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d0);
253 260
254 d0_lut_value = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution0), index, delta); 261 d0_lut_value =
262 scale *
263 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution0),
264 index, delta);
255 } 265 }
256 266
257 Math::Vec3<float> specular_0 = d0_lut_value * light_config.specular_0.ToVec3f(); 267 Math::Vec3<float> specular_0 = d0_lut_value * light_config.specular_0.ToVec3f();
@@ -263,11 +273,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
263 273
264 u8 index; 274 u8 index;
265 float delta; 275 float delta;
266 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.rr, lighting.abs_lut_input.disable_rr == 0); 276 std::tie(index, delta) =
277 GetLutIndex(num, lighting.lut_input.rr, lighting.abs_lut_input.disable_rr == 0);
267 278
268 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rr); 279 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rr);
269 280
270 refl_value.x = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectRed), index, delta); 281 refl_value.x =
282 scale *
283 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectRed),
284 index, delta);
271 } else { 285 } else {
272 refl_value.x = 1.0f; 286 refl_value.x = 1.0f;
273 } 287 }
@@ -279,11 +293,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
279 293
280 u8 index; 294 u8 index;
281 float delta; 295 float delta;
282 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.rg, lighting.abs_lut_input.disable_rg == 0); 296 std::tie(index, delta) =
297 GetLutIndex(num, lighting.lut_input.rg, lighting.abs_lut_input.disable_rg == 0);
283 298
284 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rg); 299 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rg);
285 300
286 refl_value.y = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectGreen), index, delta); 301 refl_value.y =
302 scale *
303 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectGreen),
304 index, delta);
287 } else { 305 } else {
288 refl_value.y = refl_value.x; 306 refl_value.y = refl_value.x;
289 } 307 }
@@ -295,11 +313,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
295 313
296 u8 index; 314 u8 index;
297 float delta; 315 float delta;
298 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.rb, lighting.abs_lut_input.disable_rb == 0); 316 std::tie(index, delta) =
317 GetLutIndex(num, lighting.lut_input.rb, lighting.abs_lut_input.disable_rb == 0);
299 318
300 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rb); 319 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rb);
301 320
302 refl_value.z = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectBlue), index, delta); 321 refl_value.z =
322 scale *
323 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::ReflectBlue),
324 index, delta);
303 } else { 325 } else {
304 refl_value.z = refl_value.x; 326 refl_value.z = refl_value.x;
305 } 327 }
@@ -312,54 +334,72 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
312 // Lookup specular "distribution 1" LUT value 334 // Lookup specular "distribution 1" LUT value
313 u8 index; 335 u8 index;
314 float delta; 336 float delta;
315 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d1.Value(), lighting.abs_lut_input.disable_d1 == 0); 337 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d1.Value(),
338 lighting.abs_lut_input.disable_d1 == 0);
316 339
317 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d1); 340 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d1);
318 341
319 d1_lut_value = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution1), index, delta); 342 d1_lut_value =
343 scale *
344 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Distribution1),
345 index, delta);
320 } 346 }
321 347
322 Math::Vec3<float> specular_1 = d1_lut_value * refl_value * light_config.specular_1.ToVec3f(); 348 Math::Vec3<float> specular_1 =
349 d1_lut_value * refl_value * light_config.specular_1.ToVec3f();
323 350
324 if (lighting.config1.disable_lut_fr == 0 && 351 if (lighting.config1.disable_lut_fr == 0 &&
325 LightingRegs::IsLightingSamplerSupported( 352 LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
326 lighting.config0.config, LightingRegs::LightingSampler::Fresnel)) { 353 LightingRegs::LightingSampler::Fresnel)) {
327 354
328 // Lookup fresnel LUT value 355 // Lookup fresnel LUT value
329 u8 index; 356 u8 index;
330 float delta; 357 float delta;
331 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.fr.Value(), lighting.abs_lut_input.disable_fr == 0); 358 std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.fr.Value(),
359 lighting.abs_lut_input.disable_fr == 0);
332 360
333 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.fr); 361 float scale = lighting.lut_scale.GetScale(lighting.lut_scale.fr);
334 362
335 float lut_value = scale * LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Fresnel), index, delta); 363 float lut_value =
364 scale *
365 LookupLightingLut(static_cast<size_t>(LightingRegs::LightingSampler::Fresnel),
366 index, delta);
336 367
337 // Enabled for difffuse lighting alpha component 368 // Enabled for diffuse lighting alpha component
338 if (lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::PrimaryAlpha || 369 if (lighting.config0.fresnel_selector ==
370 LightingRegs::LightingFresnelSelector::PrimaryAlpha ||
339 lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) { 371 lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
340 diffuse_sum.a() *= lut_value; 372 diffuse_sum.a() *= lut_value;
341 } 373 }
342 374
343 // Enabled for the specular lighting alpha component 375 // Enabled for the specular lighting alpha component
344 if (lighting.config0.fresnel_selector == 376 if (lighting.config0.fresnel_selector ==
345 LightingRegs::LightingFresnelSelector::SecondaryAlpha || 377 LightingRegs::LightingFresnelSelector::SecondaryAlpha ||
346 lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) { 378 lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
347 specular_sum.a() *= lut_value; 379 specular_sum.a() *= lut_value;
348 } 380 }
349 } 381 }
350 382
351 383 auto diffuse =
352 auto diffuse = light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f(); 384 light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f();
353 diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f); 385 diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f);
354 386
355 specular_sum += Math::MakeVec((specular_0 + specular_1) * clamp_highlights * dist_atten, 0.f); 387 specular_sum +=
388 Math::MakeVec((specular_0 + specular_1) * clamp_highlights * dist_atten, 0.f);
356 } 389 }
357 390
358 diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f); 391 diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f);
359 return { 392
360 Math::MakeVec<float>(MathUtil::Clamp(diffuse_sum.x, 0.0f, 1.0f) * 255, MathUtil::Clamp(diffuse_sum.y, 0.0f, 1.0f) * 255, MathUtil::Clamp(diffuse_sum.z, 0.0f, 1.0f) * 255, MathUtil::Clamp(diffuse_sum.w, 0.0f, 1.0f) * 255).Cast<u8>(), 393 return {Math::MakeVec<float>(MathUtil::Clamp(diffuse_sum.x, 0.0f, 1.0f) * 255,
361 Math::MakeVec<float>(MathUtil::Clamp(specular_sum.x, 0.0f, 1.0f) * 255, MathUtil::Clamp(specular_sum.y, 0.0f, 1.0f) * 255, MathUtil::Clamp(specular_sum.z, 0.0f, 1.0f) * 255, MathUtil::Clamp(specular_sum.w, 0.0f, 1.0f) * 255).Cast<u8>() 394 MathUtil::Clamp(diffuse_sum.y, 0.0f, 1.0f) * 255,
362 }; 395 MathUtil::Clamp(diffuse_sum.z, 0.0f, 1.0f) * 255,
396 MathUtil::Clamp(diffuse_sum.w, 0.0f, 1.0f) * 255)
397 .Cast<u8>(),
398 Math::MakeVec<float>(MathUtil::Clamp(specular_sum.x, 0.0f, 1.0f) * 255,
399 MathUtil::Clamp(specular_sum.y, 0.0f, 1.0f) * 255,
400 MathUtil::Clamp(specular_sum.z, 0.0f, 1.0f) * 255,
401 MathUtil::Clamp(specular_sum.w, 0.0f, 1.0f) * 255)
402 .Cast<u8>()};
363} 403}
364 404
365MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240)); 405MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240));
@@ -554,19 +594,16 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
554 }; 594 };
555 595
556 Math::Quaternion<float> normquat{ 596 Math::Quaternion<float> normquat{
557 { 597 {GetInterpolatedAttribute(v0.quat.x, v1.quat.x, v2.quat.x).ToFloat32(),
558 GetInterpolatedAttribute(v0.quat.x, v1.quat.x, v2.quat.x).ToFloat32(), 598 GetInterpolatedAttribute(v0.quat.y, v1.quat.y, v2.quat.y).ToFloat32(),
559 GetInterpolatedAttribute(v0.quat.y, v1.quat.y, v2.quat.y).ToFloat32(), 599 GetInterpolatedAttribute(v0.quat.z, v1.quat.z, v2.quat.z).ToFloat32()},
560 GetInterpolatedAttribute(v0.quat.z, v1.quat.z, v2.quat.z).ToFloat32()
561 },
562 GetInterpolatedAttribute(v0.quat.w, v1.quat.w, v2.quat.w).ToFloat32(), 600 GetInterpolatedAttribute(v0.quat.w, v1.quat.w, v2.quat.w).ToFloat32(),
563 }; 601 };
564 602
565 Math::Vec3<float> fragment_position{ 603 Math::Vec3<float> fragment_position{
566 GetInterpolatedAttribute(v0.view.x, v1.view.x, v2.view.x).ToFloat32(), 604 GetInterpolatedAttribute(v0.view.x, v1.view.x, v2.view.x).ToFloat32(),
567 GetInterpolatedAttribute(v0.view.y, v1.view.y, v2.view.y).ToFloat32(), 605 GetInterpolatedAttribute(v0.view.y, v1.view.y, v2.view.y).ToFloat32(),
568 GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32() 606 GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32()};
569 };
570 607
571 Math::Vec2<float24> uv[3]; 608 Math::Vec2<float24> uv[3];
572 uv[0].u() = GetInterpolatedAttribute(v0.tc0.u(), v1.tc0.u(), v2.tc0.u()); 609 uv[0].u() = GetInterpolatedAttribute(v0.tc0.u(), v1.tc0.u(), v2.tc0.u());
@@ -685,7 +722,8 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
685 Math::Vec4<u8> primary_fragment_color; 722 Math::Vec4<u8> primary_fragment_color;
686 Math::Vec4<u8> secondary_fragment_color; 723 Math::Vec4<u8> secondary_fragment_color;
687 724
688 std::tie(primary_fragment_color, secondary_fragment_color) = ComputeFragmentsColors(normquat, fragment_position); 725 std::tie(primary_fragment_color, secondary_fragment_color) =
726 ComputeFragmentsColors(normquat, fragment_position);
689 727
690 for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size(); 728 for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size();
691 ++tev_stage_index) { 729 ++tev_stage_index) {