summaryrefslogtreecommitdiff
path: root/src/video_core/swrasterizer/rasterizer.cpp
diff options
context:
space:
mode:
authorGravatar Weiyi Wang2017-08-09 18:54:29 +0300
committerGravatar GitHub2017-08-09 18:54:29 +0300
commit792dee47a7b520cb2a8d7cf43cc184c17394708f (patch)
tree35b14f184d95834bed51d3fda5c9662355e8b7f7 /src/video_core/swrasterizer/rasterizer.cpp
parentMerge pull request #2856 from wwylele/shader-share (diff)
parentSwRasterizer/Lighting: shorten file name (diff)
downloadyuzu-792dee47a7b520cb2a8d7cf43cc184c17394708f.tar.gz
yuzu-792dee47a7b520cb2a8d7cf43cc184c17394708f.tar.xz
yuzu-792dee47a7b520cb2a8d7cf43cc184c17394708f.zip
Merge pull request #2822 from wwylele/sw_lighting-2
Implement fragment lighting in the sw renderer (take 2)
Diffstat (limited to 'src/video_core/swrasterizer/rasterizer.cpp')
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index 512e81c08..fdc1df199 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -13,6 +13,7 @@
13#include "common/logging/log.h" 13#include "common/logging/log.h"
14#include "common/math_util.h" 14#include "common/math_util.h"
15#include "common/microprofile.h" 15#include "common/microprofile.h"
16#include "common/quaternion.h"
16#include "common/vector_math.h" 17#include "common/vector_math.h"
17#include "core/hw/gpu.h" 18#include "core/hw/gpu.h"
18#include "core/memory.h" 19#include "core/memory.h"
@@ -24,6 +25,7 @@
24#include "video_core/regs_texturing.h" 25#include "video_core/regs_texturing.h"
25#include "video_core/shader/shader.h" 26#include "video_core/shader/shader.h"
26#include "video_core/swrasterizer/framebuffer.h" 27#include "video_core/swrasterizer/framebuffer.h"
28#include "video_core/swrasterizer/lighting.h"
27#include "video_core/swrasterizer/proctex.h" 29#include "video_core/swrasterizer/proctex.h"
28#include "video_core/swrasterizer/rasterizer.h" 30#include "video_core/swrasterizer/rasterizer.h"
29#include "video_core/swrasterizer/texturing.h" 31#include "video_core/swrasterizer/texturing.h"
@@ -419,6 +421,26 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
419 regs.texturing.tev_combiner_buffer_color.a, 421 regs.texturing.tev_combiner_buffer_color.a,
420 }; 422 };
421 423
424 Math::Vec4<u8> primary_fragment_color = {0, 0, 0, 0};
425 Math::Vec4<u8> secondary_fragment_color = {0, 0, 0, 0};
426
427 if (!g_state.regs.lighting.disable) {
428 Math::Quaternion<float> normquat = Math::Quaternion<float>{
429 {GetInterpolatedAttribute(v0.quat.x, v1.quat.x, v2.quat.x).ToFloat32(),
430 GetInterpolatedAttribute(v0.quat.y, v1.quat.y, v2.quat.y).ToFloat32(),
431 GetInterpolatedAttribute(v0.quat.z, v1.quat.z, v2.quat.z).ToFloat32()},
432 GetInterpolatedAttribute(v0.quat.w, v1.quat.w, v2.quat.w).ToFloat32(),
433 }.Normalized();
434
435 Math::Vec3<float> view{
436 GetInterpolatedAttribute(v0.view.x, v1.view.x, v2.view.x).ToFloat32(),
437 GetInterpolatedAttribute(v0.view.y, v1.view.y, v2.view.y).ToFloat32(),
438 GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32(),
439 };
440 std::tie(primary_fragment_color, secondary_fragment_color) =
441 ComputeFragmentsColors(g_state.regs.lighting, g_state.lighting, normquat, view);
442 }
443
422 for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size(); 444 for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size();
423 ++tev_stage_index) { 445 ++tev_stage_index) {
424 const auto& tev_stage = tev_stages[tev_stage_index]; 446 const auto& tev_stage = tev_stages[tev_stage_index];
@@ -427,14 +449,13 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
427 auto GetSource = [&](Source source) -> Math::Vec4<u8> { 449 auto GetSource = [&](Source source) -> Math::Vec4<u8> {
428 switch (source) { 450 switch (source) {
429 case Source::PrimaryColor: 451 case Source::PrimaryColor:
452 return primary_color;
430 453
431 // HACK: Until we implement fragment lighting, use primary_color
432 case Source::PrimaryFragmentColor: 454 case Source::PrimaryFragmentColor:
433 return primary_color; 455 return primary_fragment_color;
434 456
435 // HACK: Until we implement fragment lighting, use zero
436 case Source::SecondaryFragmentColor: 457 case Source::SecondaryFragmentColor:
437 return {0, 0, 0, 0}; 458 return secondary_fragment_color;
438 459
439 case Source::Texture0: 460 case Source::Texture0:
440 return texture_color[0]; 461 return texture_color[0];