{"id":2041,"date":"2015-02-05T21:58:00","date_gmt":"2015-02-05T21:58:00","guid":{"rendered":"http:\/\/www.spellcasterstudios.com\/?p=2041"},"modified":"2015-01-31T21:14:49","modified_gmt":"2015-01-31T21:14:49","slug":"whats-life-without-some-problems","status":"publish","type":"post","link":"https:\/\/www.spellcasterstudios.com\/?p=2041","title":{"rendered":"What&rsquo;s life without some problems?!&hellip;"},"content":{"rendered":"<p align=\"justify\">Well\u2026 Just finished implementing decals\u2026 It went better than expected, since I\u2019ve never tried implementing screen-space decals before\u2026<\/p>\n<p align=\"justify\"><a href=\"http:\/\/www.spellcasterstudios.com\/wp-content\/uploads\/2015\/01\/screen424.jpg\" class=\"thickbox\"><img loading=\"lazy\" decoding=\"async\" title=\"screen424\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"screen424\" src=\"http:\/\/www.spellcasterstudios.com\/wp-content\/uploads\/2015\/01\/screen424_thumb.jpg\" width=\"830\" height=\"482\" \/><\/a><\/p>\n<p align=\"justify\">The main difficulty of screen-space decals is the occlusion. Most of the code is related to this, and mine is working great:<\/p>\n<p align=\"justify\"><a href=\"http:\/\/www.spellcasterstudios.com\/wp-content\/uploads\/2015\/01\/screen425.jpg\" class=\"thickbox\"><img loading=\"lazy\" decoding=\"async\" title=\"screen425\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"screen425\" src=\"http:\/\/www.spellcasterstudios.com\/wp-content\/uploads\/2015\/01\/screen425_thumb.jpg\" width=\"830\" height=\"482\" \/><\/a><\/p>\n<p align=\"justify\">One problem I\u2019m already seeing is the fact that the way the decal maps removes a bit of the volume of the scene in the affected area\u2026 Not sure if the problem is the texture (need to run tests), or if the UV mapping is not correct (but it seems to be, at least on this kind of \u201corthographic\u201d decal, if it was a perspective decal, the contour of the underlying terrain might be more noticeable). This can also be minimized by using some sort of smoothing of the blend based on the angle of the underlying normal and the decal normal.<\/p>\n<p align=\"justify\">I have more serious issues, though, namely the alpha objects:<\/p>\n<p align=\"justify\"><a href=\"http:\/\/www.spellcasterstudios.com\/wp-content\/uploads\/2015\/01\/screen426.jpg\" class=\"thickbox\"><img loading=\"lazy\" decoding=\"async\" title=\"screen426\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"screen426\" src=\"http:\/\/www.spellcasterstudios.com\/wp-content\/uploads\/2015\/01\/screen426_thumb.jpg\" width=\"830\" height=\"482\" \/><\/a><\/p>\n<p align=\"justify\">They get rendered \u201cbehind\u201d the decal\u2026 The reason for this is very simple: the decal is completely drawn based on the existing depth, and the alpha objects usually don\u2019t draw to depth, which means that from the decal rendering point of view, they simply aren\u2019t there\u2026 This is a tricky one to solve\u2026<\/p>\n<p align=\"justify\">The other one has another reason for it, but it\u2019s also as tricky to solve:<\/p>\n<p align=\"justify\"><a href=\"http:\/\/www.spellcasterstudios.com\/wp-content\/uploads\/2015\/01\/screen427.jpg\" class=\"thickbox\"><img loading=\"lazy\" decoding=\"async\" title=\"screen427\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"screen427\" src=\"http:\/\/www.spellcasterstudios.com\/wp-content\/uploads\/2015\/01\/screen427_thumb.jpg\" width=\"830\" height=\"482\" \/><\/a><\/p>\n<p align=\"justify\">\n<p align=\"justify\">Here, the sprite is drawn on the depth map, but the decal is still rendered \u201con top\u201d of it\u2026 Here the issue is the fact that the decal act as sort of \u201cprojector\u201d that affects EVERYTHING in the scene, including the player\u2026 Of course, this isn\u2019t the goal (most of the time\u2026)<\/p>\n<p align=\"justify\">Not sure exactly how I can solve this issue\u2026 One solution is to render to a stencil map what can or not be affected by the decals\u2026 Basically, I\u2019d set on the stencil buffer to 1 in all the static geometry (which I want affected by the decals), and to 0 all the dynamic stuff (or more precisely, just don\u2019t draw to the stencil buffer).<\/p>\n<p align=\"justify\">This is not a very elegant solution in my opinion because it requires me to render to another buffer, but in all honesty, I don\u2019t see any way around it: the decals need to be aware where they can be drawn in screen-space. From a perfomance point of view this can be made quite fast with a Z-equal test, no color or z-writes, and choosing the objects I\u2019m interested in \u201cdecaling\u201d.<\/p>\n<p align=\"justify\">The good news is that they are rather fast (at least on my PC) and on static geometry they work as a charm!<\/p>\n<p align=\"justify\"><em>Now listening to \u201cSongs from a Room\u201d by \u201cLeonard Cohen\u201d<\/em><\/p>\n<p align=\"justify\"><em>Link of the Day: I\u2019m not a big fan of online competitive games, so I\u2019m not seeing myself playing this one, but it looks extremely cool: <a title=\"http:\/\/www.polygon.com\/2015\/1\/27\/7917991\/dreadnought-video-gameplay-preview\" href=\"http:\/\/www.polygon.com\/2015\/1\/27\/7917991\/dreadnought-video-gameplay-preview\">http:\/\/www.polygon.com\/2015\/1\/27\/7917991\/dreadnought-video-gameplay-preview<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well\u2026 Just finished implementing decals\u2026 It went better than expected, since I\u2019ve never tried implementing screen-space decals before\u2026 The main difficulty of screen-space decals is the occlusion. Most of the code is related to this, and mine is working great: One problem I\u2019m already seeing is the fact that the way the decal maps removes [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,147,8],"tags":[256,242],"class_list":["post-2041","post","type-post","status-publish","format-standard","hentry","category-development","category-chrome-hunter","category-technology","tag-decals","tag-polish"],"_links":{"self":[{"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/posts\/2041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2041"}],"version-history":[{"count":1,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/posts\/2041\/revisions"}],"predecessor-version":[{"id":2042,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=\/wp\/v2\/posts\/2041\/revisions\/2042"}],"wp:attachment":[{"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spellcasterstudios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}