Bug 84155

Summary: Incorrect fog of war effect in Wasteland 2
Product: Mesa Reporter: tristen.hayfield
Component: Drivers/DRI/i965Assignee: Ian Romanick <idr>
Status: RESOLVED NOTOURBUG QA Contact: Intel 3D Bugs Mailing List <intel-3d-bugs>
Severity: normal    
Priority: medium CC: bfroemel, cravchik, dmitrenko1985, fdo, francois, gok+freedesktopbugs, jajcus, jonathan.cole, martin, pclouds, ufoot, zecoucou
Version: git   
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 77449    
Attachments: Wasteland 2 Apitrace
Game world displayed all black in Wasteland 2 travel mode

Description tristen.hayfield 2014-09-22 01:29:47 UTC
In the game Wasteland 2, there is a travel mode where the player travels from location to location across a 3D map. The unexplored areas of the map are obscured by a fog-of-war type effect which appears to be achieved by projecting a black texture onto the surface of the unexplored regions. Unfortunately, with the Intel driver, for some reason the black texture is not getting projected onto the surface but instead floats in front of the camera.

At the very least, the software renderer produces the correct result. When I run the program with LIBGL_ALWAYS_SOFTWARE set, the fog-of-war/shadow effect is rendered correctly.

This problem appears to be exclusive to the Linux Intel HD Graphics driver as no users of other drivers are reporting this issue.
Comment 1 Jacek Konieczny 2014-09-22 11:08:08 UTC
Here is a link to the discussion on the Wasteland 2 forums:

