AlphaVertexLitZ

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (removing broken syntax highlight tag)
m (An addition to expand the code)
 
Line 2: Line 2:
  
 
Author: [[User:NeARAZ|Aras Pranckevicius]].
 
Author: [[User:NeARAZ|Aras Pranckevicius]].
 +
 +
Modification: [[User:Derick Wiebe|Derick Wiebe]].
  
 
==Description==
 
==Description==
Line 39: Line 41:
 
             Combine texture * primary DOUBLE, texture * primary
 
             Combine texture * primary DOUBLE, texture * primary
 
         }  
 
         }  
 +
    }
 +
}
 +
}
 +
</source>
 +
 +
 +
The below is a modification so that you can get more customization. It shouldn't be much more expensive than the above:
 +
 +
== Shader 2.0 ==
 +
 +
<source lang="text">
 +
Shader "Transparent/VertexLit with Z" {
 +
Properties {
 +
    _Color ("Main Color", Color) = (1,1,1,1)
 +
    _SpecColor ("Spec Color", Color) = (1,1,1,0)
 +
    _Emission ("Emissive Color", Color) = (0,0,0,0)
 +
    _Shininess ("Shininess", Range (0.1, 1)) = 0.7
 +
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
 +
}
 +
   
 +
SubShader {
 +
    Tags {"RenderType"="Transparent" "Queue"="Transparent"}
 +
    // Render into depth buffer only
 +
        Pass {
 +
        ColorMask 0
 +
    }
 +
    // Render normally
 +
    Pass {
 +
        ZWrite Off
 +
        Blend SrcAlpha OneMinusSrcAlpha
 +
        ColorMask RGB
 +
        Material {
 +
            Diffuse [_Color]
 +
            Ambient [_Color]
 +
            Shininess [_Shininess]
 +
            Specular [_SpecColor]
 +
            Emission [_Emission]
 +
        }
 +
        Lighting On
 +
        SetTexture [_MainTex] {
 +
            Combine texture * primary DOUBLE, texture * primary
 +
        }
 
     }
 
     }
 
}
 
}
 
}
 
}
 
</source>
 
</source>

Latest revision as of 00:14, 2 June 2013


Author: Aras Pranckevicius.

Modification: Derick Wiebe.

[edit] Description

AlphaVertexLitZ.jpg

Built-in Transparent shaders do not write to depth buffer, hence an object is x-ray like transparent - you can see object's parts which are behind other parts. If you want to fade the object as a whole, this shader can help. See the image on the right.

The shader should work about everywhere (probably even on iPhone). It does render object in two passes though, so it's twice as expensive as regular VertexLit.

[edit] Shader

Shader "Transparent/VertexLit with Z" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
 
SubShader {
    Tags {"RenderType"="Transparent" "Queue"="Transparent"}
    // Render into depth buffer only
    Pass {
        ColorMask 0
    }
    // Render normally
    Pass {
        ZWrite Off
        Blend SrcAlpha OneMinusSrcAlpha
        ColorMask RGB
        Material {
            Diffuse [_Color]
            Ambient [_Color]
        }
        Lighting On
        SetTexture [_MainTex] {
            Combine texture * primary DOUBLE, texture * primary
        } 
    }
}
}


The below is a modification so that you can get more customization. It shouldn't be much more expensive than the above:

[edit] Shader 2.0

Shader "Transparent/VertexLit with Z" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Spec Color", Color) = (1,1,1,0)
    _Emission ("Emissive Color", Color) = (0,0,0,0)
    _Shininess ("Shininess", Range (0.1, 1)) = 0.7
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
 
SubShader {
    Tags {"RenderType"="Transparent" "Queue"="Transparent"}
    // Render into depth buffer only
        Pass {
        ColorMask 0
    }
    // Render normally
    Pass {
        ZWrite Off
        Blend SrcAlpha OneMinusSrcAlpha
        ColorMask RGB
        Material {
            Diffuse [_Color]
            Ambient [_Color]
            Shininess [_Shininess]
            Specular [_SpecColor]
            Emission [_Emission]
        }
        Lighting On
        SetTexture [_MainTex] {
            Combine texture * primary DOUBLE, texture * primary
        }
    }
}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox