mirror of
https://github.com/citra-emu/citra-nightly.git
synced 2024-12-23 18:45:31 +00:00
video_core: Fix distance vector used when calculating lighting distance attenuation. (#6366)
This commit is contained in:
parent
ffc95eb59b
commit
506644b9d6
|
@ -626,6 +626,7 @@ static void WriteLighting(std::string& out, const PicaFSConfig& config) {
|
||||||
out += "vec4 diffuse_sum = vec4(0.0, 0.0, 0.0, 1.0);\n"
|
out += "vec4 diffuse_sum = vec4(0.0, 0.0, 0.0, 1.0);\n"
|
||||||
"vec4 specular_sum = vec4(0.0, 0.0, 0.0, 1.0);\n"
|
"vec4 specular_sum = vec4(0.0, 0.0, 0.0, 1.0);\n"
|
||||||
"vec3 light_vector = vec3(0.0);\n"
|
"vec3 light_vector = vec3(0.0);\n"
|
||||||
|
"float light_distance = 0.0;\n"
|
||||||
"vec3 refl_value = vec3(0.0);\n"
|
"vec3 refl_value = vec3(0.0);\n"
|
||||||
"vec3 spot_dir = vec3(0.0);\n"
|
"vec3 spot_dir = vec3(0.0);\n"
|
||||||
"vec3 half_vector = vec3(0.0);\n"
|
"vec3 half_vector = vec3(0.0);\n"
|
||||||
|
@ -752,10 +753,12 @@ static void WriteLighting(std::string& out, const PicaFSConfig& config) {
|
||||||
|
|
||||||
// Compute light vector (directional or positional)
|
// Compute light vector (directional or positional)
|
||||||
if (light_config.directional) {
|
if (light_config.directional) {
|
||||||
out += fmt::format("light_vector = normalize({}.position);\n", light_src);
|
out += fmt::format("light_vector = {}.position;\n", light_src);
|
||||||
} else {
|
} else {
|
||||||
out += fmt::format("light_vector = normalize({}.position + view);\n", light_src);
|
out += fmt::format("light_vector = {}.position + view;\n", light_src);
|
||||||
}
|
}
|
||||||
|
out += fmt::format("light_distance = length(light_vector);\n", light_src);
|
||||||
|
out += fmt::format("light_vector = normalize(light_vector);\n", light_src);
|
||||||
|
|
||||||
out += fmt::format("spot_dir = {}.spot_direction;\n", light_src);
|
out += fmt::format("spot_dir = {}.spot_direction;\n", light_src);
|
||||||
out += "half_vector = normalize(view) + light_vector;\n";
|
out += "half_vector = normalize(view) + light_vector;\n";
|
||||||
|
@ -785,8 +788,8 @@ static void WriteLighting(std::string& out, const PicaFSConfig& config) {
|
||||||
// If enabled, compute distance attenuation value
|
// If enabled, compute distance attenuation value
|
||||||
std::string dist_atten = "1.0";
|
std::string dist_atten = "1.0";
|
||||||
if (light_config.dist_atten_enable) {
|
if (light_config.dist_atten_enable) {
|
||||||
const std::string index = fmt::format("clamp({}.dist_atten_scale * length(-view - "
|
const std::string index = fmt::format("clamp({}.dist_atten_scale * light_distance "
|
||||||
"{}.position) + {}.dist_atten_bias, 0.0, 1.0)",
|
"+ {}.dist_atten_bias, 0.0, 1.0)",
|
||||||
light_src, light_src, light_src);
|
light_src, light_src, light_src);
|
||||||
const auto sampler = LightingRegs::DistanceAttenuationSampler(light_config.num);
|
const auto sampler = LightingRegs::DistanceAttenuationSampler(light_config.num);
|
||||||
dist_atten = fmt::format("LookupLightingLUTUnsigned({}, {})", sampler, index);
|
dist_atten = fmt::format("LookupLightingLUTUnsigned({}, {})", sampler, index);
|
||||||
|
|
|
@ -90,13 +90,12 @@ std::tuple<Common::Vec4<u8>, Common::Vec4<u8>> ComputeFragmentsColors(
|
||||||
|
|
||||||
float dist_atten = 1.0f;
|
float dist_atten = 1.0f;
|
||||||
if (!lighting.IsDistAttenDisabled(num)) {
|
if (!lighting.IsDistAttenDisabled(num)) {
|
||||||
auto distance = (-view - position).Length();
|
|
||||||
float scale = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32();
|
float scale = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32();
|
||||||
float bias = Pica::float20::FromRaw(light_config.dist_atten_bias).ToFloat32();
|
float bias = Pica::float20::FromRaw(light_config.dist_atten_bias).ToFloat32();
|
||||||
std::size_t lut =
|
std::size_t lut =
|
||||||
static_cast<std::size_t>(LightingRegs::LightingSampler::DistanceAttenuation) + num;
|
static_cast<std::size_t>(LightingRegs::LightingSampler::DistanceAttenuation) + num;
|
||||||
|
|
||||||
float sample_loc = std::clamp(scale * distance + bias, 0.0f, 1.0f);
|
float sample_loc = std::clamp(scale * length + bias, 0.0f, 1.0f);
|
||||||
|
|
||||||
u8 lutindex =
|
u8 lutindex =
|
||||||
static_cast<u8>(std::clamp(std::floor(sample_loc * 256.0f), 0.0f, 255.0f));
|
static_cast<u8>(std::clamp(std::floor(sample_loc * 256.0f), 0.0f, 255.0f));
|
||||||
|
|
Loading…
Reference in a new issue