UV-FreeTriplanar Shaders
Version 2.0.3. By Andrew C. Wang (@andyman404)
Use this pack of terrain shaders and mesh shaders to eliminate terrain texture stretching, and easily texture objects beautifully without the need for skinning/UV-maps. Works great for rugged terrain and procedurally generated geometry.
These shaders are built using Unity 5's Physically-Based Standard Shader technology, taking full advantage of Unity 5's lighting model, Real-Time Global Illumination, Reflections.
If you're looking for the previous old v1.0 (Unity 4.x) documentation: v1.0 docs here.
Features:
- Quickly texture a mesh without having to skin/UV-map it.
- Eliminate stretching for textures on terrains and meshes.
- Includes Physically Based Metallic and Physically Based Specular shaders, as well as legacy shaders.
- Supports Unity 5 lighting features, such as Real-Time Global Illumination, skylight reflections, emissive lighting with reflection probes, light probes.
- Supports vertex colors, forward and deferred rendering paths (incl. legacy deferred), shadows, HDR, lightmapping, gamma and linear color spaces.
- Like the Unity 5 Standard Shader, features are enabled or disabled by simply using or not using various texture slots and parameters in the customized material editor. At runtime, the appropriate shader variant is pick based on which features are used. Unused variants of the shaders will not be included into the game build (more info on Shader build time stripping).
Getting Started
- Import the asset. You should see a "UVFreeShaders" folder in your assets folder. Note: Due to the number of shader variants (hundreds) that must be compiled/imported, it could take a few minutes to initially import the asset into your project. Only the ones that are used in your scenes will be included into the game build.
- Open up the Sample Scene at "UVFreeShaders/Sample/Sample Scene/Sample Scene". Wait for the Realtime and Baked lighting to finish processing, and explore the simple sample scene. It contains meshes using all the different shaders, and a sample terrain using the UV-Free Standard Metallic Terrain shader.
- Play around with the sample materials in "UVFreeShaders/Sample/Materials" to get a feel for how the shaders are used in the materials. Feel free to delete the UVFreeShaders/Sample folder after taking a look at the samples. It is not needed for the shaders to work, and is for example purposes only. You should make your own materials using the shaders. Feel free to delete the samples folder after you are done with it.
- (Optional) Read the documentation below for more info on how to use the shaders. Most users who already know how to use the Unity 5 Built-In Physically Based Standard Shader can skip this step.
Shaders Included:
Triplanar Physically-Based Standard Metallic Shader (Single Texture):
- Physically-based triplanar shader using the Metallic workflow.
- Shader interface mimics the Unity 5's built-in Standard Shader (Metallic workflow) for ease of use, but includes additional features.
- Properties include: Triplanar Space (world or self), Texture Power (how much overlap/blending between the planes), Vertex Color Strength, as well as the following properties from the Standard Shader: maps and options for Albedo, Metallic (RGB) / Smoothness (A), Normal, Height (Parallax), Occlusion, Emission, Detail Mask, Detail Albedo, and Detail Normal.
- Location in Shader dropdown: UVFree/StandardMetallic/Single-Texture
- Shader feature keywords (?):
_UVFREE_LOCAL, _EMISSION, _METALLICGLOSSMAP, _DETAIL, _OCCLUSION, _PARALLAXMAP
Triplanar Physically-Based Standard Metallic Shader (Separate Main, Top, and Bottom Textures):
- Similar to the single texture version, but allows you to optionally set separate textures for faces facing up and/or down. This is useful for simulating snow, dust, or grass growing on top, or mud/dirt on the bottom.
- Properties include: Triplanar Space (world or self), Texture Power (how much overlap/blending between the planes), Vertex Color Strength, as well as the following properties from the Standard Shader: maps and options for Albedo, Metallic (RGB) / Smoothness (A), Normal, and Emission.
- Location in Shader dropdown: UVFree/StandardMetallic/Top-Bottom-Texture
- Shader feature keywords (?):
_UVFREE_LOCAL, _EMISSION, _METALLICGLOSSMAP, _UVFREE_BOTTOM
Triplanar Physically-Based Standard Specular Shader (Single Texture):
- Similar to the single texture metallic version, but uses the more classic Specular workflow.
- Properties include: Triplanar Space (world or self), Texture Power (how much overlap/blending between the planes), Vertex Color Strength, as well as maps and options for Albedo, Specular (RGB) / Smoothness (A), Normal, Height (Parallax), Occlusion, Emission, Detail Mask, Detail Albedo, and Detail Normal.
- Location in Shader dropdown: UVFree/StandardSpecular/Single-Texture
- Shader feature keywords (?):
_UVFREE_LOCAL, _EMISSION, _SPECGLOSSMAP, _DETAIL, _OCCLUSION, _PARALLAXMAP
Triplanar Physically-Based Standard Specular Shader (Separate Main, Top, Bottom Textures):
- Similar to the single texture version, but allows you to optionally set separate textures for faces facing up and/or down. This is useful for simulating snow, dust, or grass growing on top, or mud/dirt on the bottom.
- Properties include: Triplanar Space (world or self), Texture Power (how much overlap/blending between the planes), Vertex Color Strength, Top and Bottom strength, as well as maps and options for Albedo, Specular (RGB) / Smoothness (A), Normal, and Emission.
- Location in Shader dropdown: UVFree/StandardSpecular/Top-Bottom-Texture
- Shader feature keywords (?):
_UVFREE_LOCAL, _EMISSION, _SPECGLOSSMAP, _UVFREE_BOTTOM
Triplanar Physically-Based Standard Metallic Terrain Shader:
- Physically-based triplanar terrain shader using the Metallic workflow.
- Use as many textures as you want (4 textures per pass).
- Use this the same way that Unity's built-in terrain shaders are used, but without the annoying stretching.
- Use the built-in Terrain inspector to set each texture's Albedo (RGB) / Smoothness (A) map, Metalness amount, Smoothness amount (if the map has no alpha), and Normal Map.
- Additional Properties include: Texture Power (how much overlap/blending between the planes), Texture Scale (scale all the textures on the terrain at once), and Bump Scale.
- Location in Shader dropdown: UVFree/Terrain/StandardMetallic
Triplanar Physically-Based Standard Specular Terrain Shader:
- Physically-based triplanar terrain shader using the Specular workflow.
- Use as many textures as you want (4 textures per pass).
- Use this the same way that Unity's built-in terrain shaders are used, but without the annoying stretching.
- Use the built-in Terrain inspector to set each texture's Albedo (RGB) / Smoothness (A) map, Smoothness amount (if the map has no alpha), and Normal Map.
- Additional Properties include: Texture Power (how much overlap/blending between the planes), Texture Scale (scale all the textures on the terrain at once), and Bump Scale, and Specular Color.
- Location in Shader dropdown: UVFree/Terrain/StandardSpecular
Triplanar Legacy Specular Shaders (1-Texture and 3-Texture):
- Triplanar shader using the legacy Blinn-Phong (glossy) lighting model, which is not physically-based, but can be faster to render on low-end hardware.
- The Blinn-phong lighting model has a specular highlight that is dependent on surface angle, light angle, and viewing angle. The highlight is actually just a realtime-suitable way to simulate blurred reflection of the light source. The level of blur for the highlight is controlled with the Shininess slider in the Inspector.
- Properties include: Triplanar Space (world or self), Texture Power (how much overlap/blending between the planes), Top and Strength (for the 3-texture version), Vertex Color Strength, as well as the maps and options for Diffuse (RGB) / Gloss (A), Specular Color, Shininess, Normal, Emission, and Rim Lighting.
- Location in Shader dropdown: UVFree/Legacy/Specular and UVFree/Legacy/SpecularTopBottom
- Shader feature keywords (?):
_UVFREE_LOCAL, _EMISSION, _UVFREE_RIM, _UVFREE_VERTEX_COLOR, _UVFREE_BOTTOM
(for 3-texture version)
Triplanar Legacy Diffuse Shaders (1-Texture and 3-Texture):
- Triplanar shaders using the legacy Lambert lighting model, which is not physically-based, but can be faster to render on low-end hardware.
- Properties include: Triplanar Space (world or self), Texture Power (how much overlap/blending between the planes), Top and Bottom Strength (for the 3-texture version), Vertex Color Strength, as well as the maps and options for Diffuse (RGB) / Gloss (A), Normal, Emission, and Rim Lighting.
- Location in Shader dropdown: UVFree/Legacy/Diffuse and UVFree/Legacy/DiffuseTopBottom
- Shader feature keywords (?):
_UVFREE_LOCAL, _EMISSION, _UVFREE_RIM, _UVFREE_VERTEX_COLOR, _UVFREE_BOTTOM
(for 3-texture version)
Triplanar Legacy Specular Terrain Shader:
- Triplanar terrain shader using the legacy Blinn-Phong (glossy) lighting model, which is not physically-based, but can be faster to render on low-end hardware.
- Use as many textures as you want (4 textures per pass).
- Use this the same way that Unity's built-in terrain shaders are used, but without the annoying stretching.
- Use the built-in Terrain inspector to set each texture's Diffuse (RGB) / Gloss (A) map and Normal Map.
- Additional Properties include: Texture Power (how much overlap/blending between the planes), Texture Scale (scale all the textures on the terrain at once), Specular Color, Shininess, Bump Scale, and Rim Lighting.
- Location in Shader dropdown: UVFree/Terrain/LegacySpecular
- Shader feature keywords (?):
_UVFREE_RIM
Triplanar Legacy Diffuse Terrain Shader:
- Triplanar terrain shader using the legacy Lambert lighting model, which is not physically-based, but can be faster to render on low-end hardware.
- Use as many textures as you want (4 textures per pass).
- Use this the same way that Unity's built-in terrain shaders are used, but without the annoying stretching.
- Use the built-in Terrain inspector to set each texture's Diffuse map and Normal Map.
- Additional Properties include: Texture Power (how much overlap/blending between the planes), Texture Scale (scale all the textures on the terrain at once), Specular Color, Shininess, Bump Scale, and Rim Lighting.
- Location in Shader dropdown: UVFree/Terrain/LegacyDiffuse
- Shader feature keywords (?):
_UVFREE_RIM
Additional Features:
- Texture Power field: This bonus field allows you to control the degree of overlap/sharpness when performing triplanar projection. A low Texture Power (1.0-5.0) helps create more believable surfaces from more organic-looking textures such as rock or grass. A high Texture Power (10.0 and up) allows for sharper texture transitions between top, bottom, left, right, front, and back surfaces - good for repeating textures such as bricks, grids, and strong patterns where overlap is not desired.
- Vertex Colors: Add color variation by applying vertex colors from the mesh. Control the strength of the vertex colors with the Vertex Color Strength slider. You can completely remove this feature for optimization purposes by commenting out the "
#define _UVFREE_VERTEX_COLOR
" line in the shaders that have it. (Some of the shaders have it as a keyword option that is automatically disabled when the Vertex Color Strength is set to 0.0. - Custom Material Editors and Shader Keywords: These shaders come with custom material editors that are automatically displayed when using materials with the UV-Free shaders. These custom editors automatically switch on/off features (shader keywords) used in the shaders so that only the variants of the shaders (from among hundreds of possible variants) will be included in the game build. You can also programmatically enable or disable the shader keywords, but make sure there is a material included in the game build that already has that shader keyword combination.
- Normal Multiplier or Bump Scale: Shaders which include a Bump/Normal Map have a Normal multiplier that allows you to control the bumpiness of the normal map to exaggerate it or tone it down. The default is set to 1.0.
- Texture Scale Percentage: For terrain shaders, a Texture Scale percentage property provides a quick way to scale all the textures for that terrain simultaneously.
- (Experimental) Flip Backwards Textures: (Disabled by default) If enabled, the shaders will flip any textures that are backwards, allowing you to properly display text within the textures. This helps textures to look more natural and not have a "mirroring" effect where the planes of the triplanar projection meet. When this feature is disabled (default) the textures will be flipped or backwards when facing the -X, -Y or -Z planes. You can turn on the feature by uncommenting the "
#define _UVFREE_FLIP_BACKWARD_TEXTURES
" line found in the desired shaders. Note: This may cause some normals to appear inside-out along some dimensions. - Sample materials and a simple sample scene to demonstrate the shaders. You can safely delete the Samples folder.
Notes:
- These shaders require Shader Model 3.0 GPU (most GPUs after 2004).
- The Vertex Lit Rendering Path is not supported for these shaders.
- These shaders are opaque and do not have any transparency / alpha testing features. If you'd like to add transparency / alpha testing features to the shaders, it is only 2-3 lines of code to change. See the "Transparency and alpha testing" section of Unity's Surface Shaders documentation. Download the source code for the built-in shaders and look at the "Tags" line and "#pragma surface" line of the Alpha and AlphaTest shaders for example of how it is done.
- This is a shader pack, not a texture pack!!! The sample textures included in the example scene have been marked so that they can be legally provided with this example scene, and are for example purposes only. The original textures are licensed from http://gametextures.com. The marked textures are distributed in the sample scene with permission from GameTextures.com.
- Due to the number of shader variants (hundreds) that must be compiled/imported, it could take a few minutes to initially import the asset into your project.
- When using the mesh shaders in local/self triplanar space, you may run into an issue where Unity switches to display the textures as if it was in world triplanar space, depending on the complexity, shadows, and level of detail of the mesh when Unity's Dynamic Batching is enabled. This happens because the object may be switching in and out of Unity's dynamic batching. When an object is dynamically batched, Unity passes the shader the batched vertex data in world space instead of the object's ordinary local space data. If you see this switch happening, you can either switch off dynamic batching globally (not recommended, for performance sake), or use the non-dynamic-batching version of the shader (suffixed by "NB"). Alternatively, you can make sure the problem meshes don't get dynamically batched by making sure they don't meet the threshold for dynamic batching.
Platforms Supported:
- Windows
- macOS and Mac OS X
This shader pack was developed for the Desktop platforms above. No other platforms are not supported. It does not work with WebGL.
Glossary of Shader Properties
Triplanar Space: This selects the relative space the triplanar projections. When "World" is selected, the projections will be based on the global coordinates, and textures will not stay in the same place as a mesh if the mesh is moved. This is best used for static objects (objects that do not move), or making multiple separate overlapping meshes appear to be one single mesh. When "Self" is selected, the textures will remain relative to the mesh's position, rotation, and scaling. Moving the mesh around will not affect the position of the textures on the mesh. This is best used for moving objects such as boulders, or falling debris.
Texture Power: The magnitude of blending for the different projections (top, bottom, left, right, front, back). A low texture power (1.0 - 5.0) will have more overlap and smoother blending, while a high texture power (10.0+) will have a sharper texture transition.
Top Strength: This controls the strength of the top texture on surfaces facing up (+Y). A value of 0.0 would hide the top texture, showing only the main texture. A stronger value (1.0+) would increase the portion of the surfaces that is using the top texture. Keep in mind that the top texture is a single projection of the texture from top down, so it may stretch if you increase the top strength too much.
Bottom Strength: This controls the strength of the bottom texture on surfaces facing down (-Y). A value of 0.0 would hide the bottom texture, showing only the main texture. A stronger value (1.0+) would increase the portion of the surfaces that is using the bottom texture. Keep in mind that the bottom texture is a single projection of the texture from bottom up, so it may stretch if you increase the bottom strength too much.
Vertex Color Strength: This controls how much effect vertex colors on the mesh have on the diffuse color. A value of 0.0 will disable the vertex colors, while a value of 1.0 will tint the diffuse color by the interpolated vertex color for that pixel. Vertex colors on meshes can be used to add variety while reducing the number of separate materials used. See example of how to procedurally change vertex colors.
Albedo: The Albedo parameter controls the base color of the surface. Specifying a single colour for the Albedo value is sometimes useful, but it is far more common to assign a texture map for the Albedo parameter. This should represent the colours of the surface of the object. It's important to note that the Albedo texture should not contain any lighting, since the lighting will be added to it based on the context in which the object is seen.
Albedo (RGB) Smoothness (A): In the terrain inspector, supply the Albedo in the RGB channel, and the smoothness in the alpha channel of the map. If the material does not have an alpha channel, then the terrain inspector will provide a slider for smoothness.
Diffuse (RGB) or Diffuse (RGB) Gloss (A): The RGB channels are used for the diffuse texture. The alpha channel is used for the specular highlights. The higher the gloss, the shinier that part of the texture is.
Metallic/Smoothness: The Metallic/Smoothness can be specified as a map or as separate parameters. As a map, the RGB channels represent the metallic reflection, and the A channel represents the smoothness. When there is no map, separate sliders appear for metallic and smoothness. For more information see Unity's documentation on Standard Shader Material parameters.
Specular/Smoothness: The Specular/Smoothness can be specified as a map or as separate parameters. As a map, the RGB channels represent the specular reflection, and the A channel represents the smoothness. When there is no map, separate parameters appear for specular color and smoothness. For more information see Unity's documentation on Standard Shader Material parameters.
Normal Map: The normal map or bump map texture used for faking the lighting of bumps and dents. Make sure this texture is set configured as Texture Type "Normal map" when examining this texture in the inspector. For more information see Unity's documentation on Standard Shader Material parameters.
Normal multiplier or Bump Scale: A setting which controls the bumpiness of the normalmap. The higher this is, the more exaggerated the bumps will be. At 0.0, the bumps from the normal map will be flattened out. A negative multiplier will turn the bumps inside out.
Height Map: Heightmaps are usually used in conjunction with normal maps and are often used to give extra definitino to surfaces where the texture maps are responsible for rendering large bumps and protusions. The heightmap should be a greyscale image, with white areas representing the high areas of your texture and black representing low areas. For more information see Unity's documentation on Standard Shader Material parameters.
Occlusion Map: The occlusion map is used to provide information about which areas of the model should receive high or low indirect lighting. Indirect lighting comes from ambient lighting and reflections, and so steep concave parts of your model such as a crack or fold would not realistically receive much indirect light.An occlusion map is a greyscale image, with white indicating areas that should receive full indirect lighting, and black indicating no indirect lighting. For more information see Unity's documentation on Standard Shader Material parameters.
Emission: Controls color and intensity of light emitted from the surface. When an emissive material is used in your scene, it appears to be a visible source of light itself (self-illuminated). Either a map can be provided, or it can be defined by a single color and an emission level. Set the emission level to a value higher than the default zero for the emission color and strength to appear. For more information see Unity's documentation on Standard Shader Material parameters.
Detail Maps: Detail maps allow you to overlay a second set of textures on top of the main textures. You can apply a second Albedo color map, and a second Normal map. The detail mask texture allows you to mask off certain areas of your model to have the detail texture applied. this means you can show the detail texture in certain areas, and hide it in others. For more information see Unity's documentation on Standard Shader Material parameters.
Specular Color (RGB) Strength (A): The color and strength of the specular/gloss highlights.
Shininess: The shininess of the material. Lower values will have specular highlights that are more spread out, while higher values will have specular highlights that are more focused in a smaller area.
Rim Color (RGB) Strength (A): Rim lighting gives the effect of the object being backlit or picking up bounce light. Rim color is the color of that bounce light.
Rim Power: The sharpness of the rim lighting. Lower values will cause the material's rim lighting to be spread out, while higher values will cause the rim lighting to be more concentrated.
Rim Multiplier: This is an alternative to the Rim Color's strength. When this is zero, no specular highlights will be displayed. As this increases above 1.0, the rim lighting will be exaggerated more and more.
Texture Scale %: For terrains, this is a quick way to scale all the textures for that terrain across the board simultaneously. Set this to smaller (<100.0) to shrink the textures, and larger (>100.0) to magnify the textures.
Shader Keywords
These shaders make use of shader keywords to consolidate code and automatically compile a large number of internal shader variants based on the different possible combinations of features used. Only the variants of the shaders (from among hundreds of possible variants) will be included in the game build.
The custom material editors, automatically used with these shaders, takes care of enabling/disabling these shader keywords. Additionally, you can also programmatically enable or disable the shader keywords, but make sure there is a material included in the game build that already has that shader keyword combination.
_UVFREE_LOCAL
: Whether the triplanar projections should be based on Local Space (enabled) or World Space (disabled).
_UVFREE_BOTTOM
: Whether or not to include a separate bottom set of textures, in addition to the top set of textures and main set of textures. The main and top set of textures will be included regardless of whether this is enabled/disabled.
_UVFREE_VERTEX_COLOR
: Whether or not to apply vertex colors to the diffuse coloring of the material.
_UVFREE_RIM
: Whether or not to include rim lighting for materials using the legacy shaders.
_UVFREE_BUMPED
: Whether or not to include normal/bump mapping.
_SPECGLOSSMAP
: Whether or not the Specular/Gloss map is used. If this is disabled, then the numeric _Glossiness
(Smoothness) and _SpecColor (Specular color) will be used instead (and _TopGlossiness
, _BottomGlossiness
material properties if present). If it is on, then the _UsingSpecGlossMap
material property, and the _TopUsingSpecGlossMap
and _BottomUsingSpecGlossMap
properties (if present), should be set to 0.0 (off) or 1.0 (on) to indicate whether they are using the numeric properties or the Specular/Gloss map respectively.
_METALLICGLOSSMAP
: Whether or not the Metallic/Gloss map is used. If this is disabled, then the numeric _Glossiness
(Smoothness) and _Metallic
(Metalness) will be used instead (and the _Top
and _Bottom
prefixed versions if present). If it is on, then the _UsingMetallicGlossMap
material property, and the _TopUsingMetallicGlossMap
and _BottomUsingMetallicGlossMap
properties (if present), should be set to 0.0 (off) or 1.0 (on) to indicate whether they are using the numeric properties or the Metallic/Gloss map respectively.
_PARALLAXMAP
: Whether or not the Height map(s) should be used.
_DETAIL
: Whether or not the Detail map(s) should be used.
_OCCLUSION
: Whether or not the Ambient Occlusion map(s) should be used.
_EMISSION
: Whether or not the Emission map(s) should be used.
Release Notes & Changes
2.0.3: Quick fix for heighmap issues in Unity 5.6.0.
2.0.2: Added Non-Dynamic-Batching version of shaders. Fixed issue in terrain shaders where the transition area between two different textures is darker than it should be. Shortened file names for the sample scene and its files.
2.0.1: Fixed issue where point light shadows and spot light shadows were not showing up on the terrain shaders. Added commented out code to mesh shaders for disabling dynamic batching for just that specific shader. Modified terrain shaders internally to more closely mirror the updated terrain shader code from Unity 5.2.1f1.
2.0.0: Upgraded for Unity 5. Added Standard Metallic PBR and Standard Specular PBR versions of the shaders, built using Unity 5's new lighting model. Consolidated legacy shaders into into mega shaders with a similar interface to Unity 5's Standard Shader. Features are enabled or disabled by simply using or not using various texture slots and parameters in the customized material editor.
1.0.2: Fixed issue with strange lighting when DX11 is enabled for some graphics cards. Moved documentation to online HTML file.
1.0.1, 1.0.0: Initial Release. Note: Some graphics cards may be affect by a DX11 issue. As a workaround, disable the DX11 checkbox in the Build Settings > Player Settings until the 1.0.2 update is up on the Asset Store.
Support
Please email me at andyman [at] idumpling.com with the subject "UV-Free Shaders". So that I may help you more efficiently, please specify your issue with as much useful detail and context as possible, such as platform, hardware, OS, rendering path (forward or deferred), color space (gamma or linear), and how you are trying to use the shaders. Annotated screenshots are very useful and will save us all some time.