{"id":49,"date":"2014-06-27T14:22:09","date_gmt":"2014-06-27T14:22:09","guid":{"rendered":"https:\/\/blogs.scummvm.org\/akz\/?p=49"},"modified":"2022-03-31T19:54:11","modified_gmt":"2022-03-31T19:54:11","slug":"stans-confusing-coat","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/akz\/2014\/06\/27\/stans-confusing-coat\/","title":{"rendered":"Stan&#8217;s confusing coat"},"content":{"rendered":"<p>My recent\u00a0<a href=\"https:\/\/github.com\/residualvm\/residualvm\/pull\/938\">sprite fixes PR<\/a>\u00a0includes a change that fixes the appearance of Stan (see the GitHub issue\u00a0<a href=\"https:\/\/github.com\/residualvm\/residualvm\/issues\/874\">here<\/a>). I found the method they used to produce the unmoving plaid effect quite interesting, so here&#8217;s a quick summary.<\/p>\n<p><a href=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-35-40-97.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-51\" src=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-35-40-97-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-35-40-97-300x225.png 300w, https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-35-40-97.png 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>This is the final composition for reference. Note Stan&#8217;s trademark: the pattern on his jacket does not obey perspective. Although the effect looks simple, achieving this result with fixed-function OpenGL is actually not very straightforward. Let&#8217;s see how this image is produced.<\/p>\n<p><a href=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-21-59-57.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-52\" src=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-21-59-57-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-21-59-57-300x225.png 300w, https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-21-59-57.png 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>If we render the first background layer only, we can make an interesting observation. A rectangle covered with the check pattern of Stan&#8217;s jacket is part of the background. It covers all of Stan&#8217;s screen-space area. Stan moves back and forth during dialogue, but never leaves the area covered by this rectangle.<\/p>\n<p><a href=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-17-51-70.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-50\" src=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-17-51-70-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-17-51-70-300x225.png 300w, https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-17-51-70.png 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Here is a render with only the character models on a black background. We can immediately see that the jacket is not part of the model. Instead, Stan has a fully transparent texture where the jacket should be, so we can see through him. The transparent jacket is still drawn to the depth buffer, though.<\/p>\n<p><a href=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-29-32-01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-53\" src=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-29-32-01-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-29-32-01-300x225.png 300w, https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-29-32-01.png 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>If we combine the first background layer and the character models we get a result like above. Since Stan&#8217;s model is partly transparent we can see the check-patterned background through him. Obviously something still needs to be done about the rest of the rectangle surrounding him.<\/p>\n<p><a href=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-29-49-92.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-54\" src=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-29-49-92-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-29-49-92-300x225.png 300w, https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-29-49-92.png 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Above is an additional render with the rest of the background layers enabled. The desk is part of a background layer that is drawn over Stan, covering his legs. This image is similar to what ResidualVM produced before my fixes.<\/p>\n<p><a href=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-33-24-62.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-55\" src=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-33-24-62-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-33-24-62-300x225.png 300w, https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/residualvm-2014-06-27-21-33-24-62.png 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Here&#8217;s the trick. A sprite is rendered behind Stan, but over the background layer. I highlighted the sprite with red color in the above screenshot to make it stand out from the rest of the background. The sprite contains a chunk of the &#8220;real&#8221; background without the check-patterned rectangle. Since the sprite is drawn with depth test enabled, the sprite only covers Stan&#8217;s surroundings but not Stan himself.<\/p>\n<p>This sprite was previously not drawn at all in ResidualVM, so the check-patterned rectangle was not replaced by the correct background around Stan.<\/p>\n<p>This method works nicely since the backgrounds are static and the camera never moves. Other than a bit of overdraw, there&#8217;s also no additional rendering cost.<\/p>\n<p><a href=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/stan2.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56\" src=\"https:\/\/blogs.scummvm.org\/akz\/wp-content\/uploads\/sites\/12\/2022\/03\/stan2.gif\" alt=\"\" width=\"320\" height=\"213\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>My recent\u00a0sprite fixes PR\u00a0includes a change that fixes the appearance of Stan (see the GitHub issue\u00a0here). I found the method they used to produce the unmoving plaid effect quite interesting, so here&#8217;s a quick summary. This is the final composition for reference. Note Stan&#8217;s trademark: the pattern on his jacket does not obey perspective. Although [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":2,"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":58,"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/posts\/49\/revisions\/58"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/akz\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}