Finishing shaders

This week I worked on shaders, fixing bugs from previous weeks. The first of these was a missing light on the right side of the room. This was a general problem that effected all spotlights (implemented with projective texture mapping), including the flashlight that can be picked up in the first level. Initially I thought the problem was related to a wrong translation of the tex2DProj function of the CG shader language. Thought, after some time, I tried to modify the original game’s shaders in the same way and testing them on the original game. This didn’t reproduce the problem, so I knew I was looking in the wrong place. Turns out the issue was related to the order of the elements in the engine’s matrices. This was easily fixed by adding a transpose before passing the matrices to the GLSL shaders. This had gone unnoticed until now because other matrices are not passed directly but by other means and for which a transpose was done earlier in the process. The next bug was related to fog shaders for which I was very confused by the fact that both textures and other uniforms appeared to be incorrect or missing. This was because the shader wasn’t meant to be used, with the problem being a missing conditional.

the game on the highest setting in ScummVM
the game now on the highest settings in ScummVM

Next, I worked on implementing the material classes for the lower-level setting (Material_Fallback(01|02)_BaseLight). The main purpose of these was to support systems that couldn’t use fragment shaders or with few texture units (the number of textures that can be accessed in shaders), with low requiring at least two. Implementing these was not as easy as I initially thought it would be. To replace the fragment shaders, the engine used either an ATI extension if this was supported or alternatively by specifying, through standard OpenGL, how the various textures would be combined. To overcome the low number of texture units, multiple passes are used (where, for example, the first pass is used to compute the light and the second to sample the object’s diffuse texture), and their results combined. At first, I had some difficulties understanding which texture to use at the various stages, and after that there was a problem of everything being too bright.

This happened because, when shaders weren’t used, the diffuse textures were multiplied by a color that reduced the overall brightness,  but when using shaders this was ignored. The issue was present only in the lower settings, while on the highest another mechanism was used. Since this was compatible with the constraints of the lower settings, I applied it to them as well.   

game in the medium setting
game in the medium setting
game on low settings
the game on the low setting

This week I also worked on implementing a limit for the audio tracks that are allowed to play at once. This was done to prevent the mixer from running out of available slots.  

Next week I’ll try to fix some bugs with the physics system and probably start working on saves.  

Thanks for reading.   

Leave a Reply

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