NikolaiVChr / flightgear-saab-ja-37-viggen

Saab 37 Viggen for Flightgear flight simulator
http://wiki.flightgear.org/Saab_37_Viggen
GNU General Public License v2.0
26 stars 15 forks source link

TI specular shows RWR while off #175

Closed colingeniet closed 1 year ago

colingeniet commented 3 years ago

To reproduce:

colingeniet commented 1 year ago

I think this is caused by undefined behaviour in lcd.frag: in

    // apply contrast
    color.rgb = ((color.rgb - 0.5) * contrast) + 0.5;

    color = pow(color, gammaInv);
    color = color * gl_FrontMaterial.emission.rgb;

there is no guarantee that color is non-negative, and it is undefined behaviour if it is negative. Adding

diff --git a/Aircraft/JA37/Models/Effects/displays/lcd.frag b/Aircraft/JA37/Models/Effects/displays/lcd.frag
index 07159d78..1b91ddc3 100644
--- a/Aircraft/JA37/Models/Effects/displays/lcd.frag
+++ b/Aircraft/JA37/Models/Effects/displays/lcd.frag
@@ -79,6 +79,7 @@ void main (void) {

     // apply contrast
     color.rgb = ((color.rgb - 0.5) * contrast) + 0.5;
+    color = max(color, 0.0);

     color = pow(color, gammaInv);
     color = color * gl_FrontMaterial.emission.rgb;

solves the issue for me.

colingeniet commented 1 year ago

Should be fixed by https://github.com/NikolaiVChr/flightgear-saab-ja-37-viggen/commit/8774786c11a1653d2c655b012bfa1e495557dabd