nanaxsite.blogg.se

Unity terrain splatmap texture edge blending
Unity terrain splatmap texture edge blending











  1. #Unity terrain splatmap texture edge blending code#
  2. #Unity terrain splatmap texture edge blending download#

Other than that, they’re pretty much identical.

  • Rather than using the default blendmode, which would overwrite the output of previous, AddPassShader is an additive pass, specified using the decal:add parameter following the surface shader pragma directive.
  • AddPassShader specifies "IgnoreProjector"="True".
  • FirstPassShader specifies “Queue” = “Geometry-100”, whereas AddPassShader is drawn in a later renderqueue: "Queue" = "Geometry-99".
  • The differences between the two shaders are subtle:

    #Unity terrain splatmap texture edge blending code#

    The “Dependency” property appears to be unique to terrain shaders, and is not described anywhere in Unity’s shaderlab documentation, but here’s my findings: AddPassShaderĮxamining the code of the shader specified in the “AddPassShader”, you’ll find the actual surface shader function is identical to that in the “FirstPassShader”. Also note that the control texture is passed in with a default value of “Red”, which is the channel used to indicate the influence of the Layer 0 texture (hence, by default, the entire terrain is coloured with _Splat0 texture):ĭependency "AddPassShader" = "MyShaders/Terrain/Editor/AddPass"ĭependency "BaseMapShader" = "MyShaders/Terrain/Editor/BaseMap" These are marked as since they will be passed in automatically from the terrain engine rather than set in the material inspector. The first thing to notice is the Properties block, which contains definitions for the textures and splat map control texture. It has a dependency on Hidden/Nature/Terrain/Bumped Specular AddPass, which can be found at \DefaultResourcesExtra\Nature\Terrain\TerrBumpAddPass.shader

  • The bumped specular terrain shader – Nature/Terrain/Bumped Specular – can be found in \DefaultResourcesExtra\Nature\Terrain\TerrBumpFirstPass.shader.
  • It has a dependency on Hidden/TerrainEngine/Splatmap/Lightmap-AddPass, which can be found at \DefaultResourcesExtra\TerrainShaders\Splats\AddPass.shader
  • The default diffuse terrain shader – Nature/Terrain/Diffuse – can be found in \DefaultResourcesExtra\TerrainShaders\Splats\FirstPass.shader.
  • #Unity terrain splatmap texture edge blending download#

    You can download the source of all Unity supplied shaders from To create an alternative custom terrain shader other than bumped/specular is slightly more complicated – it might help to first see the structure of the inbuilt terrain shaders. You should notice that your flat, diffuse terrain changes from this:Ĭreating bumped / specular shaders as above is fairly straightforward because Unity already comes with a bumped specular terrain shader – you just need to specify a material that uses it in place of the default diffuse terrain shader. Note the information text in the previous step says you need to apply a normal-mapped material to the terrain, so let’s do that: click on the cog icon on the right hand side and drag the material created in Step One into the “material” slot: You can then use the range of splat tools to paint the various textures onto the terrain.ģ. Click Edit Textures –> Add Texture.Īdd main textures and normal maps for each texture to be used on the terrain (they won’t take effect just yet): Highlight the terrain and, in the inspector, click on the Paintbrush icon. Note that there won’t be any texture slots on this material – it will use the textures assigned to the terrain itself in the next step.Ģ. Create a new material and assign the Nature/Terrain/Bumped Specular shader to it. The steps required to apply it are as follows:ġ. Since Unity 4.0, creating bump-mapped/specular terrain is actually pretty straightforward as Unity already comes supplied with a suitable shader. So, for reference, this blog post will describe my experience of creating custom terrain shaders as of today (Dec 2013), using Unity 4.2. Many of the previous descriptions are outdated and inaccurate but, unfortunately, still appear as top hits in search result pages, and it seems hard to find reliable up-to-date information instead. And when you try to search the internet for “custom Unity terrain shader”, say, you find a variety of conflicting information that suggests it’s either not supported, requires exporting the raw terrain to a modelling program, or involves creating a new Terrain shader which is named the same (and therefore overrides) the hidden internal terrain shaders (typically "Hidden/TerrainEngine/Splatmap/Lightmap-FirstPass" or something similarly arcane) – hardly intuitive. I love Unity – it’s one of those environments that’s actually a pleasure to program in, but its terrain system seems somewhat lacking behind its other features, requiring quite a lot of hacks and workarounds to get desired appearance and functionality (while still having an acceptable level of performance).įor example, at first glance, the inbuilt terrain appears to have only one shader, which only supports diffuse textures.













    Unity terrain splatmap texture edge blending