{"id":89,"date":"2018-07-22T18:46:10","date_gmt":"2018-07-22T18:46:10","guid":{"rendered":"https:\/\/blogs.scummvm.org\/douglas\/?p=89"},"modified":"2022-05-24T18:49:01","modified_gmt":"2022-05-24T18:49:01","slug":"residualvm-week-10","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/douglas\/2018\/07\/22\/residualvm-week-10\/","title":{"rendered":"ResidualVM: Week 10"},"content":{"rendered":"<div>And I said: &#8220;Let there be shadows!&#8221; And there are shadows. Just, not good enough&#8230;<\/div>\n<div><\/div>\n<div>So, from this week till the end of GSoC I guess I&#8217;ll be dealing with OpenGL. As a newbie to computer graphics, I would be lying if I say that I am not worried at all. I once believed that OpenGL hated me, it hated me so much that it didn&#8217;t even want me to render a tessellated triangle on the screen. But that hard time is passed now and I am happy that I start to get along well with OpenGL, and it is kind enough to let me produce something physical this week.<\/div>\n<div><\/div>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img decoding=\"async\" src=\"https:\/\/blogs.scummvm.org\/douglas\/wp-content\/uploads\/sites\/63\/2022\/05\/shadow.png\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Ah, the shadow.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>\nOkay, shadows. Actually what I have done so far is based on my previous wrong assumption about shadows in\u00a0<i>The Longest Journey<\/i>. In most of the scenes I have played, which is not many actually, characters have\u00a0shadows that look like they are cast from above.\u00a0<i>The Longest Journey<\/i>\u00a0is a 2.5D game with 3D characters and 2D backgrounds, so, in my personal perspective as a CG newbie, it won&#8217;t be that intuitive to perform a full shadow casting technique like the Shadow Mapping here. But if shadows are just cast from above, then things are a lot simpler.<\/div>\n<div><\/div>\n<div>So, with this &#8220;wrong&#8221; assumption, and the fact that the original game doesn&#8217;t seem to have complex and realistic shadows, I decided to use the simplest shadow casting technique: Planar Shadow. Basically, it just squishes the modal onto a surface and paints it grey. Since I just want to cast the shadow from above, the squishing is even easier. Below is a screenshot when I was testing how I could squish the model.<\/div>\n<div><\/div>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img decoding=\"async\" src=\"https:\/\/blogs.scummvm.org\/douglas\/wp-content\/uploads\/sites\/63\/2022\/05\/squish.png\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">April: I don&#8217;t feel so good&#8230;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div><\/div>\n<div>That&#8217;s not the whole story. A good shadow should be semi-transparent. But simply enable blending is not enough since transparent faces will cover on each other, and there will be the Z-fighting problem. The solution is intuitive though: stencil test. With the enabling of the stencil test and proper manipulation on the stencil buffer (no two shadow fragments can be drawn on the same location), a nice semi-transparent shadow is produced.<\/div>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img decoding=\"async\" src=\"https:\/\/blogs.scummvm.org\/douglas\/wp-content\/uploads\/sites\/63\/2022\/05\/code.png\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Blending and Stencil Tet<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>\nWell, like I said before, this is a wrong assumption.\u00a0<i>The Longest Journey<\/i>\u00a0does compute shadows from existing lights. And there are three types of light in the game: point light, directional light and spotlight. Luckily lights only contribute to the length of the shadow, so right now I think the Planar Shadow technique can still be used.<\/div>\n<div><\/div>\n<div>From the look of it right now, I guess it is time for some linear algebra. More updates will come next week.<\/p>\n<div>All code snippets are generated through\u00a0<a href=\"https:\/\/carbon.now.sh\/\">Carbon<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>And I said: &#8220;Let there be shadows!&#8221; And there are shadows. Just, not good enough&#8230; So, from this week till the end of GSoC I guess I&#8217;ll be dealing with OpenGL. As a newbie to computer graphics, I would be lying if I say that I am not worried at all. I once believed that [&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-89","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":1,"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/posts\/89\/revisions\/90"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/douglas\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}