{"id":2206,"date":"2013-08-11T19:47:41","date_gmt":"2013-08-11T16:47:41","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=2206"},"modified":"2014-12-24T16:06:24","modified_gmt":"2014-12-24T13:06:24","slug":"scorched-earth-terrain-wip","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2013\/08\/11\/scorched-earth-terrain-wip\/","title":{"rendered":"Scorched Earth Terrain (wip)"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2207\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/08\/11\/scorched-earth-terrain-wip\/scorched_earth_terrain_wip_unity_1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_1.jpg?fit=680%2C439&amp;ssl=1\" data-orig-size=\"680,439\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"scorched_earth_terrain_wip_unity_1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_1.jpg?fit=680%2C439&amp;ssl=1\" class=\"alignnone size-full wp-image-2207\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_1.jpg?resize=680%2C439\" alt=\"scorched_earth_terrain_wip_unity_1\" width=\"680\" height=\"439\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_1.jpg?resize=300%2C193&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>This is another thing that i&#8217;ve always wanted to try in Unity, <a title=\"http:\/\/www.youtube.com\/watch?v=P-9O1TOSfCM\" href=\"http:\/\/www.youtube.com\/watch?v=P-9O1TOSfCM\" target=\"_blank\">Scorched Earth deformable collapsing terrain<\/a> (youtube link).<\/p>\n<p><strong>Ideas:<\/strong><br \/>\n1 &#8211; Using SetPixels() with texture would most likely be easiest, just slow on bigger resolutions (but no need high resolution for this anyways?)<br \/>\n2 &#8211; <a title=\"http:\/\/wiki.unity3d.com\/index.php?title=MarchingSquares\" href=\"http:\/\/wiki.unity3d.com\/index.php?title=MarchingSquares\" target=\"_blank\">2D marching square<\/a>s (unifywiki), but how to do falling ground..?<br \/>\n3 &#8211; High resolution mesh, then adjust vertices for making holes (and create extra falling mesh slices..?)<br \/>\n4 &#8211; <a title=\"http:\/\/unitycoder.com\/upload\/demos\/WaterSim2\/\" href=\"http:\/\/unitycoder.com\/upload\/demos\/WaterSim2\/\" target=\"_blank\">2D cellular automata thing<\/a>, again its using SetPixels(), but would be nice to have 2d water on the terrain actually..<br \/>\n5 &#8211; <a title=\"http:\/\/unitycoder.com\/blog\/2012\/02\/05\/convert-bitmap-to-3d-extruded-mesh-unity3d\/\" href=\"http:\/\/unitycoder.com\/blog\/2012\/02\/05\/convert-bitmap-to-3d-extruded-mesh-unity3d\/\" target=\"_blank\">Bitmap2Mesh<\/a>, also using SetPixels() with texture, but could be made to use just array only..?<\/p>\n<p><strong>Idea#3:<\/strong> High resolution quad mesh<br \/>\n&#8211; Testing this first.. main screenshot is starting point (mesh, screenwidth, resolution = 1)<br \/>\n&#8211; Not sure yet how to handle collisions<br \/>\n&#8211; Making holes: Sphere(s) defines holes, all vertices inside sphere are moved down, until not inside sphere<br \/>\n&#8211; Collapsing: Create new mesh slices, same amount as those vertices that were moved down. Slice height = amount the vertice was moved down.. Then somehow animate them falling down.<br \/>\n&#8211; Weld terrain back to 1 mesh: Go trhough each slice, move the vertices below them, up to slice top Y, destroy slices.<br \/>\n&#8211; Problems: What is there are multiple explosions in different places..will get lots of slices on top of each other?<br \/>\n&#8211; Added webplayer (v1): Can destroy ground, slices are created and for now they fall with rigidbody (but wont stop), could use iTween for moving slices?<br \/>\n&#8211; Could probably decrease vertex count by 50%, since now each terrain slice\/column is 4 vertices (not shared).<br \/>\n&#8211; Added webplayer (v2): Main thing missing is spherical holes from explosions..<br \/>\n&#8211; Added webplayer (v3):<br \/>\n&#8211; Spherical holes on ground using : [charp]&#8230; float angle = Mathf.Asin(counter\/radius);\u00a0 float height = Mathf.Cos(angle)*radius; &#8230;[\/charp]<br \/>\n&#8211; Ground plane has now half the vertices (and its smoother, since top\u00a0 vertices connect to previous one)<br \/>\n&#8211; Exploded ground slices now fall with gravity (code from <a title=\"http:\/\/stackoverflow.com\/questions\/3966188\/c-sharp-xna-simulate-gravity\" href=\"http:\/\/stackoverflow.com\/questions\/3966188\/c-sharp-xna-simulate-gravity\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/3966188\/c-sharp-xna-simulate-gravity<\/a> )<br \/>\n&#8211; Falling slices are shown red, then after every slice has stopped, terrain vertices is set to those positions (and slices are destoyed)<\/p>\n<p>&#8212;<\/p>\n<p><strong>Sources:<\/strong> (not finished or cleaned up..)<br \/>\n<a title=\"https:\/\/github.com\/unitycoder\/ScorchedEarthTerrainFail\" href=\"https:\/\/github.com\/unitycoder\/ScorchedEarthTerrainFail\" target=\"_blank\">https:\/\/github.com\/unitycoder\/ScorchedEarthTerrainFail<\/a><\/p>\n<p>&#8212;<\/p>\n<p><strong>Webplayer:<\/strong><br \/>\n<a title=\"http:\/\/unitycoder.com\/upload\/demos\/ScorchedEarthTerrain1\/\" href=\"http:\/\/unitycoder.com\/upload\/demos\/ScorchedEarthTerrain1\/\" target=\"_blank\">http:\/\/unitycoder.com\/upload\/demos\/ScorchedEarthTerrain1\/<\/a> (v1)<br \/>\n<a title=\"http:\/\/unitycoder.com\/upload\/demos\/ScorchedEarthTerrain2\/\" href=\"http:\/\/unitycoder.com\/upload\/demos\/ScorchedEarthTerrain2\/\" target=\"_blank\">http:\/\/unitycoder.com\/upload\/demos\/ScorchedEarthTerrain2\/<\/a> (v2)<br \/>\n<a title=\"start webplayer demo\" href=\"http:\/\/unitycoder.com\/upload\/demos\/ScorchedEarthTerrain3\/\" target=\"_blank\">http:\/\/unitycoder.com\/upload\/demos\/ScorchedEarthTerrain3\/<\/a> (v3)<\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#2:<\/strong> Basic terrain shape (perlin noise), Vertices are moved down when clicking the mountain<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2214\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/08\/11\/scorched-earth-terrain-wip\/scorched_earth_terrain_wip_unity_2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_2.jpg?fit=680%2C480&amp;ssl=1\" data-orig-size=\"680,480\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"scorched_earth_terrain_wip_unity_2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_2.jpg?fit=680%2C480&amp;ssl=1\" class=\"alignnone size-full wp-image-2214\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_2.jpg?resize=680%2C480\" alt=\"scorched_earth_terrain_wip_unity_2\" width=\"680\" height=\"480\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_2.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_2.jpg?resize=300%2C211&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#3:<\/strong> Problems if using UV maps on terrain, since if we cut part of terrain at middle, we should add more vertices there to keep UV values.. (now we have vertices only in top of the terrain and bottom, not middle). Problem creating circular holes at the moment.. Slices are now welded to main terrain after movement stops.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2218\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/08\/11\/scorched-earth-terrain-wip\/scorched_earth_terrain_wip_unity_3\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_3.jpg?fit=680%2C461&amp;ssl=1\" data-orig-size=\"680,461\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"scorched_earth_terrain_wip_unity_3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_3.jpg?fit=680%2C461&amp;ssl=1\" class=\"alignnone size-full wp-image-2218\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_3.jpg?resize=680%2C461\" alt=\"scorched_earth_terrain_wip_unity_3\" width=\"680\" height=\"461\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_3.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_3.jpg?resize=300%2C203&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#4:<\/strong> Explosion shader (see source below) test with quad mesh primitive. Smooth edges, compared to using mesh circle. Idea is from here: <a title=\"http:\/\/johnwhigham.blogspot.fi\/2011\/11\/planetary-rings.html\" href=\"http:\/\/johnwhigham.blogspot.fi\/2011\/11\/planetary-rings.html\" target=\"_blank\">Planetary rings shader<\/a><\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2219\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/08\/11\/scorched-earth-terrain-wip\/shader_explosion_circle_gradient_unity\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/shader_explosion_circle_gradient_unity.jpg?fit=374%2C380&amp;ssl=1\" data-orig-size=\"374,380\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"shader_explosion_circle_gradient_unity\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/shader_explosion_circle_gradient_unity.jpg?fit=374%2C380&amp;ssl=1\" class=\"alignnone size-full wp-image-2219\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/shader_explosion_circle_gradient_unity.jpg?resize=374%2C380\" alt=\"shader_explosion_circle_gradient_unity\" width=\"374\" height=\"380\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/shader_explosion_circle_gradient_unity.jpg?w=374&amp;ssl=1 374w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/shader_explosion_circle_gradient_unity.jpg?resize=295%2C300&amp;ssl=1 295w\" sizes=\"auto, (max-width: 374px) 100vw, 374px\" \/><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\r\nShader &quot;unityCoder\/explocircleTest1&quot; {\r\nProperties {\r\n_MainTex (&quot;Base (RGB)&quot;, 2D) = &quot;white&quot; {}\r\n_Radius (&quot;Radius&quot;, float) = 0.5\r\n}\r\n\r\nSubShader {\r\nTags\r\n{\r\n&quot;Queue&quot;=&quot;Transparent&quot;\r\n&quot;IgnoreProjector&quot;=&quot;True&quot;\r\n&quot;RenderType&quot;=&quot;Transparent&quot;\r\n}\r\nLOD 200\r\nLighting Off\r\n\r\nCGPROGRAM\r\n#pragma surface surf Lambert\r\n\r\nsampler2D _MainTex;\r\nfloat _Radius;\r\n\r\nstruct Input {\r\nfloat2 uv_MainTex;\r\n};\r\n\r\nvoid surf (Input IN, inout SurfaceOutput o)\r\n{\r\nfloat dist = distance(IN.uv_MainTex, float2(0.5,0.5));\r\nif ( abs(dist) &gt; _Radius)\u00a0\u00a0 \u00a0 clip (-1.0);\r\nfloat val = dist*128;\r\nfloat c1 = 1-sin(val+_Time.x)+0.5;\r\nfloat c2 = cos(val+_Time.y)+0.5;\r\nfloat c3 = 0;\r\no.Albedo = float3(c1,c2,c3)*3;\r\no.Alpha = 1;\r\n}\r\nENDCG\r\n}\r\nFallBack &quot;Diffuse&quot;\r\n}\r\n\r\n<\/pre>\n<p>&#8212;<\/p>\n<p><strong>Image#5:<\/strong> Almost.. (see webplayer v3), but wont be able to do those small 1 pixel dirt pieces falling down like in original..not with meshes, texture with SetPixels() would be the only way i&#8217;m afraid..<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2239\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/08\/11\/scorched-earth-terrain-wip\/scorched_earth_terrain_wip_unity_4\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_4.jpg?fit=680%2C394&amp;ssl=1\" data-orig-size=\"680,394\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"scorched_earth_terrain_wip_unity_4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_4.jpg?fit=680%2C394&amp;ssl=1\" class=\"alignnone size-full wp-image-2239\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_4.jpg?resize=680%2C394\" alt=\"scorched_earth_terrain_wip_unity_4\" width=\"680\" height=\"394\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_4.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_4.jpg?resize=300%2C173&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is another thing that i&#8217;ve always wanted to try in Unity, Scorched Earth deformable collapsing terrain (youtube link). Ideas: 1 &#8211; Using SetPixels() with texture would most likely be easiest, just slow on bigger resolutions (but no need high resolution for this anyways?) 2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2214,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[65,112,535,536,534,370,5,533,168],"class_list":["post-2206","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-2d","tag-bitmap","tag-collapsing","tag-deform","tag-deformable","tag-falling","tag-mesh","tag-scorched-earth","tag-terrain"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/08\/scorched_earth_terrain_wip_unity_2.jpg?fit=680%2C480&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-zA","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/2206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=2206"}],"version-history":[{"count":14,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/2206\/revisions"}],"predecessor-version":[{"id":3530,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/2206\/revisions\/3530"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/2214"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=2206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=2206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=2206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}