Module: Mesa
Branch: main
Commit: e2927dd5e76454279d464b92eeb810515e42f2b9
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=e2927dd5e76454279d464b92eeb810515e42f2b9

Author: Charmaine Lee <[email protected]>
Date:   Wed May 31 08:26:32 2023 +0300

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 <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23404>

---

 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),

Reply via email to