diff options
author | bunnei <bunneidev@gmail.com> | 2015-11-14 05:04:19 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2016-02-05 23:17:30 +0100 |
commit | e34fa6365ff87af247b0ae8ed880c4032bcb2ed0 (patch) | |
tree | 5ca6d502f680761246eca4033daf1c7ad658a4aa /src/video_core/renderer_opengl/gl_shader_gen.cpp | |
parent | renderer_opengl: Implement HW fragment lighting LUTs within our default UBO. (diff) | |
download | yuzu-e34fa6365ff87af247b0ae8ed880c4032bcb2ed0.tar yuzu-e34fa6365ff87af247b0ae8ed880c4032bcb2ed0.tar.gz yuzu-e34fa6365ff87af247b0ae8ed880c4032bcb2ed0.tar.bz2 yuzu-e34fa6365ff87af247b0ae8ed880c4032bcb2ed0.tar.lz yuzu-e34fa6365ff87af247b0ae8ed880c4032bcb2ed0.tar.xz yuzu-e34fa6365ff87af247b0ae8ed880c4032bcb2ed0.tar.zst yuzu-e34fa6365ff87af247b0ae8ed880c4032bcb2ed0.zip |
Diffstat (limited to 'src/video_core/renderer_opengl/gl_shader_gen.cpp')
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 4e02671dd..cf99cff76 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -371,12 +371,13 @@ vec4 primary_fragment_color = vec4(0.0); for (unsigned light_index = 0; light_index < config.num_lights; ++light_index) { unsigned num = config.light_src[light_index].num; + std::string light_src = "light_src[" + std::to_string(num) + "]"; std::string light_vector; if (config.light_src[light_index].directional) - light_vector = "normalize(-light_src[" + std::to_string(num) + "].position)"; + light_vector = "normalize(-" + light_src + ".position)"; else - light_vector = "normalize(light_src[" + std::to_string(num) + "].position - fragment_position)"; + light_vector = "normalize(" + light_src + ".position - fragment_position)"; std::string dot_product; if (config.light_src[light_index].two_sided_diffuse) @@ -384,7 +385,19 @@ vec4 primary_fragment_color = vec4(0.0); else dot_product = "max(dot(" + light_vector + ", normal), 0.0)"; - out += "diffuse_sum += ((light_src[" + std::to_string(num) + "].diffuse * " + dot_product + ") + light_src[" + std::to_string(num) + "].ambient) * 1.0;\n"; + std::string dist_atten = "1.0"; + if (config.light_src[light_index].dist_atten_enabled) { + std::string scale = std::to_string(config.light_src[light_index].dist_atten_scale); + std::string bias = std::to_string(config.light_src[light_index].dist_atten_bias); + std::string lut_index = "(" + scale + " * length(fragment_position - " + light_src + ".position) + " + bias + ")"; + std::string clamped_lut_index = "((clamp(int(" + lut_index + " * 256.0), 0, 255)))"; + + unsigned lut_num = ((unsigned)Regs::LightingSampler::DistanceAttenuation + num); + + dist_atten = "lighting_lut_" + std::to_string(lut_num /4) + "[" + clamped_lut_index + "][" + std::to_string(lut_num & 3) + "]"; + } + + out += "diffuse_sum += ((light_src[" + std::to_string(num) + "].diffuse * " + dot_product + ") + light_src[" + std::to_string(num) + "].ambient) * " + dist_atten + ";\n"; } out += "diffuse_sum += lighting_global_ambient;\n"; |