{"id":64,"date":"2022-08-01T12:19:49","date_gmt":"2022-08-01T12:19:49","guid":{"rendered":"https:\/\/blogs.scummvm.org\/grisenti\/?p=64"},"modified":"2022-08-01T12:19:49","modified_gmt":"2022-08-01T12:19:49","slug":"debugging-shaders","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/grisenti\/2022\/08\/01\/debugging-shaders\/","title":{"rendered":"Debugging shaders"},"content":{"rendered":"<p><span data-contrast=\"auto\">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.\u00a0 The other problem was in the shader code. Right now, all of the vertex shaders attributes come from pre-defined attributes. For example, <code>gl_Vertex<\/code> is a 4-component vector containing the vertex position and <code>gl_Color<\/code> contains the vertex color if it has been set. This feature has been deprecated in the more recent version of GLSL but it&#8217;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 <code>gl_TexCoord[n]<\/code>, but this variable is used to store the texture coordinates and pass them to the fragment shader, so it doesn&#8217;t contain any data. The correct variable was <code>gl_MultiTexCoordn<\/code> (where the last n is the id of the texture coordinate).\u00a0<\/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\">After solving the previous two, the game was finally playable but with a considerable visual difference from the original.\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_65\" aria-describedby=\"caption-attachment-65\" style=\"width: 380px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-65\" src=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/original_game.png\" alt=\"picture of the original game\" width=\"380\" height=\"238\" srcset=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/original_game.png 1920w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/original_game-300x188.png 300w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/original_game-1024x640.png 1024w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/original_game-768x480.png 768w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/original_game-1536x960.png 1536w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/original_game-1200x750.png 1200w\" sizes=\"auto, (max-width: 380px) 100vw, 380px\" \/><figcaption id=\"caption-attachment-65\" class=\"wp-caption-text\">original game<\/figcaption><\/figure>\n<figure id=\"attachment_67\" aria-describedby=\"caption-attachment-67\" style=\"width: 378px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-67\" src=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/game_in_scummvm.png\" alt=\"picture of the game in ScummVM\" width=\"378\" height=\"302\" srcset=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/game_in_scummvm.png 820w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/game_in_scummvm-300x240.png 300w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/game_in_scummvm-768x613.png 768w\" sizes=\"auto, (max-width: 378px) 100vw, 378px\" \/><figcaption id=\"caption-attachment-67\" class=\"wp-caption-text\">game in ScummVM<\/figcaption><\/figure>\n<p><span data-contrast=\"auto\">The other problems I found were due to incorrect translation of the original shaders, but these didn\u2019t result in much difference in visual output.\u00a0Unfortunately, I couldn\u2019t find the other problems and for now I moved onto other issues. <\/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\">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\u2019t set it up (having sanitizers enabled was one of the <span class=\"TextRun SCXW70250888 BCX2\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW70250888 BCX2\">problems<\/span><\/span>), and tried to work without it, but I found it almost impossible to guess what the issues where.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\"> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-68\" src=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/Nsight_debugger.png\" alt=\"picture of the nvidia Nsight debugger\" width=\"550\" height=\"225\" srcset=\"https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/Nsight_debugger.png 3440w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/Nsight_debugger-300x123.png 300w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/Nsight_debugger-1024x419.png 1024w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/Nsight_debugger-768x314.png 768w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/Nsight_debugger-1536x628.png 1536w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/Nsight_debugger-2048x837.png 2048w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/Nsight_debugger-1200x490.png 1200w, https:\/\/blogs.scummvm.org\/grisenti\/wp-content\/uploads\/sites\/53\/2022\/08\/Nsight_debugger-1980x809.png 1980w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/span><\/p>\n<p><span data-contrast=\"auto\">After graphics I moved onto the audio system. The engine used OpenAL with an open-source wrapper also made by Frictional games. ScummVM doesn\u2019t have an equivalent system, but for now I will implement just the simple features, ignoring more complex audio modifiers.\u00a0<\/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 keep working on audio and maybe something else, thought I haven\u2019t made any plans yet.\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>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.\u00a0 The other problem was in the shader code. Right now, all of the vertex shaders attributes come from [&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-64","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts\/64","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=64"}],"version-history":[{"count":1,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":69,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/posts\/64\/revisions\/69"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/grisenti\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}