https://wasteland.inxile-entertainment.com/forum/viewtopic.php?f=34&t=8553
Comment 2 Tapani Pälli 2014-09-23 08:22:18 UTC
Reproduced this on Haswell, it looks like the "fog of war" layer gets projected in wrong position. Will check how GLSL looks like.
Comment 3 Tapani Pälli 2014-09-23 08:30:38 UTC
(In reply to comment #2)
> Reproduced this on Haswell, it looks like the "fog of war" layer gets
> projected in wrong position. Will check how GLSL looks like.

and perhaps in way too low resolution (?) with sw rendering the resolution seems much much more crisp
Comment 4 tristen.hayfield 2014-09-23 09:29:48 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Reproduced this on Haswell, it looks like the "fog of war" layer gets
> > projected in wrong position. Will check how GLSL looks like.
> 
> and perhaps in way too low resolution (?) with sw rendering the resolution
> seems much much more crisp

It might not be a low resolution issue, it could just be the fact that camera is now way too close to the layer.

Also this bug affects the normal gameplay outside of travel mode. The edges of the map also seem to use this effect to darken its boundaries. If the camera strays too close to the map edge, the incorrectly-projected dark layer will block the camera.
Comment 5 Tapani Pälli 2014-09-23 12:16:32 UTC
For some reason I cannot get the game to launch from cmdline and therefore cannot make an apitrace, would be cool to get one to see what is happening from API perspective. I did not spot anything obvious in the first glance to the shaders, they are written for compatibility profile (using gl_ModelViewProjectionMatrix and so on), GL_ARB_shader_texture_lod extension is enabled in many of them.
Comment 6 tristen.hayfield 2014-09-23 12:53:25 UTC
(In reply to comment #5)
> For some reason I cannot get the game to launch from cmdline and therefore
> cannot make an apitrace, would be cool to get one to see what is happening
> from API perspective. I did not spot anything obvious in the first glance to
> the shaders, they are written for compatibility profile (using
> gl_ModelViewProjectionMatrix and so on), GL_ARB_shader_texture_lod extension
> is enabled in many of them.

I can launch it from the command line no problem. How are you trying to launch it?
Comment 7 Tapani Pälli 2014-09-23 13:18:06 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > For some reason I cannot get the game to launch from cmdline and therefore
> > cannot make an apitrace, would be cool to get one to see what is happening
> > from API perspective. I did not spot anything obvious in the first glance to
> > the shaders, they are written for compatibility profile (using
> > gl_ModelViewProjectionMatrix and so on), GL_ARB_shader_texture_lod extension
> > is enabled in many of them.
> 
> I can launch it from the command line no problem. How are you trying to
> launch it?

I have Steam running on the background, I'll set LD_LIBRARY_PATH for Steam libraries and just launch it. Mono prints a few lines indicating that correct paths are found and I see X window created but then it just exits without any erorr.
Comment 8 Christian Mauduit 2014-09-23 16:08:05 UTC
Having the very same problem here, if you need tracebacks, logs, whatever, just ask, hardware is haswell with intel HD 5200.
Comment 9 tristen.hayfield 2014-09-23 17:38:17 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > For some reason I cannot get the game to launch from cmdline and therefore
> > > cannot make an apitrace, would be cool to get one to see what is happening
> > > from API perspective. I did not spot anything obvious in the first glance to
> > > the shaders, they are written for compatibility profile (using
> > > gl_ModelViewProjectionMatrix and so on), GL_ARB_shader_texture_lod extension
> > > is enabled in many of them.
> > 
> > I can launch it from the command line no problem. How are you trying to
> > launch it?
> 
> I have Steam running on the background, I'll set LD_LIBRARY_PATH for Steam
> libraries and just launch it. Mono prints a few lines indicating that
> correct paths are found and I see X window created but then it just exits
> without any erorr.

Try running it with gdb on the off chance it catches the error. 

I have the correct dependencies installed on my system so that I can run it without steam.

I would have provided you with an apitrace but I have to first cross compile it for 32 bit along with all of the dependencies, which is annoying. I will look into it.
Comment 10 Jonathan Cole 2014-09-24 10:34:45 UTC
Created attachment 106782 [details]
Wasteland 2 Apitrace

I am attaching a dumped to text copy of the apitrace output for running Wasteland 2 (Steam version).

Started, loaded game, moved in and out of problem fog area a few times and quit.

I have the full trace if required, but it is 812 MB
Comment 11 Peter Tworek 2014-09-26 20:00:31 UTC
If somebody is interested in full trace output mine is available at http://www.tworaz.net/downloads/wasteland2/WL2.trace.xz.
Comment 12 Coucouf 2014-09-26 22:54:39 UTC
There’s also a Steam thread with several affected users :
http://steamcommunity.com/app/240760/discussions/1/613936673392885026/
Comment 13 Jacek Konieczny 2014-09-27 18:38:04 UTC
There is a notable information on the forum linked above: there is a workaround for the problem: MESA_EXTENSION_MAX_YEAR=2002
Works for me, though there is not fog of war and graphics is a bit worse, as expected.
Comment 14 Matt Turner 2014-09-27 19:46:58 UTC
(In reply to comment #13)
> There is a notable information on the forum linked above: there is a
> workaround for the problem: MESA_EXTENSION_MAX_YEAR=2002
> Works for me, though there is not fog of war and graphics is a bit worse, as
> expected.

Looking at src/mesa/main/extensions.c's table of extensions, these two extensions from 2003 seem like plausible culprits:

GL_ARB_fragment_program_shadow
GL_ARB_shading_language_100

Running the apitrace shows no GLSL programs (except for driver internal clear shaders). We do, however have a couple instances of GL_ARB_fragment_program_shadow.
Comment 15 Matt Turner 2014-09-27 20:14:17 UTC
(In reply to comment #14)
> Running the apitrace shows no GLSL programs (except for driver internal
> clear shaders).

Spoke too soon. I was searching for #version, which GL_ARB_shading_language_100 doesn't need.

Could someone test with

 MESA_EXTENSION_OVERRIDE=-GL_ARB_shading_language_100

 MESA_EXTENSION_OVERRIDE=-GL_ARB_fragment_program_shadow

and see which (if either) affects the bug?
Comment 16 Coucouf 2014-09-27 23:16:28 UTC
Neither of the extensions have any effect for me.
But exporting MESA_EXTENSION_MAX_YEAR=2002 does let the travel mode display without being all black.

By the way the interface is always displayed, even when the game world is all black if that’s of any use.
Comment 17 Coucouf 2014-09-27 23:17:48 UTC
Created attachment 106974 [details]
Game world displayed all black in Wasteland 2 travel mode
Comment 18 Tapani Pälli 2014-09-29 05:56:23 UTC
I noticed that MESA_EXTENSION_OVERRIDE='-GL_ARB_texture_non_power_of_two' is a minimal workaround for this (this happens also when limiting extension to year 2002). This way the fog of war does not get rendered and you can use Mesa master to run the game. Unfortuntately I haven't been able to spot what the actual bug is so far :/
Comment 19 kentiq13 2014-09-29 10:34:45 UTC
Guys pleaes explain where i should insert this paremeters? (howto?) 

MESA_EXTENSION_MAX_YEAR=2002
or
MESA_EXTENSION_OVERRIDE='-GL_ARB_texture_non_power_of_two'
Comment 20 Darius Spitznagel 2014-09-29 17:43:03 UTC
(In reply to comment #19)
> Guys pleaes explain where i should insert this paremeters? (howto?) 
> 
> MESA_EXTENSION_MAX_YEAR=2002
> or
> MESA_EXTENSION_OVERRIDE='-GL_ARB_texture_non_power_of_two'

The easiest way is to put it into the startoptions of wasteland 2 inside your steam client like this...

MESA_EXTENSION_MAX_YEAR=2002 %command%

or

MESA_EXTENSION_OVERRIDE='-GL_ARB_texture_non_power_of_two' %command%

Then simply run the game.
Comment 21 dave lepore 2014-10-08 14:06:58 UTC
Both the proposed workarounds break the energy weapons shooting effect: instead of a distorsion some black geometric figures are displayed.
Comment 22 Trigrab 2015-05-07 09:22:54 UTC
I play a game which is also using unity3d to render fog of war, where a similar bug appears only with intel graphicscards. The Games name is War for the Overworld. Maybe we could get information from the unity3d developers, which function they use, to isolate the problem of the driver.
Comment 23 Tapani Pälli 2015-05-11 06:55:26 UTC
Seems to me that this problem may have been fixed either by changes to the game or changes to Mesa (tested using current Mesa git head abf3fef).

Could someone else verify? It is probably enough to try with latest oibaf-ppa if using Ubuntu.
Comment 24 Tapani Pälli 2015-05-11 07:00:58 UTC
(In reply to Tapani Pälli from comment #23)
> Seems to me that this problem may have been fixed either by changes to the
> game or changes to Mesa (tested using current Mesa git head abf3fef).
> 
> Could someone else verify? It is probably enough to try with latest
> oibaf-ppa if using Ubuntu.

Huh sorry, this was not true, I just realized I had following environment variable turned on:

UNITY_DISABLE_GRAPHICS_DRIVER_WORKAROUNDS=yes

This seems to make the bug disappear, this means the bug is most probably in Unity engine. Could someone else try if this fixes the issue for you?
Comment 25 Trigrab 2015-05-11 13:30:24 UTC
(In reply to Tapani Pälli from comment #24)
> (In reply to Tapani Pälli from comment #23)
> > Seems to me that this problem may have been fixed either by changes to the
> > game or changes to Mesa (tested using current Mesa git head abf3fef).
> > 
> > Could someone else verify? It is probably enough to try with latest
> > oibaf-ppa if using Ubuntu.
> 
> Huh sorry, this was not true, I just realized I had following environment
> variable turned on:
> 
> UNITY_DISABLE_GRAPHICS_DRIVER_WORKAROUNDS=yes
> 
> This seems to make the bug disappear, this means the bug is most probably in
> Unity engine. Could someone else try if this fixes the issue for you?

I tested it on a different unity3d game with a similar fog of war bug and it worked. Unfortunately I don't have wasteland2 to test it there.
Comment 26 Christian Mauduit 2015-05-11 20:12:44 UTC
Tested the env :

UNITY_DISABLE_GRAPHICS_DRIVER_WORKAROUNDS=yes

on a GNU/Linux box on which this FOV bug was clearly visible : it did fix the problem. Saw no side effects so far, but OTOH just ran the game for 3 minutes.

Thanks for the tip, did help me.
Comment 27 Tapani Pälli 2015-05-12 12:10:09 UTC
Per the recent comments I'm resolving this as NOTOURBUG.
Comment 28 Matt Turner 2015-05-12 17:59:33 UTC
Could we add a driconf workaround?
Comment 29 Kenneth Graunke 2015-05-18 18:33:51 UTC
I'm not really sure how - the fix isn't changing our behavior, it's asking Unity to change it's behavior.  Unity loads libGL, so it seems unlikely we could setenv() and have it affect them even if we wanted to.

Unity 4 based games could include this in their shell wrappers, while waiting for a proper fix:

if glxinfo | grep -q 'Intel Open Source Technology Center'; then export UNITY_DISABLE_GRAPHICS_DRIVER_WORKAROUNDS=yes; fi

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.