summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_core/regs_lighting.h2
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp17
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.h2
3 files changed, 20 insertions, 1 deletions
diff --git a/src/video_core/regs_lighting.h b/src/video_core/regs_lighting.h
index f383b8b4f..7221d1688 100644
--- a/src/video_core/regs_lighting.h
+++ b/src/video_core/regs_lighting.h
@@ -168,6 +168,8 @@ struct LightingRegs {
168 union { 168 union {
169 BitField<0, 1, u32> directional; 169 BitField<0, 1, u32> directional;
170 BitField<1, 1, u32> two_sided_diffuse; // When disabled, clamp dot-product to 0 170 BitField<1, 1, u32> two_sided_diffuse; // When disabled, clamp dot-product to 0
171 BitField<2, 1, u32> geometric_factor_0;
172 BitField<3, 1, u32> geometric_factor_1;
171 } config; 173 } config;
172 174
173 BitField<0, 20, u32> dist_atten_bias; 175 BitField<0, 20, u32> dist_atten_bias;
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 14be1201f..04e7cb0c4 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -73,6 +73,8 @@ PicaShaderConfig PicaShaderConfig::BuildFromRegs(const Pica::Regs& regs) {
73 state.lighting.light[light_index].num = num; 73 state.lighting.light[light_index].num = num;
74 state.lighting.light[light_index].directional = light.config.directional != 0; 74 state.lighting.light[light_index].directional = light.config.directional != 0;
75 state.lighting.light[light_index].two_sided_diffuse = light.config.two_sided_diffuse != 0; 75 state.lighting.light[light_index].two_sided_diffuse = light.config.two_sided_diffuse != 0;
76 state.lighting.light[light_index].geometric_factor_0 = light.config.geometric_factor_0 != 0;
77 state.lighting.light[light_index].geometric_factor_1 = light.config.geometric_factor_1 != 0;
76 state.lighting.light[light_index].dist_atten_enable = 78 state.lighting.light[light_index].dist_atten_enable =
77 !regs.lighting.IsDistAttenDisabled(num); 79 !regs.lighting.IsDistAttenDisabled(num);
78 state.lighting.light[light_index].spot_atten_enable = 80 state.lighting.light[light_index].spot_atten_enable =
@@ -518,7 +520,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
518 "vec4 specular_sum = vec4(0.0, 0.0, 0.0, 1.0);\n" 520 "vec4 specular_sum = vec4(0.0, 0.0, 0.0, 1.0);\n"
519 "vec3 light_vector = vec3(0.0);\n" 521 "vec3 light_vector = vec3(0.0);\n"
520 "vec3 refl_value = vec3(0.0);\n" 522 "vec3 refl_value = vec3(0.0);\n"
521 "vec3 spot_dir = vec3(0.0);\n;"; 523 "vec3 spot_dir = vec3(0.0);\n"
524 "float geo_factor = 1.0;\n";
522 525
523 // Compute fragment normals and tangents 526 // Compute fragment normals and tangents
524 const std::string pertubation = 527 const std::string pertubation =
@@ -671,6 +674,12 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
671 std::string clamp_highlights = 674 std::string clamp_highlights =
672 lighting.clamp_highlights ? "(dot(light_vector, normal) <= 0.0 ? 0.0 : 1.0)" : "1.0"; 675 lighting.clamp_highlights ? "(dot(light_vector, normal) <= 0.0 ? 0.0 : 1.0)" : "1.0";
673 676
677 if (light_config.geometric_factor_0 || light_config.geometric_factor_1) {
678 out += "geo_factor = 1 + dot(light_vector, normalize(view));\n"
679 "geo_factor = geo_factor == 0.0 ? 0.0 : min(0.5 * " +
680 dot_product + " / geo_factor, 1.0);\n";
681 }
682
674 // Specular 0 component 683 // Specular 0 component
675 std::string d0_lut_value = "1.0"; 684 std::string d0_lut_value = "1.0";
676 if (lighting.lut_d0.enable && 685 if (lighting.lut_d0.enable &&
@@ -683,6 +692,9 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
683 GetLutValue(LightingRegs::LightingSampler::Distribution0, index) + ")"; 692 GetLutValue(LightingRegs::LightingSampler::Distribution0, index) + ")";
684 } 693 }
685 std::string specular_0 = "(" + d0_lut_value + " * " + light_src + ".specular_0)"; 694 std::string specular_0 = "(" + d0_lut_value + " * " + light_src + ".specular_0)";
695 if (light_config.geometric_factor_0) {
696 specular_0 = "(" + specular_0 + " * geo_factor)";
697 }
686 698
687 // If enabled, lookup ReflectRed value, otherwise, 1.0 is used 699 // If enabled, lookup ReflectRed value, otherwise, 1.0 is used
688 if (lighting.lut_rr.enable && 700 if (lighting.lut_rr.enable &&
@@ -738,6 +750,9 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
738 } 750 }
739 std::string specular_1 = 751 std::string specular_1 =
740 "(" + d1_lut_value + " * refl_value * " + light_src + ".specular_1)"; 752 "(" + d1_lut_value + " * refl_value * " + light_src + ".specular_1)";
753 if (light_config.geometric_factor_1) {
754 specular_1 = "(" + specular_1 + " * geo_factor)";
755 }
741 756
742 // Fresnel 757 // Fresnel
743 if (lighting.lut_fr.enable && 758 if (lighting.lut_fr.enable &&
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h
index 9c90eadf9..2302ae453 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.h
+++ b/src/video_core/renderer_opengl/gl_shader_gen.h
@@ -94,6 +94,8 @@ union PicaShaderConfig {
94 bool two_sided_diffuse; 94 bool two_sided_diffuse;
95 bool dist_atten_enable; 95 bool dist_atten_enable;
96 bool spot_atten_enable; 96 bool spot_atten_enable;
97 bool geometric_factor_0;
98 bool geometric_factor_1;
97 } light[8]; 99 } light[8];
98 100
99 bool enable; 101 bool enable;