{"id":125,"date":"2015-09-05T18:43:05","date_gmt":"2015-09-05T18:43:05","guid":{"rendered":"http:\/\/metareal.net\/blog\/?p=125"},"modified":"2015-09-05T19:37:42","modified_gmt":"2015-09-05T19:37:42","slug":"mysterious-sparkling-bug","status":"publish","type":"post","link":"http:\/\/metareal.net\/blog\/?p=125","title":{"rendered":"Mysterious Sparkling Bug"},"content":{"rendered":"<p>I&#8217;ve been noticing for a while an occasional bit of &#8220;pixel sparkling&#8221; on some of the walls.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/metareal.net\/blog\/wp-content\/uploads\/2015\/09\/sparkle01.jpg\" alt=\"Sparkle01\" title=\"sparkle01.jpg\" border=\"0\" width=\"599\" height=\"454\" \/><\/p>\n<p>Those stray yellow pixels, which are the color of the next room over. My theory is that it&#8217;s small gaps in my triangle mesh, maybe due to arithmetic round-off error. Ok! Let&#8217;s tweak the shader to show those triangles.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/metareal.net\/blog\/wp-content\/uploads\/2015\/09\/sparkle02.jpg\" alt=\"Sparkle02\" title=\"sparkle02.jpg\" border=\"0\" width=\"297\" height=\"231\" \/><\/p>\n<p>Yup, that&#8217;d be it. When building the mesh, the geometry is initially only decomposed into rectangles. I notice: There are never sparkles on the rectangle halves. Great! I&#8217;ll just expand each rectangle slightly.<\/p>\n<p>Rooms in Metareal are generally about 10x10x10. (I think of it as meters&#8230; but it&#8217;s just &#8220;units&#8221;.) When I expand each rectangle by 0.01 (a centimeter? sort-of?) it fixes all the sparkles, sure enough, but makes a mess of the corners.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/metareal.net\/blog\/wp-content\/uploads\/2015\/09\/sparkle03.jpg\" alt=\"Sparkle03\" title=\"sparkle03.jpg\" border=\"0\" width=\"417\" height=\"297\" \/><\/p>\n<p>I wonder: How &#8220;big&#8221; are these sparkles? As an experiment, I <em>shrink<\/em> all the rectangles by 0.0001 (a tenth of a millimeter?) and sure enough&#8230; well&#8230; take a look.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/metareal.net\/blog\/wp-content\/uploads\/2015\/09\/sparkle04.jpg\" alt=\"Sparkle04\" title=\"sparkle04.jpg\" border=\"0\" width=\"313\" height=\"331\" \/><\/p>\n<p>And expanding each rectangle by 0.0001 seems just right. No visible corner-mangling or overlap, and, as near as I can see, all sparkles gone.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/metareal.net\/blog\/wp-content\/uploads\/2015\/09\/sparkle05.jpg\" alt=\"Sparkle05\" title=\"sparkle05.jpg\" border=\"0\" width=\"523\" height=\"422\" \/><\/p>\n<p>And some of the code that drives this&#8230;<\/p>\n<pre>\r\n\/\/ Build the four corners of the rectangle\r\n    MeVec3 p00 = wVector + sVector * sLo + tVector * tLo;\r\n    MeVec3 p10 = wVector + sVector * sHi + tVector * tLo;\r\n    MeVec3 p01 = wVector + sVector * sLo + tVector * tHi;\r\n    MeVec3 p11 = wVector + sVector * sHi + tVector * tHi;\r\n\r\n\/\/ we like to expand the rectangle a tiny bit, we need normalized s&t\r\n    float expandAmount = 0.0001;\r\n    MeVec3 s1Vector = sVector.normalize() * expandAmount;\r\n    MeVec3 t1Vector = tVector.normalize() * expandAmount;\r\n\r\n\/\/ apply the expansion        \r\n    p00 += -s1Vector -t1Vector;\r\n    p01 += -s1Vector +t1Vector;\r\n    p10 += +s1Vector -t1Vector;\r\n    p11 += +s1Vector +t1Vector;\r\n<\/pre>\n<p>Always nice to resolve an ongoing irritation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been noticing for a while an occasional bit of &#8220;pixel sparkling&#8221; on some of the walls. Those stray yellow pixels, which are the color of the next room over. My theory is that it&#8217;s small gaps in my triangle mesh, maybe due to arithmetic round-off error. Ok! Let&#8217;s tweak the shader to show those [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-3"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=125"}],"version-history":[{"count":2,"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":128,"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions\/128"}],"wp:attachment":[{"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/metareal.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}