summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2015-11-19 22:42:06 -0500
committerGravatar bunnei2016-02-05 17:19:16 -0500
commit0e67c21c9e5bb0e213d3b13bdd7592ff2a44a31c (patch)
tree413a8a8e30ff8a1d231b6abda32b02b54fd8f5f7 /src
parentgl_shader_gen: Add support for D0 LUT scaling. (diff)
downloadyuzu-0e67c21c9e5bb0e213d3b13bdd7592ff2a44a31c.tar.gz
yuzu-0e67c21c9e5bb0e213d3b13bdd7592ff2a44a31c.tar.xz
yuzu-0e67c21c9e5bb0e213d3b13bdd7592ff2a44a31c.zip
gl_shader_gen: Implement fragment lighting specular 1 component.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/pica.h27
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h8
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp17
3 files changed, 41 insertions, 11 deletions
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index 5d27da5d1..83af6a127 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -713,6 +713,16 @@ struct Regs {
713 } 713 }
714 }; 714 };
715 715
716 static bool IsLightingSamplerSupported(LightingConfig config, LightingSampler sampler) {
717 switch (sampler) {
718 case LightingSampler::Distribution0:
719 return (config != LightingConfig::Config1);
720 case LightingSampler::Distribution1:
721 return (config != LightingConfig::Config0) && (config != LightingConfig::Config1) && (config != LightingConfig::Config5);
722 }
723 return false;
724 }
725
716 struct { 726 struct {
717 struct LightSrc { 727 struct LightSrc {
718 LightColor specular_0; // material.specular_0 * light.specular_0 728 LightColor specular_0; // material.specular_0 * light.specular_0
@@ -751,12 +761,13 @@ struct Regs {
751 BitField<0, 3, u32> src_num; // number of enabled lights - 1 761 BitField<0, 3, u32> src_num; // number of enabled lights - 1
752 762
753 union { 763 union {
754 BitField< 4, 4, u32> config; 764 BitField< 4, 4, LightingConfig> config;
755 BitField<27, 1, u32> clamp_highlights; // 1: GL_TRUE, 0: GL_FALSE 765 BitField<27, 1, u32> clamp_highlights; // 1: GL_TRUE, 0: GL_FALSE
756 }; 766 };
757 767
758 union { 768 union {
759 BitField<16, 1, u32> lut_enable_d0; // 0: GL_TRUE, 1: GL_FALSE 769 BitField<16, 1, u32> lut_enable_d0; // 0: GL_TRUE, 1: GL_FALSE
770 BitField<17, 1, u32> lut_enable_d1; // 0: GL_TRUE, 1: GL_FALSE
760 771
761 // Each bit specifies whether distance attenuation should be applied for the 772 // Each bit specifies whether distance attenuation should be applied for the
762 // corresponding light 773 // corresponding light
@@ -804,13 +815,13 @@ struct Regs {
804 } abs_lut_input; 815 } abs_lut_input;
805 816
806 union { 817 union {
807 BitField< 0, 3, u32> d0; 818 BitField< 0, 3, LightingLutInput> d0;
808 BitField< 4, 3, u32> d1; 819 BitField< 4, 3, LightingLutInput> d1;
809 BitField< 8, 3, u32> sp; 820 BitField< 8, 3, LightingLutInput> sp;
810 BitField<12, 3, u32> fr; 821 BitField<12, 3, LightingLutInput> fr;
811 BitField<16, 3, u32> rb; 822 BitField<16, 3, LightingLutInput> rb;
812 BitField<20, 3, u32> rg; 823 BitField<20, 3, LightingLutInput> rg;
813 BitField<24, 3, u32> rr; 824 BitField<24, 3, LightingLutInput> rr;
814 } lut_input; 825 } lut_input;
815 826
816 union { 827 union {
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 72ded8f22..788618ed2 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -91,6 +91,13 @@ struct PicaShaderConfig {
91 res.lighting.lut_d0.abs_input = regs.lighting.abs_lut_input.d0 == 0; 91 res.lighting.lut_d0.abs_input = regs.lighting.abs_lut_input.d0 == 0;
92 res.lighting.lut_d0.type = (Pica::Regs::LightingLutInput)regs.lighting.lut_input.d0.Value(); 92 res.lighting.lut_d0.type = (Pica::Regs::LightingLutInput)regs.lighting.lut_input.d0.Value();
93 res.lighting.lut_d0.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.d0); 93 res.lighting.lut_d0.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.d0);
94
95 res.lighting.lut_d1.enable = regs.lighting.lut_enable_d1 == 0;
96 res.lighting.lut_d1.abs_input = regs.lighting.abs_lut_input.d1 == 0;
97 res.lighting.lut_d1.type = (Pica::Regs::LightingLutInput)regs.lighting.lut_input.d1.Value();
98 res.lighting.lut_d1.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.d1);
99
100 res.lighting.config = regs.lighting.config;
94 res.lighting.clamp_highlights = regs.lighting.clamp_highlights != 0; 101 res.lighting.clamp_highlights = regs.lighting.clamp_highlights != 0;
95 102
96 return res; 103 return res;
@@ -126,6 +133,7 @@ struct PicaShaderConfig {
126 bool enable = false; 133 bool enable = false;
127 unsigned src_num = 0; 134 unsigned src_num = 0;
128 bool clamp_highlights = false; 135 bool clamp_highlights = false;
136 Pica::Regs::LightingConfig config = Pica::Regs::LightingConfig::Config0;
129 137
130 struct { 138 struct {
131 bool enable = false; 139 bool enable = false;
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 9044a3813..4f8b675bf 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -408,15 +408,26 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
408 // If enabled, clamp specular component if lighting result is negative 408 // If enabled, clamp specular component if lighting result is negative
409 std::string clamp_highlights = config.lighting.clamp_highlights ? "(dot(light_vector, normal) <= 0.0 ? 0.0 : 1.0)" : "1.0"; 409 std::string clamp_highlights = config.lighting.clamp_highlights ? "(dot(light_vector, normal) <= 0.0 ? 0.0 : 1.0)" : "1.0";
410 410
411 // Lookup specular "distribution 0" LUT value 411 // Specular 0 component
412 std::string d0_lut_value = "1.0"; 412 std::string d0_lut_value = "1.0";
413 if (config.lighting.lut_d0.enable) { 413 if (config.lighting.lut_d0.enable && Pica::Regs::IsLightingSamplerSupported(config.lighting.config, Pica::Regs::LightingSampler::Distribution0)) {
414 // Lookup specular "distribution 0" LUT value
414 std::string d0_lut_index = GetLutIndex(light_config.num, config.lighting.lut_d0.type, config.lighting.lut_d0.abs_input); 415 std::string d0_lut_index = GetLutIndex(light_config.num, config.lighting.lut_d0.type, config.lighting.lut_d0.abs_input);
415 d0_lut_value = "(" + std::to_string(config.lighting.lut_d0.scale) + " * " + GetLutValue(Regs::LightingSampler::Distribution0, d0_lut_index) + ")"; 416 d0_lut_value = "(" + std::to_string(config.lighting.lut_d0.scale) + " * " + GetLutValue(Regs::LightingSampler::Distribution0, d0_lut_index) + ")";
416 } 417 }
418 std::string specular_0 = "(" + d0_lut_value + " * " + light_src + ".specular_0)";
419
420 // Specular 1 component
421 std::string d1_lut_value = "1.0";
422 if (config.lighting.lut_d1.enable && Pica::Regs::IsLightingSamplerSupported(config.lighting.config, Pica::Regs::LightingSampler::Distribution1)) {
423 // Lookup specular "distribution 1" LUT value
424 std::string d1_lut_index = GetLutIndex(light_config.num, config.lighting.lut_d1.type, config.lighting.lut_d1.abs_input);
425 d1_lut_value = "(" + std::to_string(config.lighting.lut_d1.scale) + " * " + GetLutValue(Regs::LightingSampler::Distribution1, d1_lut_index) + ")";
426 }
427 std::string specular_1 = "(" + d1_lut_value + " * " + light_src + ".specular_1)";
417 428
418 // Compute secondary fragment color (specular lighting) function 429 // Compute secondary fragment color (specular lighting) function
419 out += "specular_sum += " + clamp_highlights + " * " + d0_lut_value + " * " + light_src + ".specular_0 * " + dist_atten + ";\n"; 430 out += "specular_sum += (" + specular_0 + " + " + specular_1 + ") * " + clamp_highlights + " * " + dist_atten + ";\n";
420 } 431 }
421 432
422 // Sum final lighting result 433 // Sum final lighting result