summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_shader_gen.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2015-11-24 02:26:09 +0100
committerbunnei <bunneidev@gmail.com>2016-02-05 23:20:13 +0100
commitc37de30cfc21cd6d742eed27a996a273f5ec2ca1 (patch)
tree44757e1d0fd83110229e7fad641a54f2e6353baf /src/video_core/renderer_opengl/gl_shader_gen.cpp
parentgl_shader_gen: Implement fragment lighting specular 1 component. (diff)
downloadyuzu-c37de30cfc21cd6d742eed27a996a273f5ec2ca1.tar
yuzu-c37de30cfc21cd6d742eed27a996a273f5ec2ca1.tar.gz
yuzu-c37de30cfc21cd6d742eed27a996a273f5ec2ca1.tar.bz2
yuzu-c37de30cfc21cd6d742eed27a996a273f5ec2ca1.tar.lz
yuzu-c37de30cfc21cd6d742eed27a996a273f5ec2ca1.tar.xz
yuzu-c37de30cfc21cd6d742eed27a996a273f5ec2ca1.tar.zst
yuzu-c37de30cfc21cd6d742eed27a996a273f5ec2ca1.zip
Diffstat (limited to 'src/video_core/renderer_opengl/gl_shader_gen.cpp')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 4f8b675bf..6487172b4 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -321,8 +321,8 @@ static void WriteTevStage(std::string& out, const PicaShaderConfig& config, unsi
/// Writes the code to emulate fragment lighting
static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
// Define lighting globals
- out += "vec3 diffuse_sum = vec3(0.0);\n";
- out += "vec3 specular_sum = vec3(0.0);\n";
+ out += "vec4 diffuse_sum = vec4(0.0, 0.0, 0.0, 1.0);\n";
+ out += "vec4 specular_sum = vec4(0.0, 0.0, 0.0, 1.0);\n";
out += "vec3 light_vector = vec3(0.0);\n";
// Convert interpolated quaternion to a GL fragment normal
@@ -402,9 +402,6 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
dist_atten = GetLutValue((Regs::LightingSampler)lut_num, lut_index);
}
- // Compute primary fragment color (diffuse lighting) function
- out += "diffuse_sum += ((" + light_src + ".diffuse * " + dot_product + ") + " + light_src + ".ambient) * " + dist_atten + ";\n";
-
// If enabled, clamp specular component if lighting result is negative
std::string clamp_highlights = config.lighting.clamp_highlights ? "(dot(light_vector, normal) <= 0.0 ? 0.0 : 1.0)" : "1.0";
@@ -426,14 +423,34 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
}
std::string specular_1 = "(" + d1_lut_value + " * " + light_src + ".specular_1)";
+ // Fresnel
+ if (config.lighting.lut_fr.enable && Pica::Regs::IsLightingSamplerSupported(config.lighting.config, Pica::Regs::LightingSampler::Fresnel)) {
+ // Lookup fresnel LUT value
+ std::string fr_lut_index = GetLutIndex(light_config.num, config.lighting.lut_fr.type, config.lighting.lut_fr.abs_input);
+ std::string fr_lut_value = "(" + std::to_string(config.lighting.lut_fr.scale) + " * " + GetLutValue(Regs::LightingSampler::Fresnel, fr_lut_index) + ")";
+
+ // Enabled for difffuse lighting alpha component
+ if (config.lighting.fresnel_selector == Pica::Regs::LightingFresnelSelector::PrimaryAlpha ||
+ config.lighting.fresnel_selector == Pica::Regs::LightingFresnelSelector::BothAlpha)
+ out += "diffuse_sum.a *= " + fr_lut_value + ";\n";
+
+ // Enabled for the specular lighting alpha component
+ if (config.lighting.fresnel_selector == Pica::Regs::LightingFresnelSelector::SecondaryAlpha ||
+ config.lighting.fresnel_selector == Pica::Regs::LightingFresnelSelector::BothAlpha)
+ out += "specular_sum.a *= " + fr_lut_value + ";\n";
+ }
+
+ // Compute primary fragment color (diffuse lighting) function
+ out += "diffuse_sum.rgb += ((" + light_src + ".diffuse * " + dot_product + ") + " + light_src + ".ambient) * " + dist_atten + ";\n";
+
// Compute secondary fragment color (specular lighting) function
- out += "specular_sum += (" + specular_0 + " + " + specular_1 + ") * " + clamp_highlights + " * " + dist_atten + ";\n";
+ out += "specular_sum.rgb += (" + specular_0 + " + " + specular_1 + ") * " + clamp_highlights + " * " + dist_atten + ";\n";
}
// Sum final lighting result
- out += "diffuse_sum += lighting_global_ambient;\n";
- out += "primary_fragment_color = vec4(clamp(diffuse_sum, vec3(0.0), vec3(1.0)), 1.0);\n";
- out += "secondary_fragment_color = vec4(clamp(specular_sum, vec3(0.0), vec3(1.0)), 1.0);\n";
+ out += "diffuse_sum.rgb += lighting_global_ambient;\n";
+ out += "primary_fragment_color = clamp(diffuse_sum, vec4(0.0), vec4(1.0));\n";
+ out += "secondary_fragment_color = clamp(specular_sum, vec4(0.0), vec4(1.0));\n";
}
std::string GenerateFragmentShader(const PicaShaderConfig& config) {