mesa/main: fix distance attenuation calculation in ffvertex

The dist parameter to calculate_light_attenuation() is the
reciprocal of ||VP|| used in the distance attenuation formula (2.4).
So get its reciprocal first before applying it to the distance attenuation
formula.

This fixes a lighting issue in Knights of the Old Republic.

Fixes: c5b3d488f9 ("mesa/main: make ffvertex output nir")

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collaborar.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23404>
This commit is contained in:
Charmaine Lee 2023-05-31 08:26:32 +03:00 committed by Marge Bot
parent 049c791a63
commit e2927dd5e7

View file

@ -679,6 +679,12 @@ calculate_light_attenuation(struct tnl_program *p,
STATE_ATTENUATION, 0);
}
/* dist is the reciprocal of ||VP|| used in the distance
* attenuation formula. So need to get the reciprocal of dist first
* before applying to the formula.
*/
dist = nir_frcp(p->b, dist);
/* 1, d, d*d */
nir_ssa_def *tmp = nir_vec3(p->b,
nir_imm_float(p->b, 1.0f),