{"id":382,"date":"2011-02-18T18:45:00","date_gmt":"2011-02-18T17:45:00","guid":{"rendered":"http:\/\/shadowcovenant.com\/blog\/?p=382"},"modified":"2011-02-18T18:45:36","modified_gmt":"2011-02-18T17:45:36","slug":"shadowmap-lod","status":"publish","type":"post","link":"http:\/\/shadowcovenant.com\/blog\/2011\/02\/18\/shadowmap-lod\/","title":{"rendered":"Shadowmap LOD"},"content":{"rendered":"<p><a href=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2011\/02\/ShadowmapLOD1.jpg\" target=\"_blank\" ><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2011\/02\/ShadowmapLOD_preview1.jpg\" border=\"0\" hspace=\"8\" alt=\"ShadowmapLOD\" align=\"top\" width=\"480\" height=\"381\" \/><\/a><\/p>\n<p>This week I&rsquo;ve been working on the LOD system for the shadowmaps&#8230;<\/p>\n<p>Using the idea that I can have about 60-70 lights per area on the game, I can&rsquo;t update 1024&#215;1024 shadowmaps every frame&#8230; Well, I could, but I&rsquo;d get 0.5 FPS (I tested it for fun)&#8230;<\/p>\n<p>So, I decided to play with 4 variables:<\/p>\n<ol>\n<li>Multisampling: 16 samples per pixel take some time to render, even in today&rsquo;s video cards, so I can&rsquo;t have all lights multisampling<\/li>\n<li>Resolution: 1024&#215;1024 to 64&#215;64 shadowmaps give me quality on those that are near, but still have some quality on stuff that&rsquo;s far away<\/li>\n<li>Update rate: Updating all shadowmaps (even the 64&#215;64 ones) is slow, because of all the setup time, changing rendertargets, etc&#8230;<\/li>\n<li>Turning off shadows at a distance<\/li>\n<\/ol>\n<p>Number 4 got removed from my LOD algorithm. The reason for this is that in some angles, the difference in lighting is actually pretty big&#8230; the shadows are necessary to keep the light confined to the room where the light source is.<\/p>\n<p>So, what I do is that I do the nearest N1 lights with multisampling+256&#215;256 shadowmaps+update all frames, then I do N2 lights with 128&#215;128 shadowmaps+update every 4th frame, and so forth&#8230;<\/p>\n<p>On my test case, I have 120 lights, and I defined that I could do 10 updates per frame&#8230; I defined circa 22 categories with different resolutions and update rates, and I set the category of each light per frame, based on distance.<\/p>\n<p>On my video card (a NVidia GTX 465), I get about 200 FPS average with this scene (which is very simple, not many texture switches)&#8230; In a real case, this will of course not be the frame rate, with all the setup of objects, etc, but I still have some tricks up my sleeve (group up all static objects in a few DIP calls for shadowmap rendering, separating objects that might have alpha-test from the others so I don&rsquo;t need to use texture swaps, change the criteria of the lights, even going back to not having shadowmapping in lights that are too far away).<\/p>\n<p>Anyway, I&rsquo;m very happy with the results, specially considering that the game will not feature a camera so close to the shadows as on the above screenshot. This, combined with the ambient occlusion map rendering, will probably be a good rendering solution for the game.<\/p>\n<p>Now I&rsquo;m going back to work on the editor I&rsquo;ve been working on and off for one year&#8230; Never added 3d capabilities to it, so it will be a neat challenge, but I hope that in the next few weeks, my artist can start creating levels with decals and such stuff&#8230;<\/p>\n<p><iframe loading=\"lazy\" title=\"YouTube video player\" src=\"http:\/\/www.youtube.com\/embed\/OhzO2pnDNnQ?rel=0&amp;hd=1\" height=\"390\" frameborder=\"0\" width=\"480 allowfullscreen\" ><\/iframe><\/p>\n<div id=\"tweetbutton382\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F02%2F18%2Fshadowmap-lod%2F&amp;text=Shadowmap%20LOD&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F02%2F18%2Fshadowmap-lod%2F\" class=\"twitter-share-button\"  style=\"width:55px;height:22px;background:transparent url('http:\/\/shadowcovenant.com\/blog\/wp-content\/plugins\/wp-tweet-button\/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;\">Tweet<\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>This week I&rsquo;ve been working on the LOD system for the shadowmaps&#8230; Using the idea that I can have about 60-70 lights per area on the game, I can&rsquo;t update 1024&#215;1024 shadowmaps every frame&#8230; Well, I could, but I&rsquo;d get 0.5 FPS (I tested it for fun)&#8230; So, I decided to play with 4 variables: [&hellip;]<\/p>\n<div id=\"tweetbutton382\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F02%2F18%2Fshadowmap-lod%2F&amp;text=Shadowmap%20LOD&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F02%2F18%2Fshadowmap-lod%2F\" class=\"twitter-share-button\"  style=\"width:55px;height:22px;background:transparent url('http:\/\/shadowcovenant.com\/blog\/wp-content\/plugins\/wp-tweet-button\/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;\">Tweet<\/a><\/div>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,6],"tags":[49,44,50,42,240,43,45,47,48,39,40,41,46],"class_list":["post-382","post","type-post","status-publish","format-standard","hentry","category-development","category-games","tag-3d","tag-dynamic","tag-game","tag-hemisphere","tag-indy","tag-light","tag-lod","tag-multisampling","tag-realtime","tag-shadowmap","tag-spellcaster","tag-studios","tag-update"],"_links":{"self":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/comments?post=382"}],"version-history":[{"count":3,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions"}],"predecessor-version":[{"id":387,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions\/387"}],"wp:attachment":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/media?parent=382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/categories?post=382"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/tags?post=382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}