From e2927dd5e76454279d464b92eeb810515e42f2b9 Mon Sep 17 00:00:00 2001 From: Charmaine Lee Date: Wed, 31 May 2023 08:26:32 +0300 Subject: [PATCH] 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: c5b3d488f9be ("mesa/main: make ffvertex output nir") Reviewed-by: Erik Faye-Lund Part-of: --- src/mesa/main/ffvertex_prog.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index 56af49147f5..0a0cbcbc4e1 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -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),