{"id":115,"date":"2010-10-06T11:53:44","date_gmt":"2010-10-06T10:53:44","guid":{"rendered":"http:\/\/shadowcovenant.com\/blog\/?p=115"},"modified":"2010-10-06T11:53:44","modified_gmt":"2010-10-06T10:53:44","slug":"point-lights","status":"publish","type":"post","link":"http:\/\/shadowcovenant.com\/blog\/2010\/10\/06\/point-lights\/","title":{"rendered":"Point lights"},"content":{"rendered":"<p>Got shadows for point lights working:<\/p>\n<p><a href=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-116\" title=\"shadowmap_pointlight\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight-300x238.jpg\" alt=\"\" width=\"300\" height=\"238\" srcset=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight-300x238.jpg 300w, http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight-1024x813.jpg 1024w, http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight.jpg 1040w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Had some issues getting it to work:<\/p>\n<p><a href=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight_issue.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-117\" title=\"shadowmap_pointlight_issue\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight_issue-300x238.jpg\" alt=\"\" width=\"300\" height=\"238\" srcset=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight_issue-300x238.jpg 300w, http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight_issue-1024x813.jpg 1024w, http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/shadowmap_pointlight_issue.jpg 1040w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The errors in the shadows are noticeable in the areas in between the vertexes.<\/p>\n<p>Initially, I thought the problem was that I was a pixel shader\/vertex shader mismatch, since when I was creating the shadowmap, the vertex shader for it did most of the computation and the pixel shader was just a simple passthrough, and when I was &#8220;applying&#8221; the shadowmap, all the calculations were done in the pixel shader.<\/p>\n<p>After I corrected that (passed most of the computations for the pixel shader on the shadow map phase), the problem persisted&#8230; I got pissed about that, and after much scrounging around I found the problem&#8230;<\/p>\n<p>The issue had to do with the projection of the geometry in the shadowmap&#8230; As I&#8217;m using a dual-paraboloid map, I have to create a &#8220;fish-eye&#8221; perspective of sorts when generating the shadowmap. This works fine, but I didn&#8217;t take to account lowly tesselated geometry near the light source (because the perspective transformation is done at a vertex level):<\/p>\n<p><a href=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/errors_projection01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-118\" title=\"errors_projection01\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/errors_projection01-300x100.jpg\" alt=\"\" width=\"300\" height=\"100\" srcset=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/errors_projection01-300x100.jpg 300w, http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/errors_projection01.jpg 846w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>So, originally we have a tesselated square&#8230; If we apply the spherical projection we need for the &#8220;fish-eye&#8221; effect, we should have something rounded like we see on the second picture&#8230; But, as we are only applying the math to the vertexes, we in fact get the red lines, instead of the rounded edges&#8230;<\/p>\n<p>On a zoom:<\/p>\n<p><a href=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/errors_projection02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-119\" title=\"errors_projection02\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/errors_projection02-293x300.jpg\" alt=\"\" width=\"293\" height=\"300\" srcset=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/errors_projection02-293x300.jpg 293w, http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2010\/10\/errors_projection02.jpg 300w\" sizes=\"auto, (max-width: 293px) 100vw, 293px\" \/><\/a><\/p>\n<p>In the middle of the object, that&#8217;s not a big problem&#8230; there will the wrongfully drawn shadows, but we won&#8217;t notice them&#8230; Problem is on the outer edges of the object, in which we would fetch texels outside of the &#8220;drawn area&#8221; of the shadowmap!<\/p>\n<p>Thankfully, the solution for this problem is simple enough: just clear the shadowmap to the maximum distance, to insure that all the areas outside of the &#8220;drawn area&#8221; are never shadowed&#8230; this is potentially wrong, but it should be close enough to never be a problem&#8230;<\/p>\n<p>Anyway, they look neat and are fast, which is the two main points in all of this&#8230; I&#8217;m thinking I&#8217;ll have probably two or three shadowmapped lightsources on screen at a time&#8230; Need to devise a way to reuse the shadowbuffers of lights that don&#8217;t need them at the moment (since I&#8217;m currently using 32 bit floating point shadowmaps, which are huge memory hogs!), but that shouldn&#8217;t be an issue&#8230;<\/p>\n<p>Next step, directional lights!<\/p>\n<div id=\"tweetbutton115\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2010%2F10%2F06%2Fpoint-lights%2F&amp;text=Point%20lights&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2010%2F10%2F06%2Fpoint-lights%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>Got shadows for point lights working: Had some issues getting it to work: The errors in the shadows are noticeable in the areas in between the vertexes. Initially, I thought the problem was that I was a pixel shader\/vertex shader mismatch, since when I was creating the shadowmap, the vertex shader for it did most [&hellip;]<\/p>\n<div id=\"tweetbutton115\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2010%2F10%2F06%2Fpoint-lights%2F&amp;text=Point%20lights&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2010%2F10%2F06%2Fpoint-lights%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":[],"class_list":["post-115","post","type-post","status-publish","format-standard","hentry","category-development","category-games"],"_links":{"self":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/115","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=115"}],"version-history":[{"count":1,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":120,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/115\/revisions\/120"}],"wp:attachment":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}