{"id":3512,"date":"2014-12-22T22:10:22","date_gmt":"2014-12-22T19:10:22","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=3512"},"modified":"2015-08-21T09:27:50","modified_gmt":"2015-08-21T06:27:50","slug":"custom-terrain-shader-sharp-blending","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2014\/12\/22\/custom-terrain-shader-sharp-blending\/","title":{"rendered":"Custom Terrain Shader: Sharp Blending"},"content":{"rendered":"<p>Modified terrain shader for sharp blending.<\/p>\n<p><strong>Tutorial:<\/strong><br \/>\n&#8211; Download terrain shader sources for your unity version: <a title=\"http:\/\/unity3d.com\/unity\/download\/archive\" href=\"http:\/\/unity3d.com\/unity\/download\/archive\" target=\"_blank\">http:\/\/unity3d.com\/unity\/download\/archive<\/a><br \/>\n&#8211; Copy &#8220;DefaultResourcesExtra\\Nature\\Terrain\\TerrBumpFirstPass.shader&#8221; into your project<br \/>\n&#8211; Rename the &#8220;TerrBumpFirstPass.shader&#8221; into &#8220;&#8221;TerrBumpFirstPassCustom.shader&#8221;<br \/>\n&#8211; Edit &#8220;TerrBumpFirstPassCustom.shader&#8221;<br \/>\n&#8211; Find line:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">Shader &quot;Nature\/Terrain\/Custom Bumped Specular&quot; {<\/pre>\n<p>&#8211; Replace with: <em>*So we get this shader under custom list<\/em><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">Shader &quot;Custom\/Nature\/Terrain\/Custom Bumped Specular&quot; {<\/pre>\n<p>&#8211; Find line:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">fixed4 col;<\/pre>\n<p>&#8211; Add these lines after it: <em>*I&#8217;m sure there would be a better way to clamp those to use max channel only, but works for now \ud83d\ude42<\/em><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\tif (splat_control.r&gt;=splat_control.g &amp;&amp; splat_control.r&gt;=splat_control.b &amp;&amp; splat_control.r&gt;=splat_control.a)\r\n    {\r\n        splat_control.r=1;\r\n        splat_control.g=0;\r\n        splat_control.b=0;\r\n        splat_control.a=0;\r\n    }\r\n \r\n    if (splat_control.g&gt;=splat_control.r &amp;&amp; splat_control.g&gt;=splat_control.b &amp;&amp; splat_control.g&gt;=splat_control.a)\r\n    {\r\n        splat_control.r=0;\r\n        splat_control.g=1;\r\n        splat_control.b=0;\r\n        splat_control.a=0;\r\n    }\r\n \r\n    if (splat_control.b&gt;=splat_control.g &amp;&amp; splat_control.b&gt;=splat_control.r &amp;&amp; splat_control.b&gt;=splat_control.a)\r\n    {\r\n        splat_control.r=0;\r\n        splat_control.g=0;\r\n        splat_control.b=1;\r\n        splat_control.a=0;\r\n    }\r\n \r\n    if (splat_control.a&gt;=splat_control.g &amp;&amp; splat_control.a&gt;=splat_control.b &amp;&amp; splat_control.a&gt;=splat_control.r)\r\n    {\r\n        splat_control.g=0;\r\n        splat_control.b=0;\r\n        splat_control.r=0;\r\n        splat_control.a=1;\r\n    }\r\n<\/pre>\n<pre>\r\n\r\n<\/pre>\n<p>&#8211; Now create new material (Right click over project window, Create \/ Material<\/p>\n<p>&#8211; Rename the new material as &#8220;CustomTerrainMaterial&#8221;<br \/>\n&#8211; Assign &#8220;Custom\/Nature\/Terrain\/Custom Bumped Specular&#8221; to that material (from the material shader dropdown)<br \/>\n&#8211; Now assign material to the terrain: to Terrain object, Settings tab, Material slot<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p><strong>*Update for Unity5 (5.1.2)<\/strong><\/p>\n<p>&#8211; Download latest builtin shader (tested with 5.1.2) : http:\/\/unity3d.com\/unity\/download\/archive<br \/>\n&#8211; Copy this file to your project: &#8220;\\DefaultResourcesExtra\\TerrainShaders\\Splats\\Standard-FirstPass.shader&#8221;<br \/>\n&#8211; Edit the copied &#8220;Standard-FirstPass.shader&#8221; and rename it to &#8220;Nature\/Terrain\/StandardSharp&#8221;<br \/>\n&#8211; Copy file &#8220;\\512\\CGIncludes\\TerrainSplatmapCommon.cginc&#8221; to your project<br \/>\n&#8211; Modify file &#8220;TerrainSplatmapCommon.cginc&#8221;, find line &#8220;splat_control = tex2D(_Control, IN.tc_Control);&#8221;<br \/>\n&#8211; After that line, insert same custom code as above for unity4<br \/>\n&#8211; Create new material, assign shader Nature\/Terrain\/StandardSharp<br \/>\n&#8211; Assign this material to terrain (from terrain settings, material &gt; custom, assign your material here)<\/p>\n<p>&#8212;<\/p>\n<p><strong>Original terrain shader:<\/strong> (default blend)<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3513\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2014\/12\/22\/custom-terrain-shader-sharp-blending\/terrain_blending_custom_unity_1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_custom_unity_1.jpg?fit=680%2C481&amp;ssl=1\" data-orig-size=\"680,481\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"terrain_blending_custom_unity_1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_custom_unity_1.jpg?fit=680%2C481&amp;ssl=1\" class=\"alignnone size-full wp-image-3513\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_custom_unity_1.jpg?resize=680%2C481\" alt=\"terrain_blending_custom_unity_1\" width=\"680\" height=\"481\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_custom_unity_1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_custom_unity_1.jpg?resize=300%2C212&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><br \/>\n<strong>Custom terrain shader:<\/strong> (sharp blending)<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3514\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2014\/12\/22\/custom-terrain-shader-sharp-blending\/terrain_blending_sharp_custom_unity_2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_sharp_custom_unity_2.jpg?fit=680%2C481&amp;ssl=1\" data-orig-size=\"680,481\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"terrain_blending_sharp_custom_unity_2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_sharp_custom_unity_2.jpg?fit=680%2C481&amp;ssl=1\" class=\"alignnone size-full wp-image-3514\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_sharp_custom_unity_2.jpg?resize=680%2C481\" alt=\"terrain_blending_sharp_custom_unity_2\" width=\"680\" height=\"481\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_sharp_custom_unity_2.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_sharp_custom_unity_2.jpg?resize=300%2C212&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modified terrain shader for sharp blending. Tutorial: &#8211; Download terrain shader sources for your unity version: http:\/\/unity3d.com\/unity\/download\/archive &#8211; Copy &#8220;DefaultResourcesExtra\\Nature\\Terrain\\TerrBumpFirstPass.shader&#8221; into your project &#8211; Rename the &#8220;TerrBumpFirstPass.shader&#8221; into &#8220;&#8221;TerrBumpFirstPassCustom.shader&#8221; &#8211; Edit &#8220;TerrBumpFirstPassCustom.shader&#8221; &#8211; Find line: Shader &quot;Nature\/Terrain\/Custom Bumped Specular&quot; { &#8211; Replace with: *So we [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3514,"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":[13,3],"tags":[686,568,14,168],"class_list":["post-3512","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-shaders","category-unity3d","tag-blending","tag-custom","tag-shader","tag-terrain"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/12\/terrain_blending_sharp_custom_unity_2.jpg?fit=680%2C481&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-UE","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3512","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=3512"}],"version-history":[{"count":12,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3512\/revisions"}],"predecessor-version":[{"id":3926,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3512\/revisions\/3926"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/3514"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=3512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=3512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=3512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}