Debugging shaders

At the start of this week, graphics with shaders were extremely broken. There were mainly two causes of this. The first was that one of the shader class member functions to set uniform matrices was implemented incorrectly.  The other problem was in the shader code. Right now, all of the vertex shaders attributes come from pre-defined attributes. For example, gl_Vertex is a 4-component vector containing the vertex position and gl_Color contains the vertex color if it has been set. This feature has been deprecated in the more recent version of GLSL but it’s still available in GLSL 1.2, the version being used in the project. The issue was that I thought that the texture coordinates attributes were placed in gl_TexCoord[n], but this variable is used to store the texture coordinates and pass them to the fragment shader, so it doesn’t contain any data. The correct variable was gl_MultiTexCoordn (where the last n is the id of the texture coordinate).  

After solving the previous two, the game was finally playable but with a considerable visual difference from the original.  

picture of the original game
original game
picture of the game in ScummVM
game in ScummVM

The other problems I found were due to incorrect translation of the original shaders, but these didn’t result in much difference in visual output. Unfortunately, I couldn’t find the other problems and for now I moved onto other issues.  

On a side note, a helpful tool I used to complete most of the shader debugging has been the Nvidia Nsight graphics debugger. Initially I couldn’t set it up (having sanitizers enabled was one of the problems), and tried to work without it, but I found it almost impossible to guess what the issues where. 

picture of the nvidia Nsight debugger

After graphics I moved onto the audio system. The engine used OpenAL with an open-source wrapper also made by Frictional games. ScummVM doesn’t have an equivalent system, but for now I will implement just the simple features, ignoring more complex audio modifiers.  

Next week I’ll keep working on audio and maybe something else, thought I haven’t made any plans yet.  

Leave a Reply

Your email address will not be published. Required fields are marked *