{"id":135,"date":"2014-02-20T02:01:23","date_gmt":"2014-02-20T02:01:23","guid":{"rendered":"http:\/\/blog.3pxh.com\/?p=135"},"modified":"2014-02-20T02:26:32","modified_gmt":"2014-02-20T02:26:32","slug":"a-first-look-unity-and-shaders","status":"publish","type":"post","link":"http:\/\/blog.3pxh.com\/?p=135","title":{"rendered":"A First Look: Unity and Shaders"},"content":{"rendered":"<p>I&#8217;ve been hearing about Unity for some time and I figured I&#8217;d finally check it out. The big takeaway from today: it is a monstrous piece of software and I have a lot to learn. It&#8217;s really powerful though, so that&#8217;s neat.<\/p>\n<p>I also decided to take my first dip into shaders given that unity makes it really easy to bind shaders to objects. So I read through a tutorial and looked at the math <a href=\"http:\/\/mainisusuallyafunction.blogspot.com\/2011\/10\/quasicrystals-as-sums-of-waves-in-plane.html\">here<\/a>\u00a0to produce the following images (they&#8217;re animated as in the link above). These are all being done in a shader which is running on the gpu.<\/p>\n<p><a href=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.18.29-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-136\" alt=\"Screen Shot 2014-02-19 at 5.18.29 PM\" src=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.18.29-PM-300x250.png\" width=\"300\" height=\"250\" srcset=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.18.29-PM-300x250.png 300w, http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.18.29-PM.png 404w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.32.54-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-137\" alt=\"Screen Shot 2014-02-19 at 5.32.54 PM\" src=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.32.54-PM-300x283.png\" width=\"300\" height=\"283\" srcset=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.32.54-PM-300x283.png 300w, http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.32.54-PM.png 423w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.35.03-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-138\" alt=\"Screen Shot 2014-02-19 at 5.35.03 PM\" src=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.35.03-PM-300x272.png\" width=\"300\" height=\"272\" srcset=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.35.03-PM-300x272.png 300w, http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.35.03-PM.png 420w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.38.48-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-139\" alt=\"Screen Shot 2014-02-19 at 5.38.48 PM\" src=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.38.48-PM-300x289.png\" width=\"300\" height=\"289\" srcset=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.38.48-PM-300x289.png 300w, http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-5.38.48-PM.png 409w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><a href=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-6.16.38-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-143\" alt=\"Screen Shot 2014-02-19 at 6.16.38 PM\" src=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-6.16.38-PM-300x282.png\" width=\"300\" height=\"282\" srcset=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-6.16.38-PM-300x282.png 300w, http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-6.16.38-PM.png 423w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-6.22.21-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-144\" alt=\"Screen Shot 2014-02-19 at 6.22.21 PM\" src=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-6.22.21-PM-300x274.png\" width=\"300\" height=\"274\" srcset=\"http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-6.22.21-PM-300x274.png 300w, http:\/\/blog.3pxh.com\/wp-content\/uploads\/2014\/02\/Screen-Shot-2014-02-19-at-6.22.21-PM.png 431w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>For those interested in the shader, the short version (image 1 above) is below. It could probably be optimized a bit.<\/p>\n<p>float wave0 = sin(i.uv.x*300+_Time.y*.5);<br \/>\nfloat wave1 = sin((i.uv.x*.90096886+i.uv.y*.4338837)*300+_Time.y*.5);<br \/>\nfloat wave2 = sin((i.uv.x*.62348980185+i.uv.y*.78183148)*300+_Time.y*.5);<br \/>\nfloat wave3 = sin((i.uv.x*.22252093395+i.uv.y*.97492791218)*300+_Time.y*.5);<br \/>\nfloat wave4 = sin((i.uv.y*.97492791218-i.uv.x*.22252093395)*300+_Time.y*.5);<br \/>\nfloat wave5 = sin((i.uv.y*.78183148246-i.uv.x*.62348980185)*300+_Time.y*.5);<br \/>\nfloat wave6 = sin((i.uv.y*.43388373911-i.uv.x*.9009688679)*300+_Time.y*.5);<br \/>\nfloat z = 1.0\/(1.0+exp(-1.0*(wave0+wave1+wave2+wave3+wave4+wave5+wave6)*2));<br \/>\nreturn float4(z,z,z,1.0);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been hearing about Unity for some time and I figured I&#8217;d finally check it out. The big takeaway from today: it is a monstrous piece of software and I have a lot to learn. It&#8217;s really powerful though, so that&#8217;s neat. I also decided to take my first dip into shaders given that unity &hellip; <a href=\"http:\/\/blog.3pxh.com\/?p=135\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">A First Look: Unity and Shaders<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135"}],"version-history":[{"count":4,"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions"}],"predecessor-version":[{"id":145,"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions\/145"}],"wp:attachment":[{"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.3pxh.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}