LayerShader

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 5: Line 5:
 
This shader is good for making terrains where you need to tile textures but still want paths. Basically it blends between two textures using alpha from the third (Path Mask) texture.
 
This shader is good for making terrains where you need to tile textures but still want paths. Basically it blends between two textures using alpha from the third (Path Mask) texture.
  
This shader requires a 4-texture video card (GeForce3 and up, Radeon 8500 and up).
+
This shader requires a 4-texture video card (GeForce3 and up, Radeon 8500 and up) to be rendered in one pass.
  
 
See also: [[TerrainFourLayer]], which blends four terrain textures, and [[TerrainTwoLayerBumped]] shader, which adds bumpmapping.
 
See also: [[TerrainFourLayer]], which blends four terrain textures, and [[TerrainTwoLayerBumped]] shader, which adds bumpmapping.
Line 18: Line 18:
 
==ShaderLab - TerrainTwoLayer.shader==
 
==ShaderLab - TerrainTwoLayer.shader==
 
<shaderlab>Shader "MyShaders/TwoLayerTerrain" {
 
<shaderlab>Shader "MyShaders/TwoLayerTerrain" {
    Properties {
+
 
        _Color ("Main Color", Color) = (1,1,1,1)
+
 
        _MainTex ("Main Texture (RGB)", 2D) = "white" {}
+
Properties
        _PathTex ("Path Texture (RGB)", 2D) = "white" {}
+
{
        _PathMask ("Path Mask (A)", 2D) = "white" {}
+
_Color ("Main Color", Color) = (1,1,1)
    }
+
_MainTex ("Main Texture (RGB)", 2D) = ""
    SubShader {
+
_PathTex ("Path Texture (RGB)", 2D) = ""
      Pass {
+
_PathMask ("Path Mask (A)", 2D) = ""
          Lighting On
+
}
         
+
 
          Material {
+
SubShader  
              Diffuse [_Color]
+
{
              Ambient [_Color]
+
Lighting On
          }
+
          SetTexture [_MainTex] {
+
Material  
              combine texture
+
{
          }
+
Ambient [_Color]
          SetTexture [_PathMask] {
+
Diffuse [_Color]
              combine previous, texture
+
}
          }
+
 
          SetTexture [_PathTex] {
+
Pass
              combine previous lerp (previous) texture
+
{
          }
+
SetTexture [_MainTex]
          SetTexture [_MainTex] {
+
              combine previous * primary
+
SetTexture [_PathMask]
          }
+
{
      }
+
combine previous, texture
    }  
+
}
    FallBack " Diffuse", 1
+
 +
SetTexture [_PathTex]
 +
{
 +
combine texture lerp(previous) previous
 +
}
 +
 +
SetTexture [_MainTex]
 +
{
 +
combine previous * primary
 +
}
 +
}
 +
}
 +
 
 +
SubShader
 +
{
 +
Lighting On
 +
 +
Material
 +
{
 +
Ambient [_Color]
 +
Diffuse [_Color]
 +
}
 +
 
 +
Pass
 +
{
 +
SetTexture [_MainTex]
 +
{
 +
combine texture * primary
 +
}
 +
}
 +
 +
Pass
 +
{
 +
Blend SrcAlpha OneMinusSrcAlpha
 +
 +
SetTexture [_PathTex]
 +
{
 +
combine texture * primary
 +
}
 +
 +
SetTexture [_PathMask]
 +
{
 +
combine previous, texture
 +
}
 +
}
 +
}
 +
 
 +
Fallback "Diffuse"
 +
 
 +
 
}</shaderlab>
 
}</shaderlab>

Revision as of 19:38, 12 November 2009

Original Author: Bill Vinton (Sync1B)
Updated version for 2-texture cards: Jessy

Description

Terrain using the shader

This shader is good for making terrains where you need to tile textures but still want paths. Basically it blends between two textures using alpha from the third (Path Mask) texture.

This shader requires a 4-texture video card (GeForce3 and up, Radeon 8500 and up) to be rendered in one pass.

See also: TerrainFourLayer, which blends four terrain textures, and TerrainTwoLayerBumped shader, which adds bumpmapping.


Usage

Terrains, Tile masking

Path Mask texture's alpha channel is used to blend between Main and Path textures.


ShaderLab - TerrainTwoLayer.shader

<shaderlab>Shader "MyShaders/TwoLayerTerrain" {


Properties { _Color ("Main Color", Color) = (1,1,1) _MainTex ("Main Texture (RGB)", 2D) = "" _PathTex ("Path Texture (RGB)", 2D) = "" _PathMask ("Path Mask (A)", 2D) = "" }

SubShader { Lighting On

Material { Ambient [_Color] Diffuse [_Color] }

Pass { SetTexture [_MainTex]

SetTexture [_PathMask] { combine previous, texture }

SetTexture [_PathTex] { combine texture lerp(previous) previous }

SetTexture [_MainTex] { combine previous * primary } } }

SubShader { Lighting On

Material { Ambient [_Color] Diffuse [_Color] }

Pass { SetTexture [_MainTex] { combine texture * primary } }

Pass { Blend SrcAlpha OneMinusSrcAlpha

SetTexture [_PathTex] { combine texture * primary }

SetTexture [_PathMask] { combine previous, texture } } }

Fallback "Diffuse"


}</shaderlab>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox