{"id":75,"date":"2022-08-15T12:47:49","date_gmt":"2022-08-15T12:47:49","guid":{"rendered":"https:\/\/blogs.scummvm.org\/grisenti\/?p=75"},"modified":"2022-08-15T12:47:49","modified_gmt":"2022-08-15T12:47:49","slug":"finishing-shaders","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/grisenti\/2022\/08\/15\/finishing-shaders\/","title":{"rendered":"Finishing shaders"},"content":{"rendered":"<p><span data-contrast=\"auto\">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 <code>tex2DProj<\/code> function of the CG shader language. Thought, after some time, I tried to modify the original game\u2019s shaders in the same way and testing them on the original game. This didn\u2019t 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\u2019s 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\u2019t meant to be used, with the problem being a missing conditional.<\/span><\/p>\n<figure id=\"attachment_76\" aria-describedby=\"caption-attachment-76\" style=\"width: 820px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-76\" src=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/correct_shaders.png\" alt=\"the game on the highest setting in ScummVM\" width=\"820\" height=\"655\" srcset=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/correct_shaders.png 820w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/correct_shaders-300x240.png 300w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/correct_shaders-768x613.png 768w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><figcaption id=\"caption-attachment-76\" class=\"wp-caption-text\">the game now on the highest settings in ScummVM<\/figcaption><\/figure>\n<p><span data-contrast=\"auto\">Next, I worked on implementing the material classes for the lower-level setting (<code>Material_Fallback(01|02)_BaseLight<\/code>). The main purpose of these was to support systems that couldn\u2019t use fragment shaders or with few texture units (the number of textures that can be accessed in shaders), with <em>low<\/em> 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\u2019s 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. <\/span><\/p>\n<p><span data-contrast=\"auto\">This happened because, when shaders weren\u2019t used, the diffuse textures were multiplied by a color that reduced the overall brightness,\u00a0 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. \u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<figure id=\"attachment_78\" aria-describedby=\"caption-attachment-78\" style=\"width: 820px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-78 size-full\" src=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/medium_settings.png\" alt=\"game in the medium setting\" width=\"820\" height=\"655\" srcset=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/medium_settings.png 820w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/medium_settings-300x240.png 300w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/medium_settings-768x613.png 768w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><figcaption id=\"caption-attachment-78\" class=\"wp-caption-text\">game in the <em>medium<\/em> setting<\/figcaption><\/figure>\n<figure id=\"attachment_77\" aria-describedby=\"caption-attachment-77\" style=\"width: 820px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-77\" src=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/low_settings.png\" alt=\"game on low settings\" width=\"820\" height=\"655\" srcset=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/low_settings.png 820w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/low_settings-300x240.png 300w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/low_settings-768x613.png 768w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><figcaption id=\"caption-attachment-77\" class=\"wp-caption-text\">the game on the <em>low<\/em> setting<\/figcaption><\/figure>\n<p><span data-contrast=\"auto\">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. <\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Next week I\u2019ll try to fix some bugs with the physics system and probably start working on saves. <\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;201341983&quot;:0,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559685&quot;:0,&quot;335559737&quot;:0,&quot;335559738&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Thanks for reading. <\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;201341983&quot;:0,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559685&quot;:0,&quot;335559737&quot;:0,&quot;335559738&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":1,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":79,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts\/75\/revisions\/79"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